This is an example of a simple CartPole environment using mjlab for training. This repository is both a pedagogical example using mjlab and an example of organization using mjlab as an external dependency.
Simply run:
uv sync
To run the training, use:
uv run train Mjlab-Cartpole
Run:
uv run play Mjlab-Cartpole --checkpoint-file [path-to-checkpoint]
The checkpoint will typically appear in logs/rsl_rl/exp1/[date]/model_499.pt
The structure is as follow:
src/mjlab_cartpole/robot/: Robot modelxmls/cartpole.xml: MuJoCo MJCF speccartpole_constants.py: Describing how to load the robot entity (mostly loading the XML spec here)
tasks/: Task definition__init__.py: Environments are registered herecartpole_env_cfg.py: Environment configurations (actions, rewards, termination, reset etc.)
Here, mjlab is used as an external dependency.
Actions is the force
Agent observation is the pole angle and velocity and the cart position and velocity.
The goal is for the pole not to fall, while navigating the cart to the center, the reward is as follows:
Where:
-
$\theta$ is the pole angle (0 is upright) -
$x$ is the cart position -
$\sigma = 0.3$ is a deviation to the center -
$f$ is the applied cart force (command)
A termination is issued when
- This is inspired by the Creating a New Task markdown from mjlab