Part IV · Competencies: RL on Real Robots
18.Learning Locomotion
“DRL has shown effectiveness in synthesizing robust and adaptive locomotion controllers for challenging conditions — the dynamics involved are relatively stable and easy to simulate, and dense shaped rewards simplify exploration.”
Locomotion is the competency where robot RL genuinely won. Learned controllers ship in commercial quadrupeds, and rough-terrain walking that defeated three decades of model-based control fell to a fairly standard PPO pipeline. This chapter explains why locomotion and not something else, then builds the full recipe on Ferris: observation and action design, the reward function term by term with its units, terrain curricula, and the teacher–student transfer of Chapter 15. It closes on bipeds and flight, where the same recipe meets harder problems.
Foundation
Gait phase formalism, reward-term algebra with dimensional analysis, curricula as distribution scheduling, and the privileged-information argument specialized to terrain.
Conceptual
The reward mixer: slide the weights and watch the gait that would emerge, with each term's physical units shown.
Practical
Ferris as a 12-DoF rapier3d quadruped with PD joints, PPO over rayon-parallel randomized environments, and a terrain generator with difficulty scheduling.
After this chapter you can
- Explain why locomotion transferred to hardware before manipulation did
- Design a locomotion observation and action space, and justify each choice
- Write a locomotion reward term by term with correct units and defensible weights
- Construct a terrain curriculum and explain it as scheduling a distribution
- Assemble the full teacher–student pipeline and say what each stage contributes
- Explain what makes bipeds and quadrotors harder than quadrupeds
18.1 Why locomotion won first
Chapter 1's maturity ladder put locomotion at L4–L5 while manipulation sat at L2. That gap is not about effort or talent — it follows from four structural properties, and knowing them tells you when to expect RL to work on a new problem.
The dynamics simulate well. A walking robot is rigid bodies under gravity with intermittent point contacts. Physics engines are good at exactly that. Chapter 15 explained where they are bad — sustained sliding contact, deformation, precise friction — and locomotion mostly avoids those regimes.
Rewards are dense and writable. "Track this velocity command" gives a signal at every timestep. Compare with "assemble this device", where the reward is a single bit arriving minutes later.
Failure is cheap and recoverable. A quadruped that falls gets up. A manipulator that misjudges contact can destroy the workpiece, itself, or a person. That difference decides how freely you can explore.
The task is naturally continuous and repetitive. Millions of gait cycles are one long trajectory, which is exactly the regime where on-policy methods with massive parallelism shine.
18.2 Ferris: observations and actions
Ferris has 12 actuated joints — hip abduction, hip flexion and knee per leg.
Observations (the deployable set, what the student policy sees):
| Component | Dimension | Why |
|---|---|---|
| Base angular velocity | 3 | IMU gyro, directly measured |
| Projected gravity | 3 | Orientation without an absolute heading — invariant to yaw |
| Velocity command | 3 | — the task |
| Joint positions | 12 | Encoders |
| Joint velocities | 12 | Differentiated encoders |
| Previous action | 12 | Gives the policy access to its own recent output |
| Gait phase | 2 | — Chapter 17's CPG clock |
That is 47 numbers, all available on real hardware at 50 Hz.
Actions are joint position targets at 50 Hz, tracked by a 1 kHz PD loop with , . This is the mid-level choice from Chapter 17, and essentially the entire field has converged on it: the PD loop absorbs high-frequency dynamics, bounds the force the policy can command, and gives well-behaved gradients. Torque-level policies exist and learn much more slowly for no demonstrated benefit.
18.3 The reward function, term by term
Here is where locomotion papers actually differ from one another, and where most of the engineering time goes.
| Term | Formula | Units | Purpose |
|---|---|---|---|
| Velocity tracking | dimensionless | The task | |
| Yaw tracking | dimensionless | Turn as commanded | |
| Effort | N²·m² | Do not slam the actuators | |
| Orientation | dimensionless | Stay level | |
| Foot air time | s | Take real steps, do not shuffle | |
| Foot slip | m²/s² | Walk, do not skate | |
| Action smoothness | rad² | Protect the gearboxes |
Reward anatomy: the weights decide the gait
ch18-reward-mixerAn evolution strategy optimizes a real planar walker against the reward you specify. Move a weight and a different gait comes back.
Footfall pattern
Filled = foot loaded. Diagonal pairs alternate in a trot.
Outcome
—
Achieved speed
0m/s
commanded 0.90
Cost of transport
—
energy per unit weight-distance
Step frequency
0Hz
Where the return actually comes from
exp(−‖v_xy − v*‖² / σ)The task itself: move at the commanded speed.
−‖F‖²Force expended. Raise it and the gait chooses to go slower.
Σ_f (t_air − 0.15)Credited at touchdown, so it rewards real swings, not held feet.
−θ²Keeps the body level; the main thing between you and a faceplant.
−(|F_t| − μF_n)⁺Friction cone exceeded — the foot is sliding under load.
Set the effort penalty high and Ferris creeps. Set the air-time reward high and he prances, wasting energy on exaggerated swings. Drop the orientation term and he pitches forward until he falls. None of those is an algorithm failure — each is the optimizer correctly serving the objective it was given.
18.4 Gait as phase
A gait is a phase relationship between limbs. Give each foot a phase advancing at frequency , with a fixed offset defining the gait:
A trot sets diagonal pairs together: . A bound pairs front and rear: . Whether a foot should be in stance or swing is then a function of its phase.
Two ways to use this. Prescribe it — feed as observations and reward matching the intended contact schedule, giving fast, predictable learning of a specific gait. Or let it emerge — provide only a velocity-tracking reward and let the policy discover its own footfall pattern, which yields gaits that transition naturally with speed but takes longer and needs more careful reward shaping.
Modern systems typically prescribe a phase clock as an input while leaving the contact schedule unrewarded, getting organization without over-constraining the solution.
18.5 The terrain curriculum
Ferris cannot learn stairs by starting on stairs — he falls immediately, every episode, and there is no gradient. He must start on flat ground and progress.
Formally a curriculum schedules a distribution: at training stage , terrain parameters are drawn from , and the schedule advances only when performance justifies it. The standard mechanism is per-environment difficulty with promotion and demotion: an environment whose robot traversed most of its terrain advances a level; one whose robot fell drops a level. Difficulty tracks competence automatically, and no global schedule needs tuning.
Terrain types progress roughly as: flat → rough (Perlin noise) → gentle slopes → steps → stairs → discrete obstacles → gaps.
18.6 The full pipeline
Assembling everything from Part III:
- Build the simulation — Ferris in
rapier3d, 12 PD joints, procedural terrain, 4096 parallel environments. - Randomize (Chapter 15) — masses ±20%, friction 0.4–1.2, motor gains ±30%, latency 0–30 ms, plus random pushes.
- Train a teacher with privileged access — exact terrain heights under each foot, true friction, contact states. PPO (Chapter 10), a few billion simulated steps, hours on a GPU.
- Distill into a student (Chapter 15) — the student sees only the 47 deployable observations plus a history window, trained by DAgger-style imitation on its own state distribution (Chapter 16).
- Deploy zero-shot.
/// One additive term of the locomotion reward, with its physical units
/// recorded so logs and ablations remain interpretable.
pub struct RewardTerm {
pub name: &'static str,
pub units: &'static str,
pub weight: f64,
pub eval: fn(&FerrisState, &Command) -> f64,
}
pub fn velocity_tracking(s: &FerrisState, cmd: &Command) -> f64 {
let err = (s.base_lin_vel[0] - cmd.vx).powi(2) + (s.base_lin_vel[1] - cmd.vy).powi(2);
(-err / 0.25).exp() // dimensionless, in [0, 1]
}
pub fn foot_air_time(s: &FerrisState, _cmd: &Command) -> f64 {
// Reward deliberate swings — the standard cure for shuffling. Credited
// only at touchdown, so it cannot be farmed by holding a foot up forever.
s.feet
.iter()
.filter(|f| f.just_landed)
.map(|f| f.air_time - 0.5)
.sum::<f64>()
}
pub fn foot_slip(s: &FerrisState, _cmd: &Command) -> f64 {
s.feet
.iter()
.filter(|f| f.in_contact)
.map(|f| f.lin_vel.norm_squared())
.sum::<f64>()
}
pub fn default_terms() -> Vec<RewardTerm> {
vec![
RewardTerm { name: "vel_track", units: "-", weight: 1.0, eval: velocity_tracking },
RewardTerm { name: "yaw_track", units: "-", weight: 0.5, eval: yaw_tracking },
RewardTerm { name: "effort", units: "N²m²", weight: -2.0e-4, eval: torque_squared },
RewardTerm { name: "orient", units: "-", weight: -5.0, eval: gravity_xy_squared },
RewardTerm { name: "air_time", units: "s", weight: 1.0, eval: foot_air_time },
RewardTerm { name: "slip", units: "m²/s²", weight: -0.1, eval: foot_slip },
RewardTerm { name: "smooth", units: "rad²", weight: -0.01, eval: action_rate_squared },
]
}
/// Sum the terms, and return the per-term breakdown for the dashboard.
/// Logging terms separately is what makes reward debugging tractable.
pub fn total(terms: &[RewardTerm], s: &FerrisState, cmd: &Command) -> (f64, Vec<f64>) {
let parts: Vec<f64> = terms.iter().map(|t| t.weight * (t.eval)(s, cmd)).collect();
(parts.iter().sum(), parts)
}18.7 Bipeds and flight
Bipeds are harder for reasons that are structural rather than incidental. A quadruped in a trot always has two feet down and is statically stable much of the time; a biped in walking has long single-support phases and is never statically stable during them. Its support polygon is small — the area of one foot. Falling is expensive, since humanoids are top-heavy and fragile. And angular momentum management matters: arms and torso are not decoration, they are part of the control problem.
The recipe still applies, with more careful reward design (foot placement, centre-of-mass tracking, contact scheduling) and heavier reliance on reference motions — often motion-captured human walking — as either an imitation objective or a curriculum.
Quadrotors are the other end of the spectrum: fast, underactuated in translation, but with clean, well-modelled dynamics and no contact at all. That combination made them the setting for the most striking single result in the field — a learned policy beating human champions at drone racing on a physical track. The interesting detail is that its residual dynamics model was fitted from real flight data, which is Chapter 15's system identification doing the decisive work.
18.8 Chapter bridge
Locomotion's recipe is complete: mid-level actions on a PD loop, a dense multi-term reward whose weights are unit conversions, a terrain curriculum that manufactures a learnable gradient, randomization for transfer, and teacher–student distillation to reach a deployable observation set.
What Ferris does not have is anywhere to go. He tracks a velocity command; someone else decides what the command should be.
Chapter 19 supplies that. Navigation is the perception-heavy competency — partial observability in its natural habitat, where the state is a map the robot has never seen. Rusty graduates from Chapter 4's gridworld to continuous lidar-based navigation, and we confront the architectural question the survey finds genuinely unsettled: how much of the stack should be learned at all?
- 01Foundation●●●Dimensional audit
For each reward term in §18.3, verify the units and determine what the weight’s units must be for the sum to be dimensionally consistent. Then explain why a paper reporting weights without units is not fully reproducible.
- 02Foundation●●●Gait phases
Write phase offsets for trot, pace, bound and gallop. For each, state the number of feet in contact over a cycle and relate it to static stability. Which gaits require dynamic balance throughout?
- 03Foundation●●●Curriculum as scheduling
Formalize a terrain curriculum as a sequence of distributions p_k(ξ) with a promotion rule. Then state a condition under which the curriculum could stall — the robot neither promoting nor demoting — and propose a fix.
- 04Foundation●●●Why privileged terrain helps
Argue why a teacher with exact terrain heights learns faster than a student with only proprioception. Frame it as the difference between a nearly-fully-observed MDP and a POMDP, using Chapter 4’s belief formalism.
- 05Conceptual●●●Break the gait four ways
In the reward mixer, produce four distinct failures: standing still, creeping, prancing, and falling. Record the weight settings for each and name the term responsible.
- 06Conceptual●●●Find the trotting region
Identify the region of weight space that yields a plausible trot. Is it a broad basin or a narrow ridge? Relate your answer to how much tuning effort locomotion papers actually report.
- 07Practical●●●Ferris walks
Build Ferris in rapier3d with PD joints and train PPO on flat ground with velocity tracking only. Then add terms one at a time and record the gait change from each. Report which single term most improved the result.
- 08Practical●●●Curriculum ablation
Train two policies on stairs: one with the terrain curriculum, one starting directly on the hardest terrain. Report the sample count each needs to reach a 50% traversal rate — the second may never get there, which is itself the finding.
References
Baseline references
- Tang, C. et al. (2024). Deep Reinforcement Learning for Robotics: A Survey of Real-World Successes. Annual Review of Control, Robotics, and Autonomous Systems link§4.1 in full — quadruped, biped and quadrotor locomotion, with the trend analysis behind §18.1.
- Kober, J., Bagnell, J. A. & Peters, J. (2013). Reinforcement Learning in Robotics: A Survey. International Journal of Robotics Research 32(11)The pre-deep-learning locomotion lineage, including Kohl & Stone’s policy-gradient gait optimization.
Further reading & modern sources
- Hwangbo, J. et al. (2019). Learning agile and dynamic motor skills for legged robots. Science Robotics 4(26)Where the modern pipeline begins, including the learned actuator model.
- Lee, J., Hwangbo, J., Wellhausen, L., Koltun, V. & Hutter, M. (2020). Learning quadrupedal locomotion over challenging terrain. Science Robotics 5(47)The teacher–student pipeline assembled in §18.6.
- Miki, T., Lee, J., Hwangbo, J., Wellhausen, L., Koltun, V. & Hutter, M. (2022). Learning robust perceptive locomotion for quadrupedal robots in the wild. Science Robotics 7(62)Adding exteroception while keeping proprioceptive fallback — L4 in the wild.
- Rudin, N., Hoeller, D., Reist, P. & Hutter, M. (2022). Learning to Walk in Minutes Using Massively Parallel Deep Reinforcement Learning. CoRL 2021The parallel-simulation regime and the per-environment terrain curriculum of §18.5.
- Kumar, A., Fu, Z., Pathak, D. & Malik, J. (2021). RMA: Rapid Motor Adaptation for Legged Robots. RSS 2021Explicit estimation of dynamics parameters from proprioceptive history.
- Kaufmann, E., Bauersfeld, L., Loquercio, A., Müller, M., Koltun, V. & Scaramuzza, D. (2023). Champion-level drone racing using deep reinforcement learning. Nature 620 linkThe flight result of §18.7, with residual dynamics identified from real flight data.
- Peng, X. B., Abbeel, P., Levine, S. & van de Panne, M. (2018). DeepMimic: Example-Guided Deep Reinforcement Learning of Physics-Based Character Skills. ACM Transactions on Graphics 37(4)Reference-motion imitation — the technique bipedal work leans on most heavily.
