MuJoCo for robotics: install, first model and when to use it

A practical MuJoCo guide for robotics: installation, a minimal MJCF model, ROS 2 integration routes and where MuJoCo beats Gazebo or Isaac Sim.

MuJoCo physics simulation window showing a simple pendulum model

MuJoCo is the simulator researchers reach for when contact is the hard part. Walking, grasping, pushing and anything that depends on friction behaves better than in a general-purpose robotics simulator, and it runs on a laptop.

This guide explains what MuJoCo does well, how it fits beside Gazebo and Isaac Sim, and how to get a first model running with ROS 2.

What MuJoCo is

MuJoCo (Multi-Joint dynamics with Contact) is a physics engine built around fast, stable contact simulation. Models are described in MJCF, an XML format. It has no built-in scene editor or ROS graph; it is a library and a viewer, which is why it is fast and predictable.

ToolStrengthWeakness
MuJoCoContact, speed, reinforcement learningNo native ROS graph or large worlds
GazeboROS integration, full robot systemsWeaker contact fidelity
Isaac SimPhotoreal rendering, synthetic dataGPU and toolchain overhead

Install and run a model

python -m pip install mujoco
python -m mujoco.viewer

MuJoCo ships with example models. The viewer opens an empty scene; drag an MJCF file into it or load one from the menu. On Linux, the viewer needs OpenGL; on Windows it runs natively.

A minimal MJCF model

<mujoco model="pendulum">
  <option gravity="0 0 -9.81"/>
  <worldbody>
    <body name="arm" pos="0 0 0.5">
      <joint name="hinge" type="hinge" axis="0 1 0"/>
      <geom type="capsule" fromto="0 0 0 0 0 -0.4" size="0.02"/>
      <inertial pos="0 0 -0.2" mass="1" diaginertia="0.01 0.01 0.001"/>
    </body>
  </worldbody>
  <actuator>
    <motor joint="hinge" gear="1"/>
  </actuator>
</mujoco>

MJCF is compact because it is designed for simulation, not for describing a product. That makes it fast to iterate but means a URDF usually needs conversion and cleanup before it simulates well.

Connecting to ROS 2

There are two practical routes. The first is a bridge that publishes simulated sensor data and subscribes to commands, similar to ros_gz_bridge. The second is running MuJoCo as the physics backend for a ros2_control hardware interface, so controllers see it as hardware.

The second route is more work but more useful: your controllers, launch files and TF tree are the same as on the real robot. For reinforcement learning, most teams use the Python API directly and skip ROS during training.

Where MuJoCo earns its place

  • Legged robots. Contact-rich walking benefits from stable solver behaviour.
  • Manipulation research. Grasping and pushing need believable friction and contact.
  • Reinforcement learning. Fast headless simulation allows many parallel environments.
  • Teaching dynamics. Small models run quickly and are easy to inspect.
  • Controller prototyping. Test a control law before building hardware.

Where it is the wrong tool

If you need a full mobile robot with Nav2, multiple sensors and a warehouse world, Gazebo is the shorter path. If you need photoreal camera images for training a detector, Isaac Sim is the better fit. MuJoCo is a physics engine, not a robot systems simulator.

Mistakes

MistakeResultFix
Converting URDF without checking inertiasUnstable or floaty behaviourValidate mass and inertia in the viewer
Ignoring timestepExploding contactsReduce timestep or adjust solver iterations
Expecting ROS topics out of the boxNothing publishesAdd a bridge or hardware interface
Tuning contact parameters blindlyUnrealistic frictionMeasure friction on the real surface
Using it for large scenesSlow and awkwardUse Gazebo or Isaac Sim

Related: Isaac Sim vs Gazebo, Gazebo ROS 2 tutorial, ros2_control tutorial, quadruped robots, URDF tutorial.

What is MuJoCo used for?

It is a physics engine for robotics and reinforcement learning, especially tasks where contact and friction matter, such as walking and grasping.

Is MuJoCo free?

Yes, it is open source and free to use, including commercially, under its current licence.

Does MuJoCo work with ROS 2?

Not natively. You either bridge its data to ROS topics or run it as a ros2_control hardware interface. Many research teams use its Python API without ROS.

Is MuJoCo better than Gazebo?

For contact-rich physics and reinforcement learning, often yes. For a full robot with navigation, sensors and worlds, Gazebo is more practical.

What hardware do I need for MuJoCo?

A normal laptop is enough for small models. GPU acceleration helps for large-scale reinforcement learning but is not required for the viewer.

If your model also feeds Gazebo, the URDF vs SDF comparison explains the split.

Sources and further reading

Keep reading

Continue learning

The Build Note

One short email when something is worth your bench time.

A new build sheet, a part price that moved, or a mistake worth avoiding. No daily drip, no recycled news.

One short email when a build or a price is worth your time. Unsubscribe in one click.