Robot Control
MPC and WBC: planning forces, then moving joints
A legged robot has to answer two questions at very different speeds. Model predictive control (MPC) looks a moment ahead: what forces should my feet push with? Whole-body control (WBC) answers right now: what torque should each joint produce?
Why two layers? Predicting ahead with a full robot model is too slow, and reacting with no prediction misses what's coming. So MPC predicts ahead with a simple model, and WBC reacts with the full one.
1
Model predictive control (MPC)
Plan the next moment, carry out only the first step, then plan again.
The idea
Think of driving at night. You plan for as far as your headlights reach, you steer a little, and then you plan again from where you now are. MPC works the same way, and that's called a receding horizon:
- Measure the robot's current state.
- Predict how it would move over the next fraction of a second, for candidate foot forces.
- Optimise to find the forces that best follow the goal, while staying within the limits.
- Apply only the first step of the plan, then throw the rest away and repeat.
Because the plan is redone many times a second, a push or a slip is simply a new starting state. No separate recovery plan is needed.
Step 1: A simple model of the body
A robot's legs are often light compared with its body, so MPC can treat the whole robot as a single rigid body pushed by forces at the feet:
Here p is the body's position, ω is how fast it's turning, fᵢ is the force at foot i, and rᵢ is the arm from the centre of mass to that foot. It has far fewer states than the full robot, which makes it fast to solve.
Step 2: Make it linear
The rotation part above isn't linear, because of the cross product and how orientation is written. The MIT Cheetah 3 controller makes it linear by assuming that roll and pitch stay small, and by planning around a reference path with known foot positions. The future then becomes:
Step 3: The optimisation problem
Each term has a plain meaning:
Qsays how much each tracking error matters, such as height against sideways drift.Rdiscourages using large forces when smaller ones would do.- The horizon
Nsets how far ahead it looks. Too short and it doesn't see what's coming. Too long and it gets slow, and the simple model gets less reliable. - The gait schedule is decided beforehand. It keeps the problem convex, since the optimiser doesn't have to choose when each foot lands.
This form is a quadratic program (QP), which is convex: it has one best answer, and fast solvers can find it reliably. Di Carlo and colleagues (2018) report horizons of up to 0.5 s, running at 20–30 Hz with solves under 1 ms, and speeds up to 3 m/s on the MIT Cheetah 3 across several gaits.
A worked example: friction
Take a 35 kg humanoid standing on a floor with friction μ = 0.6. Its weight is 35 × 9.81 ≈ 343 N, so the ground pushes up with about 343 N in total. Friction can then provide at most:
On ice, with μ = 0.05, this falls to about 17 N, or about 0.5 m/s². MPC can plan within that limit, instead of commanding a force that would make the foot slip. This is one of its biggest advantages: the limits are written into the problem itself.
Humanoids are harder than quadrupeds
| Quadruped MPC | Humanoid MPC | |
|---|---|---|
| Feet | Small points: force only | Flat feet: force and torque, kept within the foot's area |
| Leg mass | Often small enough to ignore | Legs and arms are heavy; they change balance as they swing |
| Common model | Single rigid body | Linear inverted pendulum for walking, or centroidal dynamics for more motion |
| Margin for error | Larger, with a low, wide stance | Smaller, with a high body over small feet |
Centroidal dynamics is the more general model, and includes the angular momentum L of all the moving parts, such as swinging arms. It's exact for the whole robot's momentum, but makes the problem non-convex:
Variations
Convex MPC
Simple model, linearised. Very fast and reliable, but less accurate far from its assumptions, for example with a large body tilt.
Nonlinear MPC
Keeps the true model, such as centroidal dynamics. More capable, but slower and may find a poor local answer.
Whole-body MPC
Plans over every joint, so it needs no separate WBC in principle. It's the most complete, and heavy to compute in real time.
2
Whole-body control (WBC)
Take many goals at once, and find the single set of joint torques that best satisfies them.
The problem it solves
At any instant, a robot has many goals: keep the body upright, hold the stance feet still, swing the other foot to its target, follow the arm motion, and apply the forces MPC planned. They share the same motors, and may conflict. WBC decides how to share them, while obeying physics.
Step 1: The full dynamics
Unlike MPC's simple model, WBC uses every link and joint:
M(q) | Mass matrix: how hard each joint is to accelerate in this pose |
h(q, q̇) | Gravity, plus forces caused by motion |
Sᵀ τ | Motor torques, which act only on the actuated joints, not on the floating body |
J_cᵀ f | Contact forces from the ground, mapped to all the joints |
Step 2: Write each goal as a task
A task is anything you want to control, such as the position of a foot. The Jacobian J relates joint motion to task motion, so a desired task acceleration becomes a condition on joint acceleration:
The second line is a spring and damper in task space: it pulls the task back when it strays from its target.
Step 3: The optimisation problem
WBC is commonly written as a QP that's solved at every control step:
The hard limits can never be broken. The tasks in the cost are what's traded off when everything can't be satisfied at once.
Deciding what matters most
| Priority | Task | Why here |
|---|---|---|
| Hard limit | Physics, contact, friction, motor limits | These can't be negotiated |
| Highest | Centre of mass and body orientation | If this fails, the robot falls |
| High | Swing foot position | A misplaced foot can trip the robot, or ruin the next step |
| Medium | Hand or arm goals | The actual job, but never at the cost of falling |
| Low | Natural posture | Uses whatever freedom remains, and keeps the pose sensible |
This order is a typical example, and designs vary. It can be enforced in two ways:
Weighted
All tasks go in one cost, with bigger weights on important ones. Simple and flexible, but a low-priority task can still disturb a high-priority one slightly.
Strict hierarchy
A lower task may only use motion that doesn't disturb the higher ones, using null-space projection. It gives a firm order, but is more complex, and can behave abruptly when a task reaches a limit.
A worked example: raising an arm while standing
A humanoid stands and raises a heavy arm forward. The arm's weight moves the centre of mass forward too.
- Arm task: asks the shoulder to accelerate the arm upward.
- Centre of mass task: notices the forward shift, and asks the hips and ankles to lean back slightly.
- Contact condition: requires the feet to stay still, and keeps the pressure inside the foot area.
- Solver result: the arm rises and the body leans back at the same moment. No one programmed this lean; it follows from the tasks.
3
How MPC and WBC work together
MPC says what forces to apply. WBC says how the joints can produce them.
This division was shown clearly on the MIT Mini Cheetah by Kim and colleagues (2019). MPC plans ground forces over a longer horizon with a simple model, and WBC turns them into joint commands, with a focus on tracking those forces. They report six gaits, with speeds up to 3.7 m/s.
One moment in a trot
- Gait scheduler: front-left and rear-right feet are down, and the others are swinging.
- MPC: the robot is commanded forward and is tilted slightly, so it plans forces for the two stance feet over the next fraction of a second.
- Foot placement: a simple rule picks where the swinging feet should land, depending on the speed.
- WBC: takes the planned forces, the body goal and the swing-foot goals, and solves for joint torques using the full model. It may run several times before the next MPC plan arrives.
- Motors: apply the torques and joint commands.
- Sensors: report what really happened, and everything repeats from the new state.
Side by side
| MPC | WBC | |
|---|---|---|
| Question it answers | What forces do I need over the next moment? | What torque should each joint produce now? |
| Looks ahead | Yes: a fraction of a second or more | No: only the current instant |
| Model | Simple: rigid body, pendulum or centroidal | Full: all links and joints |
| Decides | Contact forces, and sometimes footsteps | Joint accelerations, forces and torques |
| Typical rate | Tens of hertz | Hundreds of hertz or more |
| Good at | Anticipating, such as slowing before a stop | Coordinating many joints and goals at once |
| Weakness | Its simple model ignores joint limits and leg swing | It can't foresee a problem that's coming |
4
Compared with reinforcement learning
Optimise while running, or learn beforehand and just run a network.
| MPC + WBC | RL policy | |
|---|---|---|
| When the hard work happens | On the robot, many times a second | In simulation, before deployment |
| Needs | An accurate model, plus expert tuning of weights and gains | A good simulator, plus reward design, and lots of GPU time |
| Limits | Written explicitly; force and friction limits can be set and inspected | Learned; usually followed, but not guaranteed |
| Failures | Easier to trace to a model, cost or constraint | Harder to explain |
| Rough ground and surprises | Harder without good contact and terrain information | Often very robust, when trained with randomisation |
| Copying human motion | Possible, but needs contact timing and care | Today's most common choice |
| Compute on the robot | Solvers run constantly | Running the network is usually cheap |
5
From math to AI
How the same problem moved from equations solved on the robot to a network trained in simulation.
The problem stays the same
A walking robot spends much of its time with legs in the air, so it's often briefly unstable. It can only move its body by pushing against the earth with its feet, and it must keep deciding how hard, in which direction and when to push, even on uneven ground or after a kick. What changed is who works out the answer, and when.
MPC: the strategist
Like a driver looking through the windscreen, it looks a fraction of a second to about a second ahead. It treats the body as a single flying brick and plans the pushing forces.
WBC: the muscle coordinator
It takes the planned forces and considers the whole robot: every joint, motor limit and leg. It works out the motor torques, while keeping the feet from slipping.
RL: muscle memory
One neural network replaces both layers on the robot. It reads the robot's sensors and directly outputs motor commands, with the hard work already done in training.
What moved where
| Classical: MPC + WBC | End-to-end RL | |
|---|---|---|
| Who writes the behaviour | Engineers: models, costs and constraints | Engineers write rewards; training finds the behaviour |
| Where the physics lives | In the equations solved on the robot | In the simulator used for training |
| On the robot | Optimisers running constantly | One network, typically about 50 times a second |
| Output | Forces, then joint torques | Usually joint target angles, followed by low-level motor controllers |
| Why it won attention | Explicit limits; explainable | Handles full-body motion that's hard to write equations for, such as fast running and recovering from kicks |
Open resources you can start from
You don't have to start from nothing, but always check what each one really contains:
| Resource | What it is | Check first |
|---|---|---|
| Unitree RL Gym | RL training code, with pretrained .pt walking policies for the G1, H1 and H1-2 humanoids | Has Go2 training settings, but no Go2 pretrained policy in the copy we checked |
| Unitree Go2 velocity policy | A community .onnx policy for the Go2 on flat ground | Flat ground only; community model, BSD-3 |
| Kyu3224 quadruped policies | Flat and rough-terrain policies in .pt and .onnx, for the KAIST Hound-1 and Hound-2 robots | Other robots need retraining; outputs torque; no licence listed |
| HIW-500 | A dataset, not a policy: hundreds of hours of a G1 being teleoperated in real homes | CC BY 4.0; suited to imitation learning |
Running a trained policy in MuJoCo
A policy works only if it receives exactly the inputs it was trained on. This loop shows the parts that matter, with example values from the Go2 policy above:
What must match training
| Must match | If it doesn't |
|---|---|
| Inputs: which values, their order, their scale, and any history | Wrong size stops with an error. Right size in the wrong order runs, and the robot falls |
| Joint order | Commands go to the wrong joints |
| Default pose and action scale | The network's output means the wrong angle |
| Motor gains and limits, and model physics | The robot walks too slowly, shakes or falls |
| Update rate | The policy sees motion at a speed it never practised |
These settings are usually in the configuration files saved with the policy, and some exported ONNX files also store them as metadata.
Training a policy for a new scenario
A pretrained policy is a quick start, but a new robot or a new behaviour, such as climbing specific obstacles, usually means training your own. Training runs in a GPU-accelerated simulator, with thousands of robots at once. Isaac Lab is widely used and replaced the older Isaac Gym; mjlab offers a MuJoCo-based route.
- The environment. Put about 4,000 virtual robots in the simulator, and randomise the terrain, friction, mass and pushes, so the policy doesn't rely on one exact world.
- The reward. Write rules that score behaviour: points for moving at the requested speed and keeping the body level, penalties for falling and wasting energy.
- The optimisation loop. Movements start out close to random, with exploration noise added. PPO (Proximal Policy Optimization) favours what earned more reward, and gradually updates the network over millions to billions of simulated steps, until stable walking emerges.
- Test before trusting it. Run it in a second simulator, then carefully on the real robot.
What hardware do you need?
A strong GPU helps, because it runs the physics and the learning together, but a top-end card isn't a hard requirement. A modest GPU can also run thousands of robots, at the cost of time.
As one example, a laptop RTX 4060 with 8 GB ran 4,096 robots in mjlab at about 51,000 steps per second, using under 2 GB of GPU memory. That's practical for one clip or a simple task, if you can leave it running for hours.
Rough guide
- Mid-range or laptop GPU: learning, smoke tests, simple tasks
- High-end desktop GPU: faster runs and more experiments
- Rented cloud GPU: large motion datasets and many runs, from providers such as RunPod or Lambda. Compare prices first
6
Tools and papers
Where to read further and try it yourself.
Papers
- Dynamic Locomotion in the MIT Cheetah 3 Through Convex Model-Predictive Control, Di Carlo et al., IROS 2018
- Highly Dynamic Quadruped Locomotion via Whole-Body Impulse Control and Model Predictive Control, Kim et al., 2019
Open software
- Cheetah-Software: MIT's MPC + WBC code
- Quadruped-PyMPC: quadruped MPC in Python
- MuJoCo MPC: predictive control in MuJoCo
- Pinocchio: fast robot dynamics
- TSID: a task-space WBC library
- Crocoddyl: optimal control for robots