Foundations to Frontier
Tests

Reinforcement learning for robots

Robots are where reinforcement learning meets physics: real hardware is slow, fragile and expensive to run, so most policies are trained in simulation and then transferred, and the gap between simulator and reality decides whether they work. This page trains linear balancing policies for a cart-pole by policy search, in a nominal simulator and in randomised ones, and tests them on a mismatched 'real' robot with a weaker motor, a heavier pole, sensor noise and actuator delay. Sections S, U and V cover robot learning in full.

Level 0: Foundation

★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.

Practising in a video game before the real thing

Pilots train in flight simulators before flying real aircraft, because mistakes in the simulator cost nothing. Robots learn the same way: they practise millions of times in a computer simulation and are then put into the real world. The catch is that no simulator is perfect. A policy that has only ever seen the perfect simulated robot may fail on a real one whose motor is a little weaker or reacts a little later. One remedy is to make the simulator deliberately varied, so the robot learns to cope with a whole range of possible worlds.

Planning and control lab
falls at ±0.21 rad10 s
Pole angle of a cart-pole balanced by a linear policy u = k·(position, velocity, angle, angular velocity) with gains k = [3.84, 5.38, 71.83, 10.43], found by policy search in the nominal simulator (Exercise 2 of this topic, seed 0). The randomised simulators varied masses, pole length and motor strength and added 0–80 ms of actuator delay and sensor noise. On this robot (delay 80 ms, motor ×0.7, pole 0.2 kg): fell after 0.92 s. The nominal policy's high gains are best in its own simulator but leave no room for delay.
Why engineers care

Simulation-trained policies now let robot hands rotate cubes, quadrupeds walk over rough terrain, and drones race at championship level.

📝 Quick check (Level 0)
0/3 answered
  1. 1. Robots are usually trained first in…
  2. 2. The sim-to-real gap is…
  3. 3. Domain randomisation trains on…

Level 1: Beginner

★★☆☆☆ Basic⏱ 20 minSecondary-school mathematics: arithmetic and elementary algebra.

By hand

  • Sim-to-real transfer: training a policy in simulation and deploying it on hardware.
  • Reality gap: the systematic differences between simulator and robot: masses, friction, motor strength, sensor noise, latency, contact behaviour.
  • Domain randomisation: randomising simulator parameters during training so the policy must work across all of them; the real robot is then, hopefully, just one more sample.
  • System identification: measuring the robot’s real parameters (such as delay) to make the simulator, or the randomisation ranges, more accurate.
  • Actuator latency: the time between a command and the motor acting on it; a few tens of milliseconds can destabilise an aggressive controller.
  • Policy search: optimising the parameters of a policy directly from returns, for example with random search or the cross-entropy method.
  • Observation normalisation and action smoothing: standard engineering for robot policies, putting sensors on one scale and stopping motor chatter.
  • Reward shaping: extra rewards that guide learning, such as potential-based terms for distance to a target.
📝 Quick check (Level 1)
0/3 answered
  1. 1. Domain randomisation varies…
  2. 2. Measuring the real robot's delay is a form of…
  3. 3. Actuator latency is…

Level 2: Intermediate

★★★☆☆ Intermediate⏱ 25 minUndergraduate students and practising engineers.

Policy search with and without randomisation

Exercise 1.

  • The cart-pole of topic L6-3 (steps of 20 ms, force limited to ±10 N), simulated for many robots at once with numpy.
  • A robot sampler: each parameter (cart mass, pole mass, pole length, motor strength) is the nominal value times a factor in [1 − spread, 1 + spread]; randomised robots also get 0 to 80 ms of actuator delay and sensor noise.
  • A linear policy u = k·(position, velocity, angle, angular velocity); episodes end when the pole passes 0.21 rad or the cart leaves ±2.4 m, with up to 500 steps and reward near 1 per step for staying upright and centred.
  • Policy search by the cross-entropy method over the 4 gains, scoring every candidate on the same 16 training robots and start angles.

Practice.

  • Model the effects that matter: latency, motor limits, sensor noise and contact are the usual culprits; measure them on the robot first.
  • Randomise ranges around measured values, wide enough to cover the uncertainty but not so wide that the task becomes impossible.
  • Use massively parallel simulation (Isaac Gym, MuJoCo XLA) to make randomised training affordable.
  • Smooth and limit actions, normalise observations, and test on hardware incrementally with safety stops.
  • Adapt online when randomisation is not enough: learned adaptation modules (RMA) or system identification during deployment.
def policy_search(rng, spread, n_robots=16, pop=32, elite=6, iters=20):
    R = tile(robots(rng, n_robots, spread), pop)          # same robots for every candidate
    x0 = np.tile(rng.uniform(-0.15, 0.15, n_robots), pop)
    mu, sd = np.array([0.0, 5.0, 30.0, 10.0]), np.array([5.0, 5.0, 15.0, 5.0])
    for _ in range(iters):
        TH = mu + sd * rng.normal(size=(pop, 4))          # candidate gains
        r, _ = rollout(np.repeat(TH, n_robots, 0), R, np.random.default_rng(0), x0)
        score = r.reshape(pop, n_robots).mean(1)          # average over robots
        e = TH[np.argsort(-score)[:elite]]
        mu, sd = e.mean(0), e.std(0) + 0.2
    return mu
🐍 Exercise 1: a batched robot simulator
Build a batched, randomisable cart-pole simulator, check it against one-at-a-time simulation, and find balancing gains by policy search in the nominal simulator.
📝 Quick check (Level 2)
0/3 answered
  1. 1. Before randomising, measure…
  2. 2. Massively parallel simulators include…
  3. 3. When randomisation is not enough, use…

Level 3: Advanced

★★★★☆ Advanced⏱ 25 minGraduate level, with full derivations and proofs.

Theory

Why optimising for one simulator is fragile. Policy search maximises return in the training simulator. With exact, delay-free dynamics, higher gains correct errors faster and score slightly better, so the optimiser drives them up. High gains, however, shrink the margin for delay: a correction applied 80 ms late overshoots, and the next correction overshoots more. The policy is optimal for a world that does not exist.

Domain randomisation as robust optimisation. Averaging the return over randomised parameters optimises the expected performance over a distribution of worlds. Any policy that scores well must work across the whole range, including long delays and weak motors, so the optimiser prefers moderate gains. If the real robot lies inside the training distribution, it is just another sample.

The price of robustness. A policy that must work everywhere is slightly worse in any particular world; here the randomised policies lose about one point of return in the nominal simulator. Too wide a distribution can make the task impossible or the policy overly timid, which is why ranges are set around measured values.

Beyond randomisation. Policies with memory (recurrent networks) can infer the current dynamics from recent history and adapt; teacher–student training uses privileged simulator information to train a teacher, then distils it into a student that sees only real sensors. Sections S, U and V develop these methods.

📝 Quick check (Level 3)
0/3 answered
  1. 1. Optimising in a delay-free simulator drove the gains…
  2. 2. Domain randomisation optimises…
  3. 3. Policies with memory can…

Level 4: Expert

★★★★★ Expert⏱ 30 minResearchers: original papers and open problems.

Does a policy trained in a perfect simulator survive a mismatched robot with actuator delay, and how much does training with randomised parameters help?

History.

  • J. Tobin and colleagues (2017) introduced domain randomisation for visual sim-to-real transfer; X. Peng and colleagues (2018) randomised dynamics for a robot arm.
  • J. Tan and colleagues (2018) trained quadruped gaits in simulation with identified actuator models and latency.
  • OpenAI (2019) solved a Rubik’s cube with a robot hand trained with automatic domain randomisation.
  • J. Hwangbo and colleagues (2019) and J. Lee and colleagues (2020) brought learned locomotion to ANYmal; A. Kumar and colleagues (2021) introduced rapid motor adaptation (RMA); E. Kaufmann and colleagues (2023) beat human drone-racing champions.

Exercise 2.

  • Three policies by policy search: in the nominal simulator, and in simulators randomised by ±30% and ±60% (both with 0 to 80 ms of delay and sensor noise).
  • Tests: 200 episodes in the nominal simulator; 200 random robots with ±60% parameters; and a fixed ‘real’ robot that none of the simulators matched exactly (pole twice as heavy, motor 30% weaker, sensor noise) with actuator delays of 0, 40, 60 and 80 ms, 100 episodes each.
  • Survival means balancing for the full 10 s.

Survival on the real robot with an 80 ms delay, and on random ±60% robots:

trained in seed 0 seed 1 seed 2 random robots (seeds 0–2)
nominal simulator 0.00 0.00 0.00 0.655, 0.72, 0.63
randomised ±30% 0.98 1.00 1.00 0.83, 0.93, 0.90
randomised ±60% 1.00 1.00 1.00 0.945, 0.965, 0.93

Seed 0 gains (position, velocity, angle, angular velocity): nominal [3.8, 5.4, 71.8, 10.4]; ±30% [1.7, 3.1, 33.2, 7.8]; ±60% [1.2, 2.7, 47.1, 15.4].

Findings.

  • In its own simulator the nominal policy was best, with returns of 499.2 to 499.4 out of 500, against 497.6 to 498.8 for the ±60% policy.
  • On the real robot it worked up to 60 ms of delay and failed in every episode at 80 ms, on all three seeds; both randomised policies survived 98 to 100% of those episodes.
  • The nominal policy had the highest angle gains (55.7 to 78.3, against 33.2 to 51.3 for the randomised ones). Its aggressiveness is what the delay punished.
  • Wider randomisation gave more robustness on random robots (0.93 to 0.965 survival for ±60% against 0.63 to 0.72 for nominal), at a small cost in nominal return.
🐍 Exercise 2 (research): does a policy trained in a perfect simulator survive a mismatched robot with actuator delay, and how much does training with randomised parameters help?
Train linear cart-pole policies by policy search in a nominal and in randomised simulators, and test them on a mismatched robot with actuator delay.

RL on real robots

  • Legged locomotion: policies trained in massively parallel simulation with randomised terrain and dynamics walk and run on ANYmal, Unitree and Spot robots.
  • Dexterous manipulation: in-hand reorientation and assembly use randomisation plus vision trained on synthetic images.
  • Aerial robots: drone racing combines simulation-trained policies with residual models identified from real flights.
  • Safety and data efficiency: real-world fine-tuning, offline RL from logged data (topic L5-2) and safe exploration (topic L5-6) reduce wear and risk.

References

  1. J. Tobin and colleagues (2017). “Domain randomization for transferring deep neural networks from simulation to the real world.” IROS.
  2. X. Peng, M. Andrychowicz, W. Zaremba and P. Abbeel (2018). “Sim-to-real transfer of robotic control with dynamics randomization.” ICRA.
  3. J. Tan and colleagues (2018). “Sim-to-real: learning agile locomotion for quadruped robots.” RSS.
  4. A. Kumar, Z. Fu, D. Pathak and J. Malik (2021). “RMA: rapid motor adaptation for legged robots.” RSS.
  5. E. Kaufmann and colleagues (2023). “Champion-level drone racing using deep reinforcement learning.” Nature.