A generic MuJoCo-based robot environment generator for LeRobot or Gymnasium-style experiments.
Project description
generic_robot_env
A generic MuJoCo-based robot environment generator for LeRobot or Gymnasium-style experiments.
This library is heavily inspired by and depends on the gym_hil project which implemented the first variant of these configurations.
This package provides
RobotConfig: A version of the gym_hil MujocoGymEnv that can extract its configuration from a well-formed mujoco scene.xml file.GenericRobotEnv, a configurable robot-control base environment around a MuJoCo XML model, with reusable robot methods (apply_action,get_robot_state,reset_robot,render,get_gripper_pose).GenericTaskEnv, a task-oriented layer on top ofGenericRobotEnvthat adds Panda-pick-style task behavior (task reset, environment state observation, reward, success/termination).
Features
- Auto-detects joints, actuators, end-effector site, cameras and (optionally) a
homekeyframe from a MuJoCo XML file. - Two control modes:
osc(end-effector operational-space control) andjoint(direct actuator control). - Separation of concerns: robot-control APIs in
GenericRobotEnv, task APIs inGenericTaskEnv. - Optional image observations from model cameras.
- Returns structured observations compatible with Gymnasium
spaces.Dict.
Installation
This project depends on MuJoCo and Gymnasium. Install prerequisites in your Python environment (example using pip):
pip install generic_robot_env
Note: The repository includes typed stubs under typings/ for local development and the project expects a working MuJoCo installation accessible to the mujoco Python package.
Usage examples
- Simple loop: Create a configuration from a scene XML and run a quick random-action loop. mujoco_menagerie is a good repository of scenes.
from pathlib import Path
import numpy as np
from generic_robot_env.generic_robot_env import RobotConfig, GenericTaskEnv
xml = Path("mujoco_menagerie/aloha/scene.xml") # point to a model in the repo
config = RobotConfig.from_xml(xml, robot_name="aloha")
env = GenericTaskEnv(config, control_mode="osc", image_obs=False)
obs, _ = env.reset()
for _ in range(200):
action = env.action_space.sample()
obs, reward, terminated, truncated, info = env.step(action)
if terminated:
break
env.close()
- Image observations: Enable
image_obs=Trueto receive pixel arrays underobs['pixels']keyed by camera name (when cameras exist in the MJCF).
config = RobotConfig.from_xml(Path("mujoco_menagerie/aloha/aloha.xml"), robot_name="aloha")
env = GenericTaskEnv(config, control_mode="osc", image_obs=True)
obs, _ = env.reset()
# obs['pixels'] -> dict(camera_name -> HxWx3 uint8 array)
Notes:
- If the MuJoCo model contains a keyframe named
home, the environment will try to use that as the default joint pose. - If cameras are present and
image_obs=True, pixel observations are returned underobs['pixels']keyed by camera name.
Files
src/generic_robot_env/generic_robot_env.py— main environment implementation (this module).
See src/generic_robot_env/generic_robot_env.py for the full implementation.
Observation and action spaces
GenericRobotEnv observations are returned as a Gymnasium spaces.Dict with primary keys under agent_pos:
joint_pos: Joint positions for the detected robot joints (array)joint_vel: Joint velocities (array)tcp_pose: End-effector pose as [x, y, z, qx, qy, qz, qw]tcp_vel: End-effector linear and angular velocity (6D)gripper_pose(optional): Single-value gripper state when a gripper actuator is detected
When image_obs=True, pixels is included and contains a spaces.Dict of camera-name -> RGB image arrays.
GenericTaskEnv uses Panda-pick-style observations:
- State mode:
{"agent_pos": <vector>, "environment_state": <object position>} - Image mode:
{"pixels": <camera dict>, "agent_pos": <vector>}
Action spaces depend on control_mode:
osc: Continuous Box controlling end-effector delta in position (x,y,z) and rotation (rx,ry,rz). If a gripper is available, an extra dimension for gripper command is appended.joint: Continuous Box mapped directly to actuator control values. When a gripper actuator exists, it is appended to the action vector.
Implementation notes
- The environment auto-resolves joint and actuator ids using the MuJoCo model and maps qpos/qvel indices for direct data access.
- For OSC control, a simple opspace solver (from
gym_hil.controllers.opspace) is used each simulation substep to compute actuator torques that track a desired end-effector target. - Gripper mapping tries to respect actuator control ranges defined in the model (
actuator_ctrlrange) when present.
Running tests
Run the test suite with pytest from the repository root:
pytest tests
Local presubmit hooks
Install local git hooks so linting/formatting runs before commit and tests run before push:
uv run pre-commit install --hook-type pre-commit --hook-type pre-push
Run hooks manually (optional):
uv run pre-commit run --all-files
uv run pre-commit run --hook-stage pre-push
-
Faster experiments: Many models include camera/site names that the environment will auto-detect (end-effector sites, cameras, and optional
homekeyframes). If your chosen model provides ahomekeyframe the environment will attempt to use it as the default reset pose. -
Example with a bundled task: Some pre-made gym-style wrappers (for example in
gym_hil) subclass the same base utilities; you can switch betweenGenericRobotEnvand those wrappers by pointing both at the same XML and configuration.
Tips and troubleshooting
- Missing end-effector/site detection: If the end-effector isn't found automatically, open the XML and add a site with a common name like
ee,end_effector,tcporattachment_siteso auto-detection can find it. - Gripper mapping: If the model exposes a gripper actuator with a control range, the environment will append a gripper command dimension to the action space and will respect
actuator_ctrlrangewhen possible.
Contributing
Contributions, bug reports and improvements are welcome. When adding new robots or tasks, prefer adding descriptive camera and site names in the MJCF so the auto-detection heuristics can find the end-effector and camera frames.
License
This project inherits the license of the repository. Ensure you follow the licensing terms of MuJoCo and any third-party dependencies.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file generic_robot_env-0.0.2a0.tar.gz.
File metadata
- Download URL: generic_robot_env-0.0.2a0.tar.gz
- Upload date:
- Size: 74.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8d7bd4dfc9f3c3b534623728e6b9e74150ee2be9f666e33b61f48a7d1f43491e
|
|
| MD5 |
5ffe213fc80067c14ac406015174992b
|
|
| BLAKE2b-256 |
76a68fe68c6993fa93ecf6dd20bebc62ee183c6d7b81422b482f3232fcded8de
|
Provenance
The following attestation bundles were made for generic_robot_env-0.0.2a0.tar.gz:
Publisher:
release.yml on btelles/generic-robot-env
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
generic_robot_env-0.0.2a0.tar.gz -
Subject digest:
8d7bd4dfc9f3c3b534623728e6b9e74150ee2be9f666e33b61f48a7d1f43491e - Sigstore transparency entry: 975089274
- Sigstore integration time:
-
Permalink:
btelles/generic-robot-env@66f09b1d24d59e43f90ae1ee6eb4e4f8ac99d953 -
Branch / Tag:
refs/tags/v0.0.2 - Owner: https://github.com/btelles
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@66f09b1d24d59e43f90ae1ee6eb4e4f8ac99d953 -
Trigger Event:
push
-
Statement type:
File details
Details for the file generic_robot_env-0.0.2a0-py3-none-any.whl.
File metadata
- Download URL: generic_robot_env-0.0.2a0-py3-none-any.whl
- Upload date:
- Size: 11.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6dac3d3f5dad95f365da37842052db16ccc5ed66023e4c358a5942c71290967b
|
|
| MD5 |
4807d27dcd24d219efa4715d0cee4239
|
|
| BLAKE2b-256 |
2a77f672f92947714877d307a72f0990dff734e730aa67226d3ae071e20ad59e
|
Provenance
The following attestation bundles were made for generic_robot_env-0.0.2a0-py3-none-any.whl:
Publisher:
release.yml on btelles/generic-robot-env
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
generic_robot_env-0.0.2a0-py3-none-any.whl -
Subject digest:
6dac3d3f5dad95f365da37842052db16ccc5ed66023e4c358a5942c71290967b - Sigstore transparency entry: 975089288
- Sigstore integration time:
-
Permalink:
btelles/generic-robot-env@66f09b1d24d59e43f90ae1ee6eb4e4f8ac99d953 -
Branch / Tag:
refs/tags/v0.0.2 - Owner: https://github.com/btelles
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@66f09b1d24d59e43f90ae1ee6eb4e4f8ac99d953 -
Trigger Event:
push
-
Statement type: