Implementation:Haosulab ManiSkill CartPole
| Knowledge Sources | |
|---|---|
| Domains | Robotics, Simulation, Control |
| Last Updated | 2026-02-15 08:00 GMT |
Overview
Concrete implementation of the CartPole control task environment in ManiSkill, adapted from the DeepMind Control Suite.
Description
The CartPole environment implements the classic cart-pole balancing and swingup tasks. A cart slides along a rail and a pole is attached via a hinge joint. The robot is defined inline via MJCF as CartPoleRobot.
Registered variants:
MS-CartPoleBalance-v1(max_episode_steps=500): Balance the pole upright from near-upright initial conditions.MS-CartPoleSwingUp-v1(max_episode_steps=500): Swing the pole from a hanging position to upright.
The robot uses PD joint position control on the slider joint, with a passive controller on the hinge. Rewards are computed from the pole's upright angle, cart centering, and angular velocity penalties. Reward modes include "dense", "normalized_dense", and "none".
Usage
Use this environment for benchmarking basic control algorithms. CartPole Balance provides a simpler task while CartPole SwingUp requires more sophisticated control strategies.
Code Reference
Source Location
- Repository: Haosulab_ManiSkill
- File: mani_skill/envs/tasks/control/cartpole.py
Signature
@register_env("MS-CartPoleBalance-v1", max_episode_steps=500)
class CartPoleBalanceEnv(CartPoleEnvBase): ...
@register_env("MS-CartPoleSwingUp-v1", max_episode_steps=500)
class CartPoleSwingUpEnv(CartPoleEnvBase): ...
Import
import gymnasium as gym
import mani_skill.envs
env = gym.make("MS-CartPoleBalance-v1")
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| obs_mode | str | No | Observation mode (default: "state") |
| reward_mode | str | No | Reward mode: "dense", "normalized_dense", "none" |
| control_mode | str | No | Control mode for the cart |
Outputs
| Name | Type | Description |
|---|---|---|
| obs | dict/array | Observation including cart position, pole angle, velocities |
| reward | float | Reward based on upright angle, cart position, angular velocity |
| terminated | bool | Whether episode ended |
| truncated | bool | Whether episode hit max steps (500) |
| info | dict | Contains evaluation metrics |
Usage Examples
Basic Usage
import gymnasium as gym
import mani_skill.envs
env = gym.make("MS-CartPoleBalance-v1", obs_mode="state", render_mode="rgb_array")
obs, info = env.reset()
for _ in range(100):
action = env.action_space.sample()
obs, reward, terminated, truncated, info = env.step(action)
if terminated or truncated:
obs, info = env.reset()
env.close()