The sim-to-real gap
Why a controller that works perfectly in simulation can overshoot, lag or oscillate on hardware when the simulator omits friction, mass errors, latency, saturation or noise.
What it demonstrates
Why a controller that works perfectly in simulation can overshoot, lag or oscillate on hardware when the simulator omits friction, mass errors, latency, saturation or noise.
How it works
Two copies of the same 1-D robot run in parallel with an identical PD controller tuned on the ideal model. The ‘simulated’ copy uses the nominal model: no dry friction, nominal mass, no delay, effectively unlimited force.
The ‘real’ copy adds whichever unmodelled effects you enable. Both follow the same square-wave target. The difference between the two traces is the sim-to-real gap for this controller.
Adjustable parameters
- Friction on/off
- +35% mass on/off
- Latency on/off and 5–150 ms
- 8 N actuator limit on/off
- Sensor noise on/off
Known limitations
- The ‘real’ robot is still a simulation. It shows the kind of gap, not real numbers.
- Real sim-to-real gaps also come from contact dynamics, backlash, compliance, thermal effects and unmodelled software paths.
Equations
Core update rule
const tgt = squareWave(t); // same command for both
stepLoop(simRobot, dt, NOMINAL_PLANT, CONTROLLER);
stepLoop(realRobot, dt, realPlant(gaps), { ...CONTROLLER, latency, noise });
gap = Math.abs(realRobot.x - simRobot.x);Explained in Chapter 1: Physical AI