Model predictive control (MPC) is a control method that uses a dynamic model of the system to predict its behavior over a short future horizon, solves an optimization problem to find the best sequence of control inputs, applies only the first input, and then repeats the process at the next time step. In robotics control systems, it is the method of choice when a robot must respect hard constraints such as joint limits, torque limits or obstacle boundaries while tracking a goal.
The repeated re-planning is called the receding horizon principle. It turns an open-loop optimization into a feedback controller, because every new measurement of the state starts a fresh prediction. This lets MPC correct for disturbances and model errors while still looking ahead.
How model predictive control works
At every control cycle, MPC performs the same sequence of steps. It measures or estimates the current state, simulates the model forward over N steps for a candidate input sequence, scores the predicted trajectory with a cost function, and searches for the input sequence that minimizes the cost while satisfying all constraints.
- Estimate the state from sensors, often through a Kalman filter or another observer.
- Formulate the optimization with the model, the cost function and constraints over the prediction horizon.
- Solve the problem within the available time budget, usually warm-started from the previous solution.
- Apply the first control input to the actuators and discard the rest of the sequence.
- Shift the horizon by one step and repeat at the next sampling instant.
The cost function typically penalizes tracking error against a reference and control effort, weighted by matrices often called Q and R. A terminal cost or terminal constraint at the end of the horizon helps guarantee stability, since the controller otherwise sees nothing beyond the horizon.
Design parameters and typical values
Tuning MPC means choosing a handful of parameters whose effects interact. The horizon length and the sampling time together set how far ahead the robot looks, and both are limited by the solver’s ability to finish on time.
| Parameter | Typical robotic range | Effect of increasing it | Main cost |
|---|---|---|---|
| Sampling time | About 1 to 100 ms | More time to solve | Slower reaction to disturbances |
| Prediction horizon | About 10 to 100 steps | Better anticipation of constraints | Larger problem, longer solve time |
| Control horizon | Equal to or shorter than prediction | More freedom in the input sequence | More decision variables |
| State weights (Q) | Problem specific | Tighter tracking | More aggressive inputs |
| Input weights (R) | Problem specific | Smoother, gentler inputs | Slower tracking |
Fast inner loops such as quadrotor attitude or legged balance may run MPC at hundreds of hertz to about 1 kHz, while path-following for a car-like robot often runs at 10 to 50 Hz with a horizon covering a few seconds of motion.
Linear and nonlinear variants
The form of the model determines the form of the optimization and therefore the computational cost. Linear MPC with a quadratic cost and linear constraints yields a quadratic program, which modern solvers handle in microseconds to milliseconds. Nonlinear MPC uses the full nonlinear dynamics and is solved with methods such as sequential quadratic programming or real-time iteration schemes.
| Variant | Model | Typical solver approach | Typical robotic use |
|---|---|---|---|
| Linear MPC | Linear or linearized dynamics | Quadratic programming | Balance control, simplified legged models |
| Nonlinear MPC | Full nonlinear dynamics | SQP or real-time iteration | Drones, vehicles, manipulators |
| Explicit MPC | Small linear system | Precomputed lookup of solutions | Embedded controllers with few states |
| Robust or tube MPC | Model with bounded uncertainty | Tightened constraints | Safety-critical motion |
| Sampling-based MPC | Any simulatable model | Random rollouts such as MPPI | Off-road driving, contact-rich tasks |
Comparison with PID and other feedback control
A PID controller reacts to the current error and its history, with no explicit model or foresight. MPC, by contrast, plans with the model and handles constraints directly, which matters when actuators saturate or obstacles limit motion. The price is far greater computation and dependence on model quality.
| Aspect | PID | LQR | MPC |
|---|---|---|---|
| Needs a model | No | Yes, linear | Yes, linear or nonlinear |
| Handles constraints | Only through clamping | No | Yes, explicitly |
| Anticipates future references | No | No | Yes, within the horizon |
| Computation per step | Trivial | One matrix product | An optimization problem |
| Typical role | Joint and motor loops | Linear stabilization | Trajectory and whole-body control |
In practice these controllers are layered: MPC computes reference trajectories or torques at a moderate rate, and fast PID loops in the motor drivers track them. In a ROS 2 system, the MPC typically runs as a dedicated real-time node or inside a controller plugin.
Practical pitfalls
Most MPC failures in real robots come from timing, modeling and feasibility rather than from the theory itself.
- Missed deadlines: a solver that occasionally exceeds the sampling time destabilizes the loop, so a fallback input and an iteration limit are essential.
- Infeasible problems: hard constraints that cannot all be met make the solver fail; soft constraints with slack variables keep it running.
- Model mismatch: unmodeled friction, delays or payload changes cause steady-state offset unless a disturbance estimate is included.
- Poor scaling: states with very different units make the optimization numerically ill-conditioned.
- Too short a horizon: the robot reacts to an obstacle only when it is too late to brake.
Put simply
Model predictive control works like a careful driver. At each moment, the driver imagines the next few seconds of the road, chooses the best way to steer and brake, but only performs the first small action. A moment later, the driver looks again and plans afresh with the new view.
The key idea is planning ahead while constantly correcting. Because the plan respects the limits of the vehicle and the road, the robot avoids requests it physically cannot perform.
In practice
A quadruped robot walking over uneven ground uses convex MPC on a simplified single rigid body model. Every 20 to 30 ms, it predicts body motion over about half a second and computes the ground reaction forces for each foot in contact, subject to friction cone limits so that no foot slips.
A lower-level controller converts those forces into joint torques at about 1 kHz. When someone pushes the robot sideways, the next MPC cycle sees the new body velocity and redistributes forces among the feet. The robot recovers its balance within a few steps instead of falling, because the controller anticipates the effect of each force over the horizon.