Skip to main content

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 environment wrapper around a MuJoCo XML robot model that supports both operational-space control (OSC) and simple joint-level control. It is designed to be a minimal, reusable foundation for building manipulation and robot arm tasks.

Features

  • Auto-detects joints, actuators, end-effector site, cameras and (optionally) a home keyframe from a MuJoCo XML file.
  • Two control modes: osc (end-effector operational-space control) and joint (direct actuator control).
  • 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, GenericRobotEnv

xml = Path("mujoco_menagerie/aloha/scene.xml")  # point to a model in the repo
config = RobotConfig.from_xml(xml, robot_name="aloha")
env = GenericRobotEnv(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=True to receive pixel arrays under obs['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 = GenericRobotEnv(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 under obs['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

Observations are returned as a Gymnasium spaces.Dict with the following 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 also included and contains a spaces.Dict of camera-name -> RGB image arrays.

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
  • Faster experiments: Many models include camera/site names that the environment will auto-detect (end-effector sites, cameras, and optional home keyframes). If your chosen model provides a home keyframe 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 between GenericRobotEnv and those wrappers by pointing both at the same XML and configuration.

Tips and troubleshooting

  • Missing EE/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, tcp or attachment_site so the auto-detection picks it up.
  • 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_ctrlrange when 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

generic_robot_env-0.0.1.tar.gz (67.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

generic_robot_env-0.0.1-py3-none-any.whl (11.5 kB view details)

Uploaded Python 3

File details

Details for the file generic_robot_env-0.0.1.tar.gz.

File metadata

  • Download URL: generic_robot_env-0.0.1.tar.gz
  • Upload date:
  • Size: 67.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for generic_robot_env-0.0.1.tar.gz
Algorithm Hash digest
SHA256 7f12a8f0034eabed96e893438eadcad776f9bfd80bb2769b5e96461b0e641d85
MD5 af95970daaa735478fc40723b98a4105
BLAKE2b-256 db84f2414f4ab80cae939857f9c0311a7b37a7d7270e49d2560e258bb8f04b42

See more details on using hashes here.

Provenance

The following attestation bundles were made for generic_robot_env-0.0.1.tar.gz:

Publisher: release.yml on btelles/generic-robot-env

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file generic_robot_env-0.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for generic_robot_env-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 182cc3ace55f6c3a2a18165ed470ec842d5fa68459a67f934e8b77ab82450c86
MD5 925431b4a3c8c861bd05312e43162966
BLAKE2b-256 34d92aab777635d0e9f327e68a26ab0d9e63b22d39c083909028194a1d067e16

See more details on using hashes here.

Provenance

The following attestation bundles were made for generic_robot_env-0.0.1-py3-none-any.whl:

Publisher: release.yml on btelles/generic-robot-env

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page