Search

Search papers and lessons

Learning agile and dynamic motor skills for legged robots

Jemin Hwangbo, Joonho Lee, Alexey Dosovitskiy et al. · 2019

Hwangbo et al. (2019) trained locomotion and fall-recovery policies for the ANYmal quadruped entirely in simulation, with a learned actuator model, and ran them on the real robot.

On this page

  • Colour = topic mix
  • Linear algebra
  • Calculus
  • Probability
  • Reinforcement learning
  • Discrete math
  • Classical mechanics
  • ReadReady to readNot yet

TL;DR

Hwangbo and colleagues trained control policies for ANYmal, a medium-dog-sized quadruped robot, entirely in simulation. Their key addition was an Actuator Network that models the robot's motors, including delays and internal feedback, learned from measurements on the real robot. The resulting policies ran faster than the robot's previous record, walked more efficiently than the best existing controller, and flipped the robot upright from nine random configurations.

Builds on: Reinforcement Learning, Trust Region Policy Optimization (TRPO), Actuator Network · Leads to: Domain Randomization, the companion idea of randomising the simulator so the policy does not depend on any one model

Why it mattered

Before this paper, the best existing ANYmal controllers were built by hand, module by module. Engineers split the problem into hand-tuned modules, and a new robot or a new manoeuvre could take months of work. The authors' central claim is that reinforcement learning can replace that process: the task is written as a reward and a set of start states, and the policy is found automatically.

The paper showed this on a real, large legged robot. Its speed record was broken by 25 percent, the new controller tracked velocity commands more accurately and with less torque and power than the best existing controller on the same hardware, and a fall-recovery behaviour was learned, which the authors say had not been achieved on a quadruped of comparable complexity before.

The method also changed the economics of control. Inference takes about 25 microseconds on one CPU thread, roughly 0.1 percent of the robot's onboard computing. Training runs on an ordinary desktop with one CPU and one GPU, and no run lasted more than eleven hours. Because the behaviours share one code base, the authors say that switching the network's parameters changes the behaviour, while the task description changes with the goal.

The problem

Learning on a real legged robot is hard for three reasons. Training needs a very large number of trials, and the controller can behave chaotically and fall during learning. Training in simulation avoids those costs, but simulators differ from reality, a difference the paper calls the reality gap. Improving the simulator analytically or by system identification is possible, and so is randomising its properties so the policy is robust to them.

For a legged robot the simulator's weakest part is the actuator. The rigid links can be modelled well from a CAD model, but the mapping from commanded position to actual torque includes delays from several hardware and software layers, the low-level controller's dynamics, and compliance and damping at the joints. The paper notes that ANYmal's 12 series elastic actuators are hard to model analytically. Their model of Gehring and colleagues contains nearly one hundred parameters, and the authors found it insufficiently accurate for training a high-performance controller.

Prior modular and trajectory-optimisation controllers faced their own limits. Modular controllers operate in small regions where each approximation holds, and their tuning is laborious. Trajectory optimisation can need the robot to solve a hard problem at run time, or to offload it to an external computer.

How it works

The method has four steps, shown in the paper's Figure 1: identify the robot's physical parameters, learn an actuator model, train a control policy in simulation, and deploy the policy on the robot.

flowchart LR
  A["1. Identify rigid-body model and parameter uncertainty"] --> B["2. Learn actuator net from real data"]
  B --> C["3. Train policy with TRPO in the hybrid simulator"]
  C --> D["4. Deploy policy on ANYmal, no hardware tuning"]
  1. Model the rigid body. The links are modelled from the CAD model, with about 20 percent uncertainty in inertia, so the authors train on 30 randomised versions of the robot. Check: 30 models with masses, centres of mass and joint positions sampled around their nominal values.
  2. Learn the actuators. Sine-wave foot motions are logged on the real robot at 400 Hz, and a small network maps position errors and velocities over a short history to torque. Check: the history used is the current sample and the samples at 0.01 and 0.02 seconds earlier.
  3. Train the policy. Inside the hybrid simulator, a multi-layer perceptron takes the history of robot states and outputs a joint position target. The target becomes a torque through a fixed impedance law, and TRPO improves the policy from the reward. Check: a training run of about a quarter of a billion state transitions takes roughly four hours.
  4. Deploy. The trained network runs on the robot at 25 microseconds per evaluation, with no further tuning on hardware. Check: this is about 0.1 percent of the robot's onboard compute, so the policy leaves most of the computer free.

Three training choices made the simulated policies work on hardware. The output is a position target rather than a torque, which makes the policy a stable standing controller at the start of training. The policy uses a bounded activation, because unbounded ones can produce huge actions in states the policy never visited. And a curriculum scales down every cost term except the objective at the start, so the policy first learns to move, and the costs for smooth, efficient motion are turned up towards full strength. The paper also adds noise to the velocity measurements, because on the real robot they come from numerically differentiating positions.

The math

The control problem is written as a discounted reinforcement-learning problem. At each time step the agent sees an observation oto_t, takes an action ata_t, and gets a reward rtr_t. The policy π(at∣Ot)\pi(a_t \mid \mathbf{O}_t) is a distribution over actions, conditioned on the recent history Ot=⟨ot,ot−1,…,ot−h⟩\mathbf{O}_t = \langle o_t, o_{t-1}, \ldots, o_{t-h} \rangle. The objective is

π∗=arg⁡max⁡π  Eτ(π)[∑t=0∞γtrt]\pi^* = \arg\max_{\pi} \; \mathbb{E}_{\tau(\pi)} \left[ \sum_{t=0}^{\infty} \gamma^t r_t \right]

where γ∈(0,1)\gamma \in (0, 1) is the discount factor and τ(π)\tau(\pi) is the distribution of trajectories under the policy and the dynamics. This is the Discounted Return that TRPO maximises.

Step 2 in symbols: the actuator model

The actuator network replaces the ideal torque with a learned function of the history of position error ee and velocity ϕ˙\dot\phi, as the Actuator Network lesson describes. Inside the simulator it is the map

τt=fθ(et,et−0.01,et−0.02,ϕ˙t,ϕ˙t−0.01,ϕ˙t−0.02)\tau_t = f_\theta\bigl(e_t, e_{t-0.01}, e_{t-0.02}, \dot\phi_t, \dot\phi_{t-0.01}, \dot\phi_{t-0.02}\bigr)

with fθf_\theta a small network trained by Mean Squared Error.

Step 3 in symbols: the action is an impedance command

The policy outputs a single position reference q∗q^* per joint. The torque is then

τ=kp(q∗−q)+kd(0−q˙)\tau = k_p (q^* - q) + k_d (0 - \dot q)

with kp=50k_p = 50 Nm/rad and kd=0.1k_d = 0.1 Nm/rad/s. This is the same structure as a PD Control law with a target velocity of zero. Check: if q∗−q=0.2q^* - q = 0.2 rad and q˙=1\dot q = 1 rad/s, then τ=50×0.2−0.1×1=9.9\tau = 50 \times 0.2 - 0.1 \times 1 = 9.9 Nm.

The gain choice has a stated reason: 3030 Nm of torque range divided by 0.60.6 rad of motion range is about 5050 Nm/rad, so the network's output has a similar scale for torque and position.

Step 3 in symbols: the discount and the half-life

The discount factor sets how far ahead the policy plans. Its half-life in seconds is

t1/2=ln⁡(1/2)ln⁡γ Δtt_{1/2} = \frac{\ln(1/2)}{\ln \gamma} \, \Delta t

With γ=0.9988\gamma = 0.9988 and a control step Δt=0.01\Delta t = 0.01 s, this gives t1/2=577×0.01≈5.77t_{1/2} = 577 \times 0.01 \approx 5.77 s, which is the value the paper reports.

Step 3 in symbols: the curriculum

The curriculum factor kck_c scales the cost terms that are not the objective. It advances by kc,j+1=(kc,j)kdk_{c,j+1} = (k_{c,j})^{k_d}, starting from k0=0.3k_0 = 0.3, with advance rate kd=0.997k_d = 0.997. After jj iterations, kc,j=k0kd jk_{c,j} = k_0^{k_d^{\,j}}, which rises towards 1.

Worked examples

Example
1. Tiny: one joint, one step
  1. Position target from the policy: q∗=q+0.2q^* = q + 0.2 rad, so the error is 0.20.2 rad. Check: the error is the target minus the current angle.
  2. Velocity: q˙=1\dot q = 1 rad/s. Check: the velocity term opposes motion, so it has a negative sign.
  3. Proportional part: 50×0.2=1050 \times 0.2 = 10 Nm.
  4. Derivative part: 0.1×1=0.10.1 \times 1 = 0.1 Nm, which is subtracted.
  5. Torque: 10−0.1=9.910 - 0.1 = 9.9 Nm. Interpretation: most of the command comes from the position error, and the velocity term only trims the response.
Example
2. Standard: the curriculum rising towards one
  1. Start: k0=0.3k_0 = 0.3. Check: the factor begins at 0.3, so most cost terms are switched down.
  2. After one iteration: kc,1=0.30.997≈0.301k_{c,1} = 0.3^{0.997} \approx 0.301. Check: the factor rises by a tiny amount.
  3. After 100 iterations: the exponent is 0.997100≈0.7410.997^{100} \approx 0.741, so kc,100=0.30.741≈0.41k_{c,100} = 0.3^{0.741} \approx 0.41.
  4. After 1,000 iterations: the exponent is 0.9971000≈0.04950.997^{1000} \approx 0.0495, so kc,1000=0.30.0495≈0.94k_{c,1000} = 0.3^{0.0495} \approx 0.94.
  5. Interpretation: the costs for smooth, efficient motion are switched on gradually, reaching about 0.94 of full strength after a thousand iterations. The paper chooses kdk_d so that the factor is about 0.9 by the end of training.
Example
3. Realistic: how fast was training?

The paper reports two training runs. The locomotion policies used nine days of simulated time, which took about four hours of computation. The recovery policy used 79 days of simulated time, which took about eleven hours.

  1. Locomotion: 9 days is 9×24=2169 \times 24 = 216 simulated hours. Check: 216 divided by the 4 hours of computation is 54.
  2. Interpretation: end-to-end training ran about 54 times faster than real time. The paper says the simulator alone runs roughly a thousand times faster than real time, and that about half of its runtime goes to evaluating the actuator nets. The gap between the two numbers is not broken down in the paper.
  3. Try it: compute the simulated hours per real hour for the recovery run, and say whether it is faster or slower than the locomotion run.

Answer: 79 days is 79×24=189679 \times 24 = 1896 simulated hours, and 1896 divided by 11 is about 172. The recovery training ran about 172 times faster than real time, so it was faster per real hour than the locomotion training, even though its episodes were different.

Common mistakes and tradeoffs

  • It is tempting to think the actuator network alone made the policies work. In fact the paper's ablations show that policies trained with an ideal actuator model and with a carefully tuned analytical model could not make a single step without falling. The learned actuator model is one ingredient, and the others (the impedance output, the curriculum, the bounded activation, and the randomisation) matter too.
  • It is tempting to think the speed record is the main result. In fact it is one of three demonstrations. The command-tracking comparison against the best existing controller is the more controlled test, and the fall recovery is the one that had no prior quadruped equivalent, according to the authors.
  • It is tempting to think a learned policy has no structure to check. In fact the authors choose concrete design features that can be checked: a position output with fixed gains, a bounded activation, and a discount whose half-life is stated in seconds.
  • It is tempting to think unbounded activations are a free improvement. In fact the paper reports that the nonlinearity strongly affects real-robot performance: ReLU can produce very large actions in states the training never reached.
ApproachEngineering effortRun-time computeStated limit
Hand-tuned modular controllerMonths per robot and per manoeuvreLowOperates in small regions where its approximations hold
Trajectory optimisationHeavy tuning and approximationsHigh, often on an external computerContact timing and points must be specified in advance
Learned controller with a learned actuator modelAbout two days of task design for a locomotion taskVery low on the robotNeeds a simulator and an actuator net, and a cost design per task

Results

The paper's measured results are summarised below.

ResultNumber in the paper
Random-command test: linear velocity error0.143 m/s
Random-command test: yaw rate error0.174 rad/s
Comparison profile, best existing controller: linear and yaw error0.231 m/s and 0.278 rad/s
Learned vs existing controller, torque8.23 Nm vs 11.7 Nm on average
Learned vs existing controller, mechanical power78.1 W vs 97.3 W on average
Top speed on the real robot (command 1.6 m/s)1.5 m/s, against a previous record of 1.2 m/s
Peak torque and joint speed reached40 Nm and 12 rad/s
Fall recoveryAll nine random configurations recovered, in under 3 seconds
Ideal or analytical actuator modelsNo successful step
Inference time on one CPU threadAbout 25 microseconds

Command following. The policy follows forward, lateral and turning commands without knowing their timing, with 30-second random tests and five minutes without failure. Its forward velocity reliably reaches 1.2 m/s when commanded slightly higher. The paper reports that the best existing controller's tracking error is about 95 percent higher for linear velocity and about 60 percent higher for yaw rate on the comparison profile. Two linear-velocity figures come from different command profiles, so that 95 percent is not a simple ratio of the two numbers in the table.

Efficiency. Over forward speeds from 0.25 to 1.0 m/s, the paper reports the learned controller uses 23 to 36 percent less torque than the existing gaits, and its velocity error is 1.5 to 2.5 times smaller than the dynamic lateral walk and 5 to 7 times smaller than the flying trot. The learned walk uses a straighter knee posture, 10 to 15 degrees, which the authors say the existing approach could not reach without a higher failure rate.

High speed. The learned high-speed gait is close to a flying trot with a longer and asymmetric flight phase. The authors suspect it is one of several near-optimal solutions. The high-speed result is one controlled test at a command of 1.6 m/s, where the robot reached 1.5 m/s.

Limits. The paper's own limitations are concrete. A single network trained in one session shows single-faceted behaviour and does not generalise across tasks, which the authors suggest hierarchical policies could address. The approach still needs a cost function and an initial-state distribution for each task, which took about two days of expert time for the locomotion tasks and about a week for recovery. The actuator model is per joint and assumes independence, which may fail for hydraulic systems. The short-term results do not establish long-term durability, although the robot was used for more than three months without changing the policies.

Reading guide

Check yourself

QuestionWhat are the three ingredients the paper combines to bridge the reality gap?Show answer
A learned actuator model that maps commands and history to torque, a simulator with randomised rigid-body properties and noise, and a reinforcement-learning policy trained inside that simulator with TRPO. The analytical rigid-body model is taken from the CAD data, and the learned part covers what analytical modelling cannot capture.
QuestionThe policy outputs a position target q∗q^* with kp=50k_p = 50 Nm/rad and kd=0.1k_d = 0.1 Nm/rad/s. For q∗−q=0.4q^* - q = 0.4 rad and q˙=2\dot q = 2 rad/s, what is the torque?Show answer
The proportional part is 50×0.4=2050 \times 0.4 = 20 Nm. The derivative part is 0.1×2=0.20.1 \times 2 = 0.2 Nm, subtracted. The torque is 19.819.8 Nm.
QuestionWhy does the paper use a position output and a bounded activation rather than torque and ReLU?Show answer
A position output starts as a standing controller, so training does not begin with a torque policy that falls over in most trajectories. A bounded activation keeps actions moderate in states the training never visited. The paper reports that unbounded activations such as ReLU degraded real-robot performance even when simulation looked similar.
QuestionA team wants to reuse this approach for a new legged robot whose hydraulic actuators share one accumulator. What should they expect and change?Show answer
Learning each actuator separately may not reach enough accuracy, because coupled dynamics mean one actuator's torque depends on the others. They should consider a single network that sees several actuators together, and check the actuator model's validation error before trusting any policy trained against it.

Sources

Read the full paper

Jemin Hwangbo, Joonho Lee, Alexey Dosovitskiy et al., 2019. arXiv:1901.08652