Control Systems

Model Predictive Control (MPC)

Optimize over a receding horizon — the controller that plans ahead and re-plans every step

Model predictive control (MPC) is a feedback strategy that, at every sample, uses a mathematical model of the plant to predict its response over a finite prediction horizon of N future steps, then solves an online optimization that picks the control moves minimizing a cost on tracking error and control effort — subject to explicit constraints on actuators and outputs. Only the first move of the optimal sequence is applied; at the next sample the state is measured again and the whole problem is re-solved. That look-ahead-then-re-plan loop is the receding horizon principle. For a linear model with a quadratic cost the per-step problem is a convex quadratic program that solves in microseconds to milliseconds. MPC's defining advantage over PID is that it enforces hard constraints and multivariable coupling directly, which is why it runs refinery columns, automotive traction, drones, and robot balance.

  • Core ideaPredict, optimize, apply first move, re-plan
  • Solved each stepConvex QP (linear model + quadratic cost)
  • Prediction horizon N~10–30 samples (covers settling time)
  • Control horizon M~2–5 free moves
  • Key edge vs PIDExplicit hard constraints, multivariable
  • Where usedRefining, automotive, drones, robotics

Interactive visualization

Press play, or step through manually. The visualization is yours to drive — try it before reading on.

Open visualization fullscreen ↗

Watch the 60-second explainer

A condensed visual walkthrough — narrated, captioned, under a minute.

Why MPC matters

Classical control tunes a fixed law — a PID gain triple, a lead-lag network — and hopes the plant stays inside the region where that law behaves. The moment the interesting engineering shows up, that assumption breaks: a valve saturates at 100 % open, a motor current hits its thermal limit, a drone's tilt cannot exceed 30° before it stalls its own lift, a distillation column must not flood. Those are constraints, and a fixed feedback law has no principled way to respect them. It clamps, it winds up, it fights itself when several loops share one actuator.

MPC turns control into repeated forecasting. It carries an explicit model, looks a fixed number of steps into the future, and asks an optimizer the concrete question a good operator asks: given where I am now and everything I am not allowed to violate, what is the best sequence of moves? Because the answer is recomputed every sample from the newest measurement, MPC is still feedback — but feedback that plans. The economic payoff is real: refiners run units closer to their true limits because the controller knows exactly where those limits are, which is worth millions of dollars per year on a single large unit.

  • Constraints are first-class. Actuator limits, slew rates, and output bounds live inside the optimization, not in bolted-on logic.
  • Multivariable by construction. One controller coordinates many coupled inputs and outputs; no loop-pairing or decoupling network needed.
  • Look-ahead. Known future setpoint changes and measured disturbances are used before they hit, not just reacted to.
  • Economic operation. Running at the true constraint edge, not a conservative margin, is where the money is.
  • Systematic tuning. Weights on error and effort have clear physical meaning, unlike hand-tuned gain triples.

How MPC works, step by step

Every sample instant k, the controller runs the same four-stage cycle:

  1. Measure / estimate the state. Read the sensors, and use an observer or Kalman filter to reconstruct the full state vector x(k) and estimate current disturbances. This is the "where am I now" that anchors the forecast.
  2. Predict. Push the plant model forward N steps for a candidate input sequence, producing the predicted output trajectory. The model is the crystal ball; its fidelity sets the ceiling on performance.
  3. Optimize. Solve for the input sequence that minimizes the cost J while satisfying every constraint. For a linear model with quadratic cost this is a convex quadratic program with a unique global optimum.
  4. Apply the first move, then discard the rest. Send only u(k) — the first element of the optimal sequence — to the actuators. Wait one sample, take a fresh measurement, and return to stage 1. The horizon has receded by one step.

Throwing away everything but the first move looks wasteful, but it is exactly what makes MPC robust: the discarded plan was based on a prediction, and the next measurement is truth. Re-solving from the new state folds every disturbance and every model error back into the loop.

The cost function and the QP

The heart of MPC is the optimization solved at each step. In the standard linear-quadratic form the plant is the discrete state-space model

x(k+1) = A x(k) + B u(k),   y(k) = C x(k)

and the controller minimizes, over the input sequence, the finite-horizon cost:

J = Σi=1..N ‖ y(k+i) − r(k+i) ‖2Q + Σi=0..M−1 ‖ Δu(k+i) ‖2R

subject to umin ≤ u ≤ umax, Δumin ≤ Δu ≤ Δumax, and ymin ≤ y ≤ ymax. Every symbol:

SymbolMeaningUnits / notes
x(k)State vector at sample kdimension n (engineering units)
u(k)Control input (manipulated variable)dimension m (e.g. valve %, volts)
ΔuInput move, u(k) − u(k−1)per-sample change; slew rate × Ts
y(k)Controlled outputdimension p (measured variable)
r(k+i)Reference / setpoint trajectorycan be a known future profile
NPrediction horizonsamples; ~10–30, covers settling
MControl horizon (≤ N)free moves; ~2–5, rest held constant
Q ⪰ 0Output-error weightp×p; larger = tighter tracking
R ≻ 0Move-suppression weightm×m; larger = gentler, slower action
A, B, CPlant model matricesfrom first principles or system ID
TsSample timeseconds; loop period

Because J is quadratic and every constraint is linear, this is a convex quadratic program (QP) in the stacked move vector. Its solution is unique; active-set or interior-point solvers return it in microseconds for small problems and single-digit milliseconds for hundreds of variables. Two tuning ratios do most of the work: the Q/R balance trades tracking aggressiveness against control smoothness, and the horizon length trades foresight against compute. As a sanity check, if you delete all the constraints and let N→∞, the MPC law collapses exactly onto the infinite-horizon LQR — MPC is constrained LQR, re-solved online.

Worked example: a temperature loop with a rate limit

Take a heating process modelled as a first-order plant with a 30 s time constant, sampled at Ts = 1 s, and a heater whose power can move no faster than 5 % per second (Δu limit) and never exceed 100 %. Suppose an operator commands a 40 °C step in setpoint.

  • PID would slam the heater toward full power, hit the 100 % ceiling, and its integrator would wind up; the temperature overshoots while the integrator unwinds. Anti-windup helps but is reactive.
  • MPC predicts, at t = 0, that driving the heater hard now will overshoot in ~40 s. It plans a ramp that respects the 5 %/s slew and the 100 % ceiling, easing off before the target so the temperature arrives without overshoot. It never violated a limit because the limits were constraints in the QP, not afterthoughts.

Set N = 30 (one full time constant of foresight), M = 3 free moves, Q = 1 on the temperature error and R = 0.1 on the heater move. Increase R and the approach gets gentler and slower; increase Q and it gets crisper but pushes harder against the slew limit. Those two numbers, plus the horizon, are the whole tuning story — and each has a physical meaning, unlike a hand-tuned Kp, Ki, Kd triple.

MPC vs PID vs LQR — a spec comparison

PropertyPIDLQRMPC
Plant model neededNoYes (state-space)Yes (state-space or step response)
Look-ahead / predictionNoneInfinite (implicit)Finite horizon N, explicit
Hard constraintsNo (clamp + anti-windup)NoYes — built into the QP
Multivariable / coupledPoorly (loop pairing)NativelyNatively
Compute per stepA few multiply-addsOne matrix-vector productSolve a QP
Typical loop ratekHz–MHzkHzHz (process) to kHz (embedded)
Tuning knobsKp, Ki, KdQ, R weightsQ, R, N, M, constraints

Common misconceptions and failure modes

  • "Every step is optimal, so it must be stable." False. A finite-horizon optimum is not the infinite-horizon optimum; a short horizon or bad weights can be unstable. Stability is engineered in with a terminal cost (the LQR value function) plus a terminal set, or a long-enough horizon.
  • "MPC removes the need for a good model." The opposite — MPC's ceiling is set by model fidelity. Bad predictions steer bad moves. Integrating-disturbance models and an observer are what give it PID-like zero offset despite mismatch.
  • "Constraints are always satisfiable." A disturbance can drive the plant into a state where no feasible input exists. Naïve MPC then throws an infeasible QP and stalls. Real controllers use soft constraints (slack variables with a heavy penalty) so output limits can be relaxed gracefully while input limits stay hard.
  • "It's too slow for fast systems." Historically true, now obsolete. Explicit MPC precomputes the piecewise-affine solution offline for a lookup table, and modern embedded QP solvers run linear MPC at kilohertz rates on automotive and robotics ECUs.
  • "Longer horizon is always better." Beyond the settling time, extra horizon mostly adds compute and can amplify model error at the far end. Match N to the dominant time constant, not to a bigger number.

Variants worth knowing

  • Linear MPC / DMC / GPC. The workhorses. Dynamic Matrix Control (step-response models) and Generalized Predictive Control are the classic process-industry formulations.
  • Nonlinear MPC (NMPC). A nonlinear model turns the QP into a nonlinear program; real-time iteration and SQP schemes make it tractable for robots and vehicles.
  • Explicit MPC. Solve the parametric QP offline; the controller is a lookup of affine feedback laws — no online solver, ideal for tiny fast systems.
  • Robust / tube MPC. Plans a nominal trajectory plus a bounded "tube" so guarantees hold under disturbance and model mismatch.
  • Economic MPC. The cost is a direct economic objective (profit, energy) rather than tracking error — the plant is driven to the economically optimal operating point.

Frequently asked questions

What is model predictive control?

Model predictive control is a feedback strategy that at each sample uses a model of the plant to predict its behaviour over a finite horizon of N future steps, then solves an optimization that chooses a sequence of control moves minimizing a cost on tracking error and control effort while respecting constraints on inputs and states. Only the first move of that optimal sequence is applied. At the next sample the measurement is taken again and the entire problem is re-solved. This repeated look-ahead-and-re-plan cycle is the receding horizon principle.

How is MPC different from PID?

PID computes one output from three fixed terms acting on the present error, with no model and no look-ahead. MPC carries an explicit dynamic model, predicts many steps ahead, and solves a fresh optimization every sample. The decisive difference is constraints: PID cannot enforce limits on actuators or outputs except by ad-hoc clamping and anti-windup, whereas MPC bakes hard constraints such as valve limits, slew rates, and output bounds directly into the optimization. MPC also handles multivariable, coupled systems in one controller, where a bank of PID loops would fight each other.

What is the receding horizon?

The receding, or moving, horizon is the idea that MPC always plans over a window of fixed length N reaching into the future, but only ever commits to the first control move. When the clock advances one sample the window slides forward by one step, a fresh measurement enters, and the optimization is solved again from the new state. Because the plan is recomputed continuously with the latest data, disturbances and model error are corrected as they appear — the feedback comes from throwing away all but the first move and re-optimizing, not from a fixed gain.

What optimization does MPC solve?

For a linear plant model and a quadratic cost with linear inequality constraints, the per-sample problem is a convex quadratic program (QP): minimize the sum of weighted squared tracking errors and control moves, subject to the prediction equations and to lower and upper bounds. A QP with tens to hundreds of variables solves in microseconds to milliseconds with active-set or interior-point solvers, which is why linear MPC now runs at kilohertz rates on embedded hardware. If the model is nonlinear the problem becomes a nonlinear program (nonlinear MPC), which is far heavier and may need real-time iteration schemes.

How do you choose the prediction and control horizons?

The prediction horizon N should cover the dominant settling time of the plant, typically 10 to 30 samples, so the optimizer sees the full effect of today's moves. The control horizon M, the number of free moves, is usually much shorter (often 2 to 5); moves beyond M are held constant, which shrinks the QP without much loss of performance. A longer prediction horizon and a terminal cost or terminal constraint improve nominal closed-loop stability, at the price of a larger optimization each step.

Is MPC guaranteed to be stable?

Not automatically. A finite-horizon optimum is not the same as an infinite-horizon optimal (which would be the unconstrained LQR), so a short horizon or poor weights can be unstable even though every step is optimal. Stability is engineered in by adding a terminal cost equal to the LQR value function plus a terminal set constraint, or by choosing a horizon long enough that the terminal region is reached. Robust and tube MPC formulations then guarantee performance under bounded disturbance and model mismatch.

Where is MPC actually used?

MPC is the dominant advanced-control layer in oil refining and petrochemicals, where thousands of large multivariable controllers hold distillation columns and crackers near economic limits. It runs cement kilns, paper machines, and building HVAC. Faster embedded versions now sit in automotive powertrain and traction control, active suspension, adaptive cruise control, drone and quadrotor flight, legged-robot balance, and grid battery dispatch. SpaceX's Falcon and Starship landing guidance uses convex-optimization MPC-style trajectory solvers.