[MicroDuck RL 08] MuJoCo Basics: Explore the Robot Without Training

MicroDuck RL: From Simulation to the Real Robot — Part 08 of 14

This is a lighter installment: no training, just exploring and experimenting with the robot model. For a beginner, it is the fastest way to understand MJCF, MuJoCo’s model format.

Open the Viewer

cd microduck_rl

# Option 1: Open the scene directly with MuJoCo's built-in viewer.
# The scene contains the floor, the robot, and the STAND/SIT/FOLD keyframes.
uv run python -m mujoco.viewer src/mjlab_microduck/robot/microduck/scene_walk.xml

# Option 2: Use the repository's entry point to load the walking model.
uv run python src/mjlab_microduck/robot/microduck_constants.py

Basic viewer controls:

  • Press the spacebar to pause.
  • Press Tab to switch camera views.
  • Hold the right mouse button and drag to rotate the camera.
  • Hold Ctrl and drag to push the robot by hand and watch it fall. That is part of the fun of simulation.

Where to Begin Reading the Model

  • scene_walk.xml: the scene, which combines the floor, an included robot model, and keyframes
  • robot_walk.xml: the robot body; meshes are stored in assets/, while joints_properties.xml and sensors.xml define the joints and sensors
  • Four important MJCF elements: <body> for the rigid-body tree, <joint> for joints and their limits, damping, and friction, <geom> for collision and visual geometry, and <actuator> for actuation

A Quick Tour of the MuJoCo Python API

Thirty minutes in the interactive API will teach you more than thirty minutes of reading documentation:

import mujoco, time
m = mujoco.MjModel.from_xml_path("src/mjlab_microduck/robot/microduck/scene_walk.xml")
d = mujoco.MjData(m)
print(m.nq, m.nv, m.nu)        # Position, velocity, and actuator dimensions
d.ctrl[:] = 0.1                # Send a command to every actuator
while d.time < 3.0:
    mujoco.mj_step(m, d)        # Advance the simulation by one physics step
    time.sleep(0.005)
print(d.qpos)                   # Inspect the final pose

Try different combinations of d.ctrl, observe how the joints move, and then locate each body in robot_walk.xml. That is the first exercise in the practice roadmap in Part 12. Part 09 covers deployment from simulation to the physical robot.