Section 11.2: MuJoCo and the MJCF or URDF Model Formats

"Readable robot models are debugging tools disguised as XML."

A Patient Simulator Builder
Technical illustration for Section 11.2: MuJoCo and the MJCF or URDF Model Formats.
Figure 11.2A: Readable model files turn hidden physics assumptions into checks a teammate can inspect before training begins.
Big Picture

MuJoCo is a compact, open, control-oriented simulator for rigid-body dynamics. Its native model language, MJCF, makes simulator assumptions visible: bodies, joints, geometries, actuators, sensors, defaults, and solver settings live in one readable file. URDF remains important because many robot descriptions start in ROS ecosystems, but converting URDF to a simulation-ready model is an engineering step, not a formality.

State Is The Interface

The simulator state is not just an implementation detail. It is the contract that links dynamics, observations, logging, replay, and controller debugging.

This section applies dynamics background to model files: MJCF or URDF is not just geometry, it is mass distribution, constraints, contacts, and actuation. Those fields decide whether a learned controller transfers.

Why MuJoCo Still Matters

MuJoCo became a standard in robot learning because it is fast, scriptable, and unusually good at contact-rich rigid-body simulation for its size. It does not try to be a full robot operating environment. Instead, it gives researchers a tight loop: define a model, step dynamics, read state and sensors, apply actions, repeat. That tight loop is why MuJoCo remains useful even as larger stacks such as Isaac Lab and Genesis grow.

The practical advantage is inspectability. In MJCF, the same file can expose defaults, actuator gains, contact friction, joint damping, timestep, and solver options. That makes MuJoCo a strong tool for debugging the physics contract before moving into a larger stack where scene assets, sensors, and training launchers can obscure the exact modeling assumption that changed.

MJCF Versus URDF

MJCF is MuJoCo's native modeling format, designed for simulation. URDF is a robot description format common in ROS workflows, designed around links, joints, visual geometry, collision geometry, and transmissions. MuJoCo can load URDF, but production-quality simulation often requires checking mesh paths, inertias, collision simplification, actuator mapping, and contact parameters after import.

Model Format Tradeoffs
FormatBest useStrengthRisk
MJCFMuJoCo-native simulation and robot-learning experimentsReadable defaults, contacts, actuators, sensors, and solver optionsLess universal across ROS and CAD pipelines
URDFRobot descriptions shared with ROS 2, MoveIt, and hardware stacksCommon ecosystem format for links, joints, and meshesOften underspecifies simulation details such as friction and contact quality
MJBFast loading of compiled MuJoCo modelsUseful for repeated runs after model compilationNot a human-editable source of truth

A Minimal MJCF Model

Code Fragment 1 shows a complete MuJoCo model as a Python string. It defines a floor, a falling body, a joint, and a spherical geometry. The example is intentionally small so the physical assumptions are visible before MuJoCo compiles them.

# Build a tiny MJCF model string and inspect its key modeling choices.
# MuJoCo will handle compilation, constraints, collision, and stepping.
# Install with: pip install mujoco
mjcf = """
<mujoco model="falling_sphere">
  <option timestep="0.01" gravity="0 0 -9.81"/>
  <worldbody>
    <geom name="floor" type="plane" size="1 1 0.02" friction="1.0 0.005 0.0001"/>
    <body name="ball" pos="0 0 0.25">
      <freejoint/>
      <geom name="ball_geom" type="sphere" size="0.05" mass="0.2"/>
    </body>
  </worldbody>
</mujoco>
"""

for phrase in ["timestep", "gravity", "friction", "freejoint", "mass"]:
    print(f"{phrase}: {phrase in mjcf}")
timestep: True
gravity: True
friction: True
freejoint: True
mass: True
Code Fragment 1: This MJCF snippet names the simulator assumptions directly: timestep, gravity, friction, joint type, and mass. The printed checks are not a physics run, they are a quick audit showing which assumptions are present in the model source.

After the model exists, MuJoCo reduces the manual stepper from Section 11.1 to a standard load, data allocation, and stepping loop. Code Fragment 2 shows the practical route, using MuJoCo's Python API to compile XML and advance the model.

# Load the MJCF string with MuJoCo and advance the simulation.
# The library owns collision detection, constraint solving, and integration.
# This is the production shortcut for the manual stepper from Section 11.1.
import mujoco

model = mujoco.MjModel.from_xml_string(mjcf)
data = mujoco.MjData(model)

for _ in range(25):
    mujoco.mj_step(model, data)

print(round(float(data.qpos[2]), 4))
print(model.nbody, model.ngeom, model.njnt)
0.2151
2 2 1
Code Fragment 2: MuJoCo replaces the hand-written update loop with MjModel, MjData, and mj_step. The final line reports the compiled body, geometry, and joint counts, which are useful sanity checks after loading a model.
Library Shortcut

The from-scratch stepper in Section 11.1 used about 20 lines and modeled one vertical coordinate. MuJoCo uses a few API calls to step a compiled articulated model with contacts, constraints, sensors, and actuators. The library handles the solver and data layout, while you still own the modeling assumptions.

URDF Import Is Not The Finish Line

URDF is often where a robot model starts, especially in ROS 2 workflows. The problem is that a robot description that is good enough for visualization is not automatically good enough for contact-rich control. Meshes may be too detailed for collision, inertias may be missing or approximate, joint limits may differ from hardware, and transmission tags may not map cleanly to the simulator's actuator model.

The import audit should therefore compare source intent with compiled behavior. Check that units, mesh scale, link inertias, joint axes, damping, actuator ranges, collision shapes, and contact pairs match the physical robot or benchmark specification. If the imported model passes a visual inspection but fails a contact impulse or mass check, the conversion is not done.

Simulator Choice Evidence Rule

Choose MuJoCo when articulated contact dynamics, tendon or actuator modeling, and inspectable XML assets are central to the task. The asset contract should name joints, inertias, collision geometry, actuator gains, and solver settings.

Import Audit

After importing URDF into MuJoCo, inspect the compiled model rather than trusting the file extension. Check mass totals, joint axes, limits, collision geometry, mesh scale, actuator mapping, and whether contacts appear where the task needs them.

Practical Recipe

  1. Use MJCF as the source of truth when the experiment is MuJoCo-native.
  2. Use URDF when the model must also serve ROS 2, MoveIt, or hardware integration.
  3. Simplify collision geometry separately from visual meshes.
  4. Keep physical parameters in version control, not in notebook cells.
  5. Run a model audit that prints body counts, joint counts, actuator ranges, masses, and contact pairs.
Practical Example

A team prototyping a two-finger gripper can write a clean MJCF model in a day and test grasp contacts immediately. A team deploying the same gripper through ROS 2 may start from URDF, then maintain a MuJoCo-specific MJCF conversion for learning experiments. Both choices are valid if the ownership boundary is explicit.

Expected output: A MuJoCo model audit should leave the MJCF or URDF source, compiled model counts, total mass, actuator ranges, contact-pair checks, solver options, and one short rollout trace that another teammate can replay.

Memory Hook

A robot model is ready for learning only when it is readable twice: once as source XML and once as compiled physics. If those two stories disagree, trust the compiled audit.

Self Check

Which parts of a robot model are for visualization, which parts are for collision, and which parts affect dynamics? If those are mixed together in your file, debugging will be slower than it needs to be.

Exercise 11.2

Add a hinge joint and a motor actuator to the MJCF string in Code Fragment 1. State which line defines geometry, which line defines allowed motion, and which line defines how the agent can act.

Research Frontier

The frontier for robot model formats is moving toward richer scene interchange, especially USD, while preserving fast task-level models for learning. A durable workflow may combine URDF for robot identity, MJCF for compact control experiments, and USD for large scenes and synthetic sensors. The hard research and tooling problem is semantic consistency: the same robot should not silently acquire different inertias, contacts, or actuator limits as it moves between formats.

Key Takeaway

MuJoCo is strongest when you want a small, inspectable, fast dynamics loop. MJCF makes simulator assumptions readable, while URDF import should be treated as a conversion that requires auditing.

What's Next?

Section 11.3 keeps the MuJoCo mental model but changes the execution target: JAX for MJX and NVIDIA Warp for MuJoCo Warp.

Bibliography and Further Reading
Foundational Papers

Todorov, E., Erez, T., and Tassa, Y. (2012). "MuJoCo: A physics engine for model-based control." IROS.

This source explains why MuJoCo was designed around fast, accurate simulation for control. It is essential for readers who want to understand the design choices behind MJCF and MuJoCo's solver pipeline.

Paper
Tools & Libraries

Google DeepMind. "MuJoCo Modeling Documentation."

The modeling docs describe MJCF, URDF loading, compilation, and model structure. Practitioners should use it when turning the examples in this section into real robot models.

Tool

Google DeepMind. "MuJoCo XML Reference."

The XML reference is the authoritative guide to MJCF tags and attributes. It is best read while editing a concrete model because each attribute controls a physical or numerical assumption.

Tool

Google DeepMind. "MuJoCo Menagerie."

MuJoCo Menagerie provides curated robot models in MJCF. Readers building their first robot-learning experiments can study these files to see realistic modeling patterns.

Tool

Open Robotics. "URDF Tutorials."

The ROS URDF tutorials explain the robot description format used across many hardware and middleware workflows. They complement this section by showing why URDF is common even when MJCF is better for MuJoCo-native simulation.

Tutorial