3 MuJoCo Sim2Sim Validation
Before deploying to the real robot, use MuJoCo (a different physics engine from training) to validate the transferability of the exported ONNX policy across engines, and use fidelity parameters to isolate the sim2real gap dimension by dimension. This is the last software-validation step before going to the real robot.
Unless stated otherwise, all commands below are run from the code root directory (the root of the SDK main repo); the sim2sim scripts live in extra/mc-rl/rl/sim2sim/.
3.1 Overview: why sim2sim is needed
Training runs in Isaac Lab (the PhysX engine) and deployment runs on the real robot; between them lie engine differences, calibration differences, and latency differences. Deploying a trained policy directly to the real robot is risky and costly to debug. sim2sim adds a validation step in the middle of this pipeline: it loads the same policy.onnx in MuJoCo (a different physics engine) to verify that the policy has not merely overfit to PhysX but has genuinely learned a transferable gait.
Validation script:
extra/mc-rl/rl/sim2sim/sim2sim_x2.py(with GUI, FSM, keyboard control, external-force disturbance, and recording).Default model: to evaluate the in-repo deployment model, explicitly pass
--onnx extra/mc-rl/x2_deploy_pkg/models/policy.onnx(the script’s built-in--onnxdefault points to a training-export path, not the in-repo deployment model).
3.2 Running sim2sim_x2.py
The script offers four usage modes, for: interactively walking through the full FSM, walking with RL directly to inspect metrics, explicitly specifying an ONNX model file, and recording video without a GUI.
MuJoCo sim2sim: the policy walks forward steadily at cmd_vx inside MuJoCo (50 Hz inference, cross-engine validation of the same policy.onnx).
conda activate isaaclab
# Usage A: full FSM + real-time keyboard control (WASD+QE), closest to the state-machine logic of `extra/mc-rl/x2_deploy_pkg/deploy_x2.py`
python extra/mc-rl/rl/sim2sim/sim2sim_x2.py
# Usage B: skip the FSM and walk with RL directly, specifying forward speed
python extra/mc-rl/rl/sim2sim/sim2sim_x2.py --no-fsm --cmd_vx 0.3
# Usage C: explicitly specify the ONNX model file (e.g. to evaluate the in-repo deployment model or a model exported from a training run)
python extra/mc-rl/rl/sim2sim/sim2sim_x2.py \
--onnx extra/mc-rl/x2_deploy_pkg/models/policy.onnx
# You can also specify a model exported from a particular training run
python extra/mc-rl/rl/sim2sim/sim2sim_x2.py \
--onnx extra/mc-rl/rl/agibot_rl_lab/logs/rsl_rl/agibot_x2_29dof_velocity/<run>/exported/policy.onnx
# Usage D: no GUI (e.g. remote server / no desktop), EGL offscreen video recording
MUJOCO_GL=egl python extra/mc-rl/rl/sim2sim/sim2sim_x2.py --no-fsm --cmd_vx 0.3 --record sim_walk.mp4 --duration 10
Warning
Usage A and B use the MuJoCo viewer, which requires a GLX desktop environment; without a GUI you can only use Usage D (--record together with MUJOCO_GL=egl offscreen rendering), otherwise the viewer cannot start.
Parameter Table
Argument |
Default |
Description |
|---|---|---|
|
A training-export path (not the in-repo deployment model) |
ONNX model path; to evaluate the in-repo deployment model you must explicitly pass |
|
|
MuJoCo scene XML |
|
|
Fixed forward speed (m/s), effective only in |
|
|
Fixed lateral speed |
|
|
Fixed turning angular velocity |
|
false |
Skip the FSM and go straight to |
|
None |
Record video to a file (e.g. |
|
|
Simulation duration (seconds), effective only in |
|
|
In FSM mode, the value |
|
|
W/S speed-adjustment step |
|
|
Upper/lower bounds on forward speed |
|
|
A/D lateral speed-adjustment step (clamped to ±0.3) |
|
|
Q/E turning speed-adjustment step (clamped to ±0.2) |
|
|
Simulate an IMU pitch zero-point bias: add a constant to projected_gravity[x]. Positive = the robot actually leans forward, negative = leans back (e.g. |
External-force disturbances are applied via interactive keys (I/J/K/L/U + digits 1–5); see “Keyboard Control” above.
Keyboard Control
The full FSM transition is DAMPING → [Enter/Space] → JOINT_DEFAULT → STANDUP → RL_ACTIVE. On entering RL_ACTIVE, forward_velocity=0 (stand steady first); it only walks after you press W.
Key |
Action |
|---|---|
|
|
|
Forward / backward ±step. Note: the first W press jumps directly from 0 to |
|
Strafe left / right ±vy_step |
|
Turn left / right ±vyaw_step |
|
Apply a single 100ms force impulse: forward / backward / left / right (base 100N, can be scaled up by the digit keys) |
|
Apply a single force impulse in a random direction (base 150N) |
|
Set the force multiplier (1=100N … 5=500N); takes effect on the next direction-key press |
|
Switch to |
|
Exit under |
|
Print the full key-binding help |
The key bindings match
extra/mc-rl/x2_deploy_pkg/deploy_x2.py, so operating habits from sim2sim transfer directly to the real robot. UnderRL_ACTIVE, if the orientation exceedsGRAVITY_PITCH_LIMIT=0.72(about a 46° tilt, aligned with the trainingbad_orientationlimit_angle=0.8), it automatically entersESTOP.
3.3 Comparison of the Three Control Frequencies
The policy frequency is a constant 50 Hz (POLICY_DT=0.02); across the three ends only the low-level physics timestep and decimation differ — this is one of the premises that make sim2sim valid: the policy runs inference every 20 ms, independent of the low-level PD frequency.
Environment |
sim_dt |
PD frequency |
decimation |
Policy frequency |
|---|---|---|---|---|
Isaac Lab training |
0.005 s |
200 Hz |
4 |
50 Hz |
MuJoCo Sim2Sim |
0.001 s |
1000 Hz |
20 |
50 Hz |
Real robot |
~0.001 s |
~1000 Hz |
Sent at 200 Hz ( |
50 Hz |
On the sim2sim side,
SIM_DT=0.001andDECIMATION = int(POLICY_DT / SIM_DT) = int(0.02 / 0.001) = 20are defined inextra/mc-rl/x2_config/sim/sim_config.py(POLICY_DTcomes from the shared source of truthextra/mc-rl/x2_config/shared/policy_defs.py), i.e. one policy inference every 20 physics steps at 1 kHz, equal to 50 Hz.The real-robot 200 Hz output corresponds to
CONTROL_DT=0.005inextra/mc-rl/x2_deploy_pkg/deploy_x2.py(the control loop runs one policy inference everyint(POLICY_DT/CONTROL_DT)=4ticks = 50 Hz). The low-level motor PD inner loop runs at roughly 1 kHz or more inside the driver, which is a separate concept from the output frequency.
The Two Things That Must Match Across All Three Ends
Matching frequency alone is not enough; only when the joint order and observation structure match bit-for-bit across all three ends is it valid. Otherwise the observations the policy reads are misaligned and the actions it outputs are misaligned too, which looks like policy failure but is really a data-alignment error. The joint order, observation structure, and constants such as ACTION_SCALE, OBS_TERM_DIMS, and HISTORY_LENGTH that must be identical across the three ends are defined in one place: extra/mc-rl/x2_config/shared/policy_defs.py.
Action mapping:
target_pos = action × 0.25 + default_pos(ACTION_SCALE = 0.25). The 29-dim action is mapped to joint target positions viaACTION_JOINT_ORDER, then PD-controlled.Observation structure: obs is 500-dim, i.e. 100 dims per frame × 5 frames of history (
HISTORY_LENGTH=5). Each 100-dim frame is the concatenation of 6 terms inOBS_TERM_DIMSorder:obs term
Dim
scale
base_ang_vel
3
×0.25
projected_gravity
3
×1.0
velocity_commands
3
×1.0
joint_pos_rel
31
(relative to default, ×1.0)
joint_vel_rel
31
×0.05
last_action
29
×1.0
Total 3+3+3+31+31+29 = 100, ×5 = 500.
joint_pos_rel and joint_vel_rel use 31 dims (the URDF has 31 revolute joints, including head_yaw / head_pitch), while the action is only 29 dims (the head does not participate in RL). On the MuJoCo side the head joints are set to
KP=0(no position tracking) andKD=2.0(velocity damping only), i.e. not driven by the policy and damped to rest, with negligible effect on the policy.The joint_vel scale is 0.05 on the training side (the unitree_rl_lab convention); training and deployment must stay internally consistent and must not be mixed.
History concatenation is done per-term (each obs term maintains its own 5-frame CircularBuffer, oldest first), not per-frame. Concatenating this incorrectly causes clearly abnormal policy behavior (see “Troubleshooting” below).
3.4 Acceptance Criteria: What “sim2sim Passes” Means
The core criterion is stable forward walking at cmd_vx=0.2. A valid policy should produce meter-scale displacement in 10s at cmd_vx=0.2 (actual speed about 0.16 m/s); if the displacement approaches 0 and it roughly marches in place, it does not pass.
Metric |
Passing criterion |
Description |
|---|---|---|
Forward displacement |
At cmd_vx=0.2, about 1.5 m or more per 10s (actual speed about 0.16 m/s) |
As long as it matches the command magnitude; in low-speed tasks the actual speed being slightly below the command value is normal |
Action norm |a| at steady state |
About 3.2–3.7 |
Matches real-robot measurements; too large indicates jitter, too small may indicate the policy has stalled and is standing still in place |
yaw drift |
The smaller the better; under a straight-line command the systematic yaw-rate bias should be close to 0 |
See the in-depth evaluation below |
pelvis height |
Stays near the training base_height (0.68) with a small standard deviation |
|
In-Depth Evaluation: 30s and Multiple Seeds
A 10s snapshot is not enough to expose accumulated yaw drift — yaw is a cumulative quantity, and a systematic bias is hard to see over a short time. The following is recommended:
Extend the duration to 30s: observe whether yaw drifts persistently in one direction (rather than oscillating) within a single trajectory. If the yaw-rate center has a stable non-zero bias (e.g. a steady −0.03 rad/s under a straight command, accumulating about −50° over 30s), the policy has a systematic yaw bias (an intrinsic behavior, not instability).
5-seed joint perturbation (±0.02 rad/joint): compute the mean and standard deviation of yaw. A small standard deviation means the bias is intrinsic and reproducible; a large one means the policy is sensitive to initial perturbation and less robust.
Bring test commands back within the training distribution: the training commands are a curriculum-based range — initially ±0.1 per axis, with curriculum upper limits
x ∈ (−1.0, 1.0),y ∈ (−0.3, 0.3),yaw ∈ (−0.2, 0.2)(seelimit_rangesin the trainingvelocity_env_cfg.py). Evaluation should stay within this range: vx can go up to 1.0, but avyawabove 0.2 is outside the training distribution and tests extrapolation failure rather than policy quality.
Warning
Evaluation limitations: sim2sim is done on flat ground with fixed commands and zero initial velocity; the real robot has rough terrain, changing teleop commands, and external disturbances. Good sim2sim robustness data does not guarantee passing on the real robot — the sim-real gap is not fully covered by the current evaluation. Passing sim2sim is a necessary condition, not a sufficient one.
3.5 Headless Evaluation and Recording
Without a GUI (remote server / no desktop), use --record together with MUJOCO_GL=egl offscreen rendering to run a fixed command, record video, and print metrics (such as Pelvis height: mean ± std, steady-state |a|, and forward displacement):
conda activate isaaclab
# 30s straight-line evaluation with recording (evaluating the in-repo deployment model)
MUJOCO_GL=egl python extra/mc-rl/rl/sim2sim/sim2sim_x2.py --no-fsm --cmd_vx 0.2 \
--onnx extra/mc-rl/x2_deploy_pkg/models/policy.onnx --record sim_walk.mp4 --duration 30
For multi-model / multi-scenario batch regression, wrap this script in a shell loop and call it multiple times (passing different --onnx and commands each time).
3.6 Disturbance-Rejection and Fidelity Testing
sim2sim_x2.py currently provides two kinds of sim2real-related test tools, both diagnostic / research tools rather than training configuration:
External-force disturbance rejection: after a single force impulse is applied to the torso, the policy recovers its gait on its own (I/J/K/L selects the direction, digits 1–5 set the force multiplier; see “Keyboard Control” above).
Interactive external-force disturbance (see “Keyboard Control” above):
I/J/K/Lfor forward / backward / left / right andUfor a random direction apply a 100ms force impulse to the torso; digits1–5set the force multiplier (1=100N … 5=500N, base 150N for random direction). Used to observe the policy’s recovery under pushes of different directions and strengths.IMU pitch zero-point bias (
--imu_pitch_bias): add a constant bias to projected_gravity[x] to simulate an attitude zero-offset caused by real-robot IMU mounting / calibration, aligned with the training-side IMU-bias domain randomization. Sweeping this parameter alone shows the policy’s tolerance to attitude zero-offset.
Warning
The PD gains (KP / KD) used by sim2sim come from the single source of truth extra/mc-rl/x2_config/joint_gains.yaml (model X2 T2.5); training (agibot.py), sim2sim, and deployment (extra/mc-rl/x2_deploy_pkg/deploy_x2.py) all load from this file, so a change in one place takes effect in all three. These gains are simulation values, not real-robot measurements; once real-robot calibration values are obtained, editing the YAML applies to all three.
3.7 Troubleshooting
Symptom |
Cause |
Solution |
|---|---|---|
Clearly abnormal sim2sim behavior |
obs history mistakenly concatenated per-frame |
Switch to per-term: each obs term maintains its own 5-frame history buffer ( |
The viewer cannot start without a GUI |
The viewer requires a GLX desktop environment |
Use |
The policy stalls and stays in place, with |a| tending to a constant |
Excessive regularization causes the policy to converge, in MuJoCo (deterministic, no exploration noise), to a local optimum of “constant action, standing still” |
This is a model problem, not a script defect: reduce regularization and retrain, or switch to a checkpoint that walks properly |
Stays in place when cmd_vx < 0.2 |
Empirically the policy only walks stably at cmd_vx ≥ 0.2, and stays still at low speeds by default |
Start with |
On the difference between the FSM
DAMPINGstate and the real robot: sim2sim’sDAMPINGstate is simulated with a PD hold (apply_dampingsends-DAMPING_KD * vel, withDAMPING_KD=4.0matching the deploy-measured value). In simulation, truly setting kp=0 would collapse to the ground and prevent standing up, so simulation uses a PD hold while the real robot uses true damping — this is a known, intentional difference, not a defect.
After sim2sim passes, proceed to Real-Robot Sim2Real Deployment.