Model Predictive Control (MPC)
Adaptive Cruise Control Simulation
Prediction Horizon (Gap)
Predicted distance vs Target gap over the next 10 steps. Click to learn more.
Control Horizon
Planned optimal acceleration command (m/s²). Click to learn more.
The Ultimate Guide to Model Predictive Control (MPC)
Discover how modern autonomous systems, robotics, and industrial processes use advanced mathematical optimization to predict the future and act perfectly in the present.
1. What is Model Predictive Control (MPC)?
Model Predictive Control (MPC) is an advanced method of process control that relies on a mathematical model of a system to predict its future behavior and optimize control inputs accordingly. Unlike traditional reactive controllers, MPC “looks ahead” by simulating future states and determining the sequence of actions that yields the best outcome while strictly adhering to physical and operational constraints.
At its core, MPC operates on a receding horizon strategy. It calculates an optimal control sequence for a set time into the future, implements only the very first step of that sequence, and then repeats the entire calculation a fraction of a second later using updated sensor data. This makes it incredibly robust to disturbances and dynamic changes.
2. Applications: Where and When is MPC Used?
Primary Applications of MPC
- Automotive & Autonomous Driving: Adaptive Cruise Control (ACC), lane keeping, and collision avoidance trajectories.
- Aerospace: Drone trajectory tracking, rocket landing (e.g., SpaceX reusable boosters).
- Chemical & Process Industries: Oil refineries and chemical plants managing multiple variables simultaneously.
- Robotics: Dynamic walking for humanoid robots and precision robotic arms.
- Energy Management: Smart grids and HVAC systems optimizing for cost and energy efficiency.
When Do You *Need* MPC?
You should transition from basic controllers to MPC when your system features:
- MIMO Complexity: Multiple Inputs and Multiple Outputs that are highly coupled (changing one input affects multiple outputs).
- Hard Constraints: Systems that have strict physical limits (e.g., a valve cannot open more than 100%, or a car cannot exceed maximum braking capability).
- Future Pre-knowledge: Scenarios where you know the future reference path (like a curving road ahead) and want the system to prepare in advance rather than react blindly.
3. MPC vs. PID Control: Understanding the Difference
The Proportional-Integral-Derivative (PID) controller is the most common algorithm in the world, but it fundamentally differs from MPC in calculation and philosophy.
PID Controller (Reactive)
PID looks at the Past and Present. It calculates control action based on the current error, the accumulation of past error, and the current rate of change.
- Pros: Computationally simple, requires no mathematical model of the system.
- Cons: Does not handle constraints naturally; struggles with complex, multi-variable (MIMO) systems; cannot anticipate future curves.
MPC Controller (Proactive)
MPC looks into the Future. It solves a constrained optimization problem at every time step to minimize a defined cost function over a future horizon.
Subject to: $$ x_{k+1} = Ax_k + Bu_k $$
- Pros: Naturally handles constraints; excellent for MIMO; anticipates future changes.
- Cons: Requires an accurate mathematical model and significant computational processing power.
4. Kalman Filter vs. Model Predictive Control
A common point of confusion is the relationship between a Kalman Filter and an MPC. They are actually complementary technologies that look in opposite directions of time. The Kalman Filter handles the past to estimate the present state, while MPC takes that present state and calculates the future.
5. Horizons: Prediction vs. Control
The “Predictive” part of MPC is defined by two critical parameters: the Prediction Horizon ($N_p$) and the Control Horizon ($N_c$).
Prediction Horizon ($N_p$)
This is how far into the future (in time steps) the mathematical model simulates the state of the system. If $N_p = 10$, the controller is looking 10 steps ahead to evaluate the consequences of its actions.
Control Horizon ($N_c$)
This determines the number of active control moves the optimizer is allowed to change. Typically, $N_c < N_p$. After the control horizon ends, the control input is held constant for the remainder of the prediction horizon to save computational power.
6. Requirements to Implement MPC
Before you can write an MPC algorithm, you must have four fundamental components in place:
- A Mathematical Plant Model: A state-space representation or transfer function describing how the system’s physics work (e.g., how throttle affects speed).
- A Cost Function (Objective Function): A mathematical equation that defines “good” performance. It balances tracking the target versus conserving energy or comfort.
- Defined Constraints: The absolute limits of the system (e.g., maximum motor RPM, voltage limits, actuator physical bounds).
- An Optimization Solver: An algorithm (usually Quadratic Programming or non-linear solver) running on a microprocessor fast enough to solve the math before the next time step.
7. Implementation Steps: Adaptive Cruise Control Example
To truly understand how MPC works, let’s map out the mathematics of an Adaptive Cruise Control (ACC) system. Our autonomous car must follow a lead car at a safe distance while avoiding harsh braking to ensure passenger comfort.
Step 1: Define the Mathematical Model (State-Space)
The MPC needs to know how the car moves. We define a discrete-time kinematic model that predicts the car’s future position based on its current speed and the throttle/brake input applied.
$$ v_{k+1} = v_k + u_k \Delta t $$
- $p_{k+1}$ , $v_{k+1}$ : The predicted future position and future velocity of the car at the next time step.
- $p_k$ , $v_k$ : The current measured position (meters) and velocity (meters/second).
- $u_k$ : The control input we are solving for. In this case, it is the commanded acceleration or braking ($m/s^2$).
- $\Delta t$ : The sample time duration between calculations (e.g., 0.1 seconds).
Step 2: Formulate the Cost Function ($J$)
The cost function is the heart of the MPC. It mathematically represents what we care about. We want to minimize the error between our actual distance to the lead car and our target safe distance, while simultaneously minimizing large, jerky accelerations.
- $J$ : The total cost. The optimization algorithm’s job is to find the sequence of $u_i$ that makes this number as close to zero as possible.
- $N_p$ and $N_c$ : The Prediction Horizon and Control Horizon (number of steps into the future).
- $Gap_{actual, i}$ – $Gap_{target, i}$ : The error between where the car is predicted to be and where it should be to maintain a safe following distance. Squaring this $(x)^2$ severely punishes large errors.
- $W_{gap}$ : The tuning weight for safety. If this is very high, the car will aggressively stay exactly at the target distance, even if it requires hard braking.
- $u_i$ : The acceleration control input. Squaring it punishes extreme throttle or braking inputs.
- $W_{acc}$ : The tuning weight for passenger comfort. If this is high, the car will brake very smoothly, but might briefly drift slightly closer to the lead car.
Step 3: Establish the Hard Constraints
Unlike PID, MPC inherently understands real-world physics. A car cannot accelerate infinitely, and it cannot violate highway speed limits. We define these limits mathematically so the solver never considers an impossible solution.
$$ a_{min} \le u_{k+i} \le a_{max} \quad \text{(Actuator Constraints)} $$
- $0 \le v_{k+i}$ : The vehicle speed must be greater than or equal to zero (preventing the car from calculating a “reverse” trajectory on the highway to increase the gap).
- $V_{max}$ : The upper boundary for velocity, often mapped dynamically to the current road speed limit (e.g., 30 m/s or 67 mph).
- $a_{min}$ : The maximum braking capability of the vehicle (e.g., $-5.0 \text{ m/s}^2$).
- $a_{max}$ : The maximum acceleration capability of the engine (e.g., $+3.0 \text{ m/s}^2$).
Step 4: Solve and Apply (The Receding Horizon Loop)
At current time $t$, the onboard microprocessor runs a Quadratic Programming (QP) solver. It tests thousands of future acceleration profiles to find the one sequence $[u_0, u_1, u_2… u_{Nc}]$ that results in the lowest cost $J$ while respecting the constraints.
The brilliant trick of MPC: It throws almost all of that calculation away. The car applies only $u_0$ (the throttle command for the immediate present millisecond). By the time the next time step $t+1$ occurs, the sensors have fetched new radar data on the lead car, and the entire horizon is shifted forward and recalculated from scratch. This makes it impervious to unexpected disturbances.
8. Summary Conclusion
Model Predictive Control represents the bridge between classical control theory and modern artificial intelligence/optimization. While computationally expensive, its ability to foresee the future and respect physical boundaries makes it the premier choice for complex, high-stakes autonomous systems.
| Feature | PID Control | Model Predictive Control (MPC) |
|---|---|---|
| Core Philosophy | Reacts to past and present errors. | Predicts future behavior and optimizes proactive action. |
| System Model | Model-free (Black box tuning). | Requires an accurate mathematical representation (State-Space). |
| Constraints Handling | Poor (requires messy anti-windup patches). | Native and mathematically guaranteed. |
| Variable Handling | Single-Input Single-Output (SISO). | Multi-Input Multi-Output (MIMO) naturally integrated. |
| Hardware Requirements | Extremely low (runs on basic microcontrollers). | High (requires powerful microprocessors to solve matrix math in real-time). |