A general Python interface for robot simulations using MuJoCo. Its public API
mirrors pybullet_robot so that controllers written
against that backend can be run here with minimal changes. MujocoRobot is a single object to
load, introspect, control, and read state from a robot, implemented directly on MjModel +
MjData.
Requires Python >= 3.10 and
mujoco >= 3.2.
pip install mujoco_robot
pip install "mujoco_robot[ik]" # optional whole-body IK backend (mink)From source:
git clone https://github.com/justagist/mujoco_robot && cd mujoco_robot
pip install -e .import numpy as np
from mujoco_robot import MujocoRobot
from mujoco_robot.utils.robot_loader_utils import get_mjcf_from_awesome_robot_descriptions
robot = MujocoRobot(
mjcf_path=get_mjcf_from_awesome_robot_descriptions("panda_mj_description"),
ee_names=["hand"],
run_async=False, # step manually
render=True, # launch the passive viewer (needs a display)
)
robot.set_position_control_mode()
target = robot.get_actuated_joint_positions()
target[0] += 0.5
while robot.is_viewer_running():
robot.set_joint_positions(target)
robot.step()- Load an MJCF/URDF file, or wrap an existing
(model, data); assemble a world (ground, light, props, force-torque sensors) with theMjSpechelpers inmujoco_robot.utils.model_builder. - Introspect: name<->id maps for bodies, joints, actuators, sites, geoms, and sensors, with
per-joint
qpos/dofaddressing. - Lifecycle: manual
step()or a background stepping thread, an optional passive viewer, joint/base resets, and place-on-ground. - State: joint, base, and link/site pose and velocity (quaternions as
[x, y, z, w]), the geometric Jacobian, gravity-compensation torques, and aget_robot_statessnapshot. - Control: position control via the model's actuators, and torque/impedance control via
data.qfrc_applied, with a PVT-PD command and position/torque mode switching. - Contacts and force-torque sensing, plus cosmetics / domain-randomisation helpers (transparency, per-geom collision, dynamics editing).
- Inverse kinematics:
differential_ikfor a single frame (from mujoco_robot.ik import differential_ik);minkfor whole-body (optional[ik]).
Runnable demos in examples/ (each takes --headless to run without the viewer):
KUKA iiwa14 follows a joint-space sinusoid (position control).
Panda traces a circle with Cartesian impedance control.
Contact wrench visualised as the robot presses on a block.
UR5e tracks a moving target with differential_ik.
Go1 whole-body squat demo by doing IK for all four feet and body simultaneously.
- Quaternions: the external API uses
[x, y, z, w](scipy convention); values are converted to MuJoCo's[w, x, y, z]only at the boundary. - Angles: joint positions, velocities, and limits are in radians (a compiled model always
stores radians, regardless of the MJCF
compiler anglesetting). - Control: writes
data.ctrlwhen the model has actuators, otherwise falls back todata.qfrc_appliedwith a Python PD loop. - Fixed vs floating base: a structural free joint (added via
MjSpec), not a load-time flag. - Sensors: force-torque sensors are declared up front (
ft_sensor_links); the toggle only gates reading, since MuJoCo sensors are compile-time.
pip install -e ".[dev]" # test + lint + build tooling
ruff check .
pytest -qMIT (c) Saif Sidhik




