Simulation

MuJoCo

MuJoCo is a physics engine used for multi-body simulation, contact-rich control experiments and reinforcement learning. Its native model format MJCF contains bodies, joints, inertias and actuators; an imported robot model still needs careful validation.

Practical engineering guide

What you can build with MuJoCo and where problems start

MuJoCo is a physics engine used for multi-body simulation, contact-rich control experiments and reinforcement learning. Its native model format MJCF contains bodies, joints, inertias and actuators; an imported robot model still needs careful validation.

Download, install and launch MuJoCo

The existing Python setup uses the official MuJoCo package. Activate an isolated environment, then install and check the import before opening the viewer.

Download MuJoCo
python -m venv .venv
# Activate the environment first
python -m pip install mujoco
python -c "import mujoco; print(mujoco.__version__)"
python -m mujoco.viewer

A first test you can reproduce

  1. 01.Create a clean Python environment and install 'mujoco' from PyPI using the official version instructions.
  2. 02.Launch 'python -m mujoco.viewer' and load a known MJCF model; a blank viewer does not mean a robot asset was installed.
  3. 03.Load the model in Python, create MjData, apply controls through data.ctrl and advance the simulation with mj_step.
  4. 04.Compare model.nq, model.nv and model.nu before assuming a commanded motor index equals a joint index.

Questions that come up during real implementation

Why does MuJoCo open but my humanoid does not appear?

The viewer starts without a robot model unless one is loaded. Use the viewer's model loader or '--mjcf=/path/to/model.xml' as documented. Confirm that the MJCF references valid meshes, textures and included files. A Unitree or other robot asset is a separate download.

How do I control a joint from Python?

Load MjModel and MjData, locate the intended actuator, assign its permitted command to data.ctrl and call mujoco.mj_step repeatedly. Joint qpos indexing and actuator indexing differ for some models, including floating bases. Inspect the model's actuator definitions and control ranges first.

Why does the robot behave differently from real hardware?

Verify link masses, actuator characteristics, gearbox/friction, joint damping, control interval and contact parameters. MJCF controllers can omit motor current limits, network delay and backlash. A stable simulated gait needs hardware validation.

Checks before using it on a robot

  • Log actuator commands, joint position, joint velocity and contact events in the same time base.
  • Test small input magnitudes before applying learned policies to a full robot.

Official technical reference

https://mujoco.readthedocs.io/en/stable/python.html

Compatibility and installation

Developer
Google DeepMind
License
Open source
Operating systems
Linux, Windows, macOS
ROS support
No official ROS support recorded
Languages
C, C++, Python
Installation method
Official GitHub releases and Python packages

Profile sources

Explore the connected robotics directories