Model Predictive Controller (MPC)
March 23, 2026 · View on GitHub
Overview & Motivation
Model Predictive Control (MPC) is a receding-horizon optimal control strategy that computes control inputs by solving a finite-horizon optimization problem at each time step. Unlike LQR, which applies a fixed gain computed offline, MPC re-solves the optimization online, enabling it to handle constraints on control inputs directly.
At each sample instant, MPC predicts the future system trajectory over a prediction horizon , optimizes a sequence of control moves over a control horizon , applies only the first control move, and repeats at the next step. This receding-horizon approach provides feedback and robustness to disturbances.
Key advantages over LQR:
- Explicit handling of input constraints (actuator limits)
- Preview and anticipation of future reference changes
- Tunable trade-off between horizon length and computational cost
When to use MPC:
- Systems with actuator saturation or operational limits
- Multi-input multi-output (MIMO) systems requiring coordinated control
- Applications where the computational budget allows online optimization (typically )
Mathematical Theory
Prerequisites
- Discrete-time linear state-space model:
- Quadratic cost weighting matrices (state), (control)
- Optional terminal cost matrix (typically from DARE)
Core Definitions
Cost function over prediction horizon with control horizon :
For , the control input is held at or zero (our implementation sets it to zero beyond ).
Prediction Matrices
The future state trajectory can be expressed as:
where and .
State propagation matrix ():
Control-to-state matrix ():
QP Formulation
Substituting predictions into the cost yields a quadratic program in :
where:
is block-diagonal with on the first blocks and on the last block. is block-diagonal with repeated times.
Unconstrained Solution
Setting :
Solved via Gaussian elimination () rather than explicit matrix inversion.
Box Constraints
For control input constraints , a simple projected approach clamps each element of the unconstrained solution. This is a first-order approximation; for tight constraints or state constraints, a full QP solver would be required.
Complexity Analysis
| Phase | Time | Space | Notes |
|---|---|---|---|
| Offline | Prediction matrices, Hessian, gradient precomputed | ||
| Online | Gaussian elimination to solve | ||
| Per step | Matrix-vector product + constraint clamping |
For typical embedded use (): the online solve is a $10 \times 10$ linear system, well within real-time budgets.
Step-by-Step Walkthrough
System: Double integrator with s
Step 1 — Build :
Step 2 — Build :
Step 3 — Compute and :
produces a $3 \times 3$ positive definite matrix.
produces a $3 \times 2$ matrix.
Step 4 — Online solve for :
Solve via Gaussian elimination.
Apply first element to the plant.
Pitfalls & Edge Cases
- Horizon too short: If is too small, the controller is myopic and may produce oscillatory or unstable behavior. Use DARE terminal cost to mitigate.
- Ill-conditioned Hessian: Very large ratios create poorly conditioned . Keep and within 3–4 orders of magnitude of each other.
- Constraint infeasibility: Box constraints that are too tight for the required control effort will clamp every step, degrading performance. Monitor constraint activity.
- Fixed-point overflow: For Q15/Q31 types, the Hessian elements grow with horizon length. Keep small and scale weights carefully.
- Stack usage: All matrices are stack-allocated. A system with creates a $20 \times 20$ Hessian (1600 bytes for float). Monitor stack budget.
- Terminal cost omission: Without terminal cost , the controller ignores cost-to-go beyond the horizon, leading to suboptimal or unstable behavior for short horizons.
Variants & Generalizations
| Variant | Key Difference | Use Case |
|---|---|---|
| Nonlinear MPC (NMPC) | Nonlinear prediction model, requires iterative optimization | Nonlinear plants, high-accuracy |
| Explicit MPC | Precomputes control law as piecewise affine function | Very fast online evaluation |
| Move-Blocking MPC | Constrains control moves to change only at specific steps | Reduces QP size |
| Adaptive MPC | Updates plant model online | Time-varying or uncertain systems |
| Distributed MPC | Decomposes problem across subsystems | Large-scale multi-agent systems |
| Robust MPC | Accounts for bounded disturbances in constraints | Safety-critical applications |
Applications
- Autonomous vehicles: Path tracking with steering and acceleration limits
- Process control: Chemical reactor temperature/pressure regulation with valve constraints
- Robotics: Joint torque-constrained trajectory tracking
- Power electronics: Voltage/current regulation in converters with switching constraints
- HVAC systems: Energy-efficient building climate control with comfort bounds
- Quadrotor control: Attitude and position control with thrust limits
Connections to Other Algorithms
graph LR
DARE["Discrete Algebraic<br/>Riccati Equation"] -->|terminal cost P| MPC["Model Predictive<br/>Controller"]
GE["Gaussian<br/>Elimination"] -->|solves H·U = -F·x| MPC
LQR["LQR Controller"] -.->|special case<br/>N→∞, no constraints| MPC
MPC -->|first control move| Plant["Plant Model"]
Plant -->|state measurement| MPC
- LQR is the infinite-horizon, unconstrained special case of MPC. As with DARE terminal cost, the MPC gain converges to the LQR gain.
- DARE computes the terminal cost matrix , ensuring the finite-horizon problem approximates the infinite-horizon solution.
- Gaussian Elimination solves the dense linear system at each step. For constrained problems, iterative QP solvers could replace this.
- Kalman Filter provides state estimates when full state measurement is unavailable (MPC + KF = output-feedback MPC).
References & Further Reading
- Maciejowski, J.M., Predictive Control with Constraints, Prentice Hall, 2002.
- Rawlings, J.B. and Mayne, D.Q., Model Predictive Control: Theory and Design, Nob Hill Publishing, 2009.
- Camacho, E.F. and Bordons, C., Model Predictive Control, 2nd ed., Springer, 2007.
- Borrelli, F., Bemporad, A., and Morari, M., Predictive Control for Linear and Hybrid Systems, Cambridge University Press, 2017.
- Wang, L., Model Predictive Control System Design and Implementation Using MATLAB, Springer, 2009.