Model predictive control

On this page 7

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.

  1. Estimate the state from sensors, often through a Kalman filter or another observer.
  2. Formulate the optimization with the model, the cost function and constraints over the prediction horizon.
  3. Solve the problem within the available time budget, usually warm-started from the previous solution.
  4. Apply the first control input to the actuators and discard the rest of the sequence.
  5. 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.

ParameterTypical robotic rangeEffect of increasing itMain cost
Sampling timeAbout 1 to 100 msMore time to solveSlower reaction to disturbances
Prediction horizonAbout 10 to 100 stepsBetter anticipation of constraintsLarger problem, longer solve time
Control horizonEqual to or shorter than predictionMore freedom in the input sequenceMore decision variables
State weights (Q)Problem specificTighter trackingMore aggressive inputs
Input weights (R)Problem specificSmoother, gentler inputsSlower tracking
Main MPC design parameters

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.

VariantModelTypical solver approachTypical robotic use
Linear MPCLinear or linearized dynamicsQuadratic programmingBalance control, simplified legged models
Nonlinear MPCFull nonlinear dynamicsSQP or real-time iterationDrones, vehicles, manipulators
Explicit MPCSmall linear systemPrecomputed lookup of solutionsEmbedded controllers with few states
Robust or tube MPCModel with bounded uncertaintyTightened constraintsSafety-critical motion
Sampling-based MPCAny simulatable modelRandom rollouts such as MPPIOff-road driving, contact-rich tasks
Common MPC variants in robotics

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.

AspectPIDLQRMPC
Needs a modelNoYes, linearYes, linear or nonlinear
Handles constraintsOnly through clampingNoYes, explicitly
Anticipates future referencesNoNoYes, within the horizon
Computation per stepTrivialOne matrix productAn optimization problem
Typical roleJoint and motor loopsLinear stabilizationTrajectory and whole-body control
MPC compared with neighboring control approaches

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.