Skip to content

MuJoCo robot control

Control Go1, G1, and MicroDuck with MuJoCo physics inside UnrealZoo, while Unreal Engine supplies scene geometry and rendering. This guide follows unrealzoo-gym v3.1, audited at commit 01f56d4180c8dba2f5ca65430a61cb59e76b2ba0. The upstream example requires a compatible UnrealZoo v3.1.1 binary or an UnrealCV-enabled editor project; the Python tag and packaged binary version are not interchangeable.

Architecture and scope

  • MuJoCo computes robot dynamics and joint control inside the UE runtime, not in a separate Python MuJoCo simulator. UE provides rendering, cameras, and terrain/collision queries. Installing a Python MuJoCo package does not add these capabilities to an old binary.
  • The runtime environment owns terrain/collision queries; the shared coordinator handles synchronized batch stepping and shared props; each robot adapter maps joints, actuators, observations, and visual components. See the architecture notes.
  • UnrealCvMujocoBase owns process launch, UnrealCV connection, and pre-start physics configuration. UnrealCvMujocoEnv supplies the single-robot lifecycle. This is separate from the image/navigation base environment.
  • The base Gym bridge returns zero reward and no termination. A locomotion demonstration is not a complete RL task: add task-specific rewards, resets, and episode rules yourself.

Supported robots and policies

Micro Duck pretrained locomotion
Micro Duck pretrained locomotion
Workflow Actual policy and interface
Go1 locomotion ONNX velocity policy; 12 joint actions. The downloader offers go1_velocity and go1_rough_velocity; the unified demo defaults to the velocity policy.
G1 locomotion Unitree G1 29-DoF velocity policy; 480 policy inputs and 29 actions.
MicroDuck locomotion Official 61-dimensional observation policies; 14 actions. The unified demo switches between walking and standing according to the command.
Go1 visual Parkour A different recurrent checkpoint: 48-dimensional proprioception, 48×64 depth, and recurrent state. Policy control runs at 50 Hz; delayed depth is supplied at 10 Hz.
MicroDuck skills and mixed scenarios Walking, standing/body pose, sit/stand, ground pick, left/right kick, and roulade; specialized batch scripts, not modes of the single-robot demo.

Checkpoints and licensing

The source tree contains the default policy paths under example/mujoco/policies/; examples must be run from a source checkout, not just an installed wheel. Confirm that actual checkpoint files are present. The Go1 downloader retrieves files from robomotic/mjlab-policies on Hugging Face and skips existing files unless --force is set. It uses remote main, not an immutable model revision; downloading is not a license grant or an integrity verification. Review the model publisher's terms before reuse, and record the exact downloaded artifact for reproducible experiments.

  • G1 policy provenance: Unitree unitree_rl_lab commit 4960b84732b0c2ec593dccbfe963fda1bcd7b1e3, Apache-2.0.
  • Parkour policy provenance: Robot Parkour Learning commit 5e1f4136f7fec9dac2741add63ca58d32090666f, MIT; includes model_674000.pt, configuration, provenance hashes, and an isolated upstream inference runtime.
  • MicroDuck policy provenance: Pollen Robotics daemon-v0.10.0, Apache-2.0 for code/policies. Robot 3D models have separate Creative Commons BY-SA-NC terms as described by microduck_rl; review these before redistributing a binary.

Only load trusted checkpoints, particularly PyTorch .pt files. A replacement policy must match the robot's observation/action contract, joint order, normalization, and control frequency; an arbitrary ONNX model is not a drop-in replacement.

Prerequisites and installation

  1. Obtain the compatible packaged environment or editor project using Getting started. It must contain the robot Blueprints and MuJoCo command support. Follow UnrealCV for connectivity.
  2. Use Python 3.9 or newer in an isolated environment. Upstream declares gym==0.10.9, unrealcv==1.3.2, onnxruntime, numpy, opencv-python, and pynput among its base dependencies. This guide uses the existing four-value Gym API, not Gymnasium's five-value API.
  3. From the unrealzoo-gym repository root, install the base package. Use the optional extra for Parkour's PyTorch runtime:
python -m pip install -e .
python -m pip install -e '.[mujoco-training]'
python -m pip check

The second command is needed for Parkour, not ordinary ONNX playback. The extra declares torch>=1.12; select a PyTorch build appropriate for your machine if needed. The unified ONNX helper explicitly uses CPUExecutionProvider; Parkour defaults to --device cpu and can select --device cuda:0 with a compatible PyTorch/CUDA installation. UE rendering still needs an appropriate graphics runtime. A keyboard session needs working input permissions; the optional depth dashboard needs a graphical display.

If the Go1 default checkpoint is missing, download it before connecting:

python example/mujoco/tools/download_go1_policy.py --name go1_velocity

For the optional rough-terrain checkpoint, download and select it explicitly:

python example/mujoco/tools/download_go1_policy.py --name go1_rough_velocity
python example/mujoco/mujoco_robot_demo.py go1 checkpoint --policy example/mujoco/policies/go1/rough_velocity/policy.onnx --command-vx 0.5 --duration 20

The second command requires the running UE session described below. Download availability, policy quality, and hardware performance are not established by source inspection.

Launch and single-robot control

Go1 keyboard control in UnrealZoo
Go1 keyboard control in UnrealZoo

Connect to a manually started environment

Start the v3.1.1 packaged binary, load a map with usable collision geometry, and wait until UnrealCV listens on 127.0.0.1:9000. Alternatively, start Play in Editor (PIE) in the compatible project. Place Camera 0 over suitable ground: by default the demo spawns the selected robot in front of it and settles it onto collision geometry. Run one controller at a time, from the repository root:

python example/mujoco/mujoco_robot_demo.py go1 keyboard --host 127.0.0.1 --port 9000

I/K moves forward/backward, J/L turns, Space stops, and X/Esc exits. Substitute g1 or microduck for go1 to use their corresponding policies:

python example/mujoco/mujoco_robot_demo.py g1 keyboard --host 127.0.0.1 --port 9000
python example/mujoco/mujoco_robot_demo.py microduck keyboard --host 127.0.0.1 --port 9000

These are alternatives, not concurrent controllers. For a fixed velocity command instead of keyboard input:

python example/mujoco/mujoco_robot_demo.py go1 checkpoint --host 127.0.0.1 --port 9000 --command-vx 0.5 --command-vy 0.0 --command-yaw 0.0 --duration 20

checkpoint means continuous pretrained-policy playback, not training. --duration 0 runs until stopped; the default --warmup 1.0 initially sends a zero command. Use --actor NAME to reuse an existing robot or --keep-actor to keep one spawned by the demo. Cleanup removes only the actor owned by that demo; attaching does not give it ownership of the editor process.

Automatically launch a packaged environment

The CLI above only connects. For owned process launch, use the Python API with setting_file and launch=True. The supplied Mujoco/SuburbNeighborhood_Day.json currently names a Windows v3.1.1 executable, a Linux v3.0.0 executable, and a placeholder macOS path. Do not interpret that file as a verified cross-platform MuJoCo release. On Linux/macOS, provide a setting with an actual compatible executable; installing Python dependencies cannot fix a missing build.

For the supplied Windows layout, set UnrealEnv in PowerShell to the directory containing the extracted environment folder (replace the example path):

$env:UnrealEnv = 'I:/UnrealProject/UnrealZoo_UE5_7/Binaries'

Run this Python example in the same environment. It launches on reset(), configures G1 before model compilation, and closes its owned process:

import gym_unrealcv

env = gym_unrealcv.make_mujoco_env(
    "g1",
    setting_file="Mujoco/SuburbNeighborhood_Day.json",
    launch=True,
    physics_config={"timestep": 0.002, "control_decimation": 10},
)
try:
    observation = env.reset()
    print(env.observation_space, env.action_space)
finally:
    env.close()

This initialization check does not execute a learned policy. Without a setting file the API defaults to connecting to an existing server; passing launch=False explicitly also selects attachment. See the actual setting and physics guide.

Gym API and physics configuration

The base API uses observation = env.reset() and observation, reward, done, info = env.step(action). Use a compatible policy to generate actions; sampling random actions only tests the interface, not stable locomotion. Set velocity commands with env.unwrapped.set_command([vx, vy, yaw_rate]) when implementing a policy loop.

Physics is configured after actor creation and before MuJoCo model compilation. Stop and recreate the simulation to reconfigure it. Runtime physics_config overrides robot-specific settings, which override common settings and defaults. Supported keys include timestep, control_decimation, gravity, solver_iterations, joint damping/armature/friction-loss scales, geometry friction scales, and actuator force-limit scale.

The control period is timestep * control_decimation: Go1 and MicroDuck default to 0.005 * 4, G1 to 0.002 * 10, all 20 ms. Changing only one parameter changes policy timing; changing CLI --hz only changes loop pacing, not the compiled physics configuration. See physics details rather than tuning against an assumed policy frequency.

Go1 visual Parkour

Go1 Parkour: third-person and depth views
Go1 Parkour: third-person and depth views
Go1 Parkour: third-person view
Go1 Parkour: third-person view
Go1 Parkour: depth observation
Go1 Parkour: depth observation

Install the PyTorch extra first. This offline checkpoint load/inference check does not need a running UE server:

python example/mujoco/parkour/demo.py --self-test --device cpu

Then start the compatible rendered UE session and run:

python example/mujoco/parkour/demo.py --host 127.0.0.1 --port 9000 --camera-id auto --vx 1.0 --command-ramp 0 --device cpu

The camera selector prefers the acquired Go1's FusionCamSensor and creates a temporary fallback only if needed. --preserve-attached-camera-pose retains Blueprint-authored extrinsics. I/K, J/L, Space, and X/Esc control movement, turning, stopping, and exiting. On Windows, the default keyboard mode is hold-to-move, --keyboard-mode latch keeps the last command, and R resets recurrent state. On Linux/macOS (POSIX), terminal key commands remain active until replaced or stopped with Space; releasing a key does not stop motion, R reset is not implemented, and --keyboard-mode hold does not add Windows-style key-release handling.

Use --no-visualize-observation to disable the live raw/processed depth dashboard. Diagnostic captures go to artifacts/mujoco/parkour_observation_debug. Rendering/depth is still required: disabling the dashboard is not NullRHI support. The parser requires --policy-hz 50; do not change it to compensate for slow rendering.

The checkpoint was trained for discrete Parkour obstacles, not arbitrary continuous staircases. Success depends on camera extrinsics, depth scale/latency, collision fidelity, joint ordering, and the training distribution. Detailed StaticMesh/Box collision may be necessary for steps; coarse Landscape heightfields can erase treads. See the Parkour guide and checkpoint notes.

Multi-robot scenarios

These scripts use the generic batch protocol directly; the upstream architecture still lists migration to UnrealCvMujocoBatchEnv as future work. They are not a single monolithic multi-robot physics world.

For MicroDuck skills, open /Game/SchoolGym/Maps/SchoolGymDay in PIE or the matching packaged map, retaining its four placed balls:

python example/mujoco/scenarios/schoolgym.py --host 127.0.0.1 --port 9000 --ducks 7 --vx 0.36 --duration 0

The seven policies demonstrate the skills listed above. The script reuses the balls and removes only robots it spawned. For DowntownWest, the showcase requires balls named StaticMeshActor_4, StaticMeshActor_6, and StaticMeshActor_8:

python example/mujoco/scenarios/downtown_showcase.py --host 127.0.0.1 --port 9000 --duration 0

It runs five MicroDucks and two Go1 robots using synchronized independent worlds, shared dynamic-ball state, and kinematic cross-world proxies. The follow-the-leader alternative runs one Go1 and three MicroDucks:

python example/mujoco/scenarios/downtown_follow.py --host 127.0.0.1 --port 9000 --duration 0

X, Esc, or Ctrl+C ends a scenario and cleans up spawned robots. Read the scenario setup before changing maps or actor names.

Training and runtime limits

For learning rather than playback, follow the separate Go1 PPO guide. train_go1_ue.py learns from MuJoCo transitions inside UE, with randomly initialized actor/critic on fresh runs. It has its own pinned Python 3.11/PyTorch/RSL-RL setup and MJLab source requirement; the base extra is not a substitute for that runtime.

The UE trainer steps independent MuJoCo models on CPU; the neural policy may use CPU or CUDA. NullRHI removes rendering, not CPU physics. The v2 task requires matching plugin endpoints and is limited to static scenes, excluding shared dynamic props, robot-to-robot collisions, and visual RL. The separate train_go1.py native MJLab/MuJoCo Warp baseline is not UE training and does not establish UE throughput or checkpoint compatibility. Measure stepping/reset capacity before scaling; no universal real-time rate or GPU count is promised here.

Troubleshooting

Symptom Check
Connection refused or timeout Start the correct binary/PIE, wait for map load, check host/port and UnrealCV availability, and stop competing controllers.
Missing Blueprint or unsupported MuJoCo command Confirm the packaged assets and embedded plugin version. Updating gym_unrealcv or unrealcv in Python does not update a packaged UE plugin.
Checkpoint missing or incompatible dimensions Check the source-tree policy paths, downloader result, observation/action layout, and policy provenance. Use --policy for Go1/G1, or --walking and --standing for MicroDuck.
Robot falls or spawns incorrectly Place Camera 0 over collision geometry or supply all three --spawn-x, --spawn-y, --spawn-z coordinates (UE cm); verify joint mapping and physics/control frequency before changing policy gains.
Parkour depth is wrong or stairs fail Inspect raw/processed depth, camera pose, --depth-scale, latency, and collision fidelity. Try --self-test to separate checkpoint loading from UE integration; it does not validate cameras or terrain.
Automatic launch fails Check UnrealEnv, the setting's platform-specific executable, permissions, and the actual binary version. The bundled Linux/macOS paths are not proof of compatible build availability.
Keyboard/dashboard unavailable Use a session with input/display access; for the unified demo choose fixed-command checkpoint mode, or disable the Parkour dashboard with --no-visualize-observation.

Source compatibility alone does not establish runtime success. Validate checkpoint inference, camera observations, collisions, and hardware performance in the target environment; consult the linked upstream guides for configuration and diagnostics.