| name | model-predictive-control |
| description | Model Predictive Control (MPC) — prediction horizon, control horizon, cost function, QP optimization, constraints handling, linear vs. nonlinear MPC, economic MPC, state estimation, offset-free MPC, MIMO applications, process control (distillation, reactor), automotive (ACC, lane keeping), MATLAB MPC Toolbox. |
| metadata | {"priority":7,"promptSignals":{"phrases":["model predictive control","MPC","predictive control","receding horizon control","MPC optimization","MPC constraints"],"minScore":3}} |
Model Predictive Control (MPC) — Complete Skill
MPC Concept and Formulation
Receding Horizon Principle
MPC algorithm at each time step k:
- Obtain current system state x_k (measured or estimated)
- Solve optimization problem over prediction horizon N_p:
- Minimize cost function J(x, u) over future N_p steps
- Subject to: system dynamics, state constraints, input constraints
- Extract first control input u*(k) from optimal sequence
- Apply u*(k) to plant; advance time → k+1
- Repeat (receding horizon)
Key difference from LQR/PID:
MPC explicitly handles constraints (input saturation, state bounds)
MPC can optimize over multi-step predictions considering future disturbances
MPC is naturally MIMO (multiple input, multiple output)
Prediction Model
Linear time-invariant prediction model:
x_(k+1) = A × x_k + B_u × u_k + B_d × d_k [d = measured disturbance; d known a priori]
y_k = C × x_k + D_u × u_k
Prediction over N_p steps:
X = Γ × x_k + Φ × U + Ψ × D [compact matrix form; X = stacked state vector; U = stacked input; D = stacked disturbance]
Γ, Φ, Ψ = structured matrices from A, B_u, B_d repeated N_p times
Cost Function
Standard MPC cost:
J = Σ_{i=0}^{N_p-1} [||y_(k+i|k) - r_(k+i)||²_Q + ||Δu_(k+i)||²_R] + ||y_(k+N_p|k) - r_(k+N_p)||²_P
Terms:
Output tracking: ||y - r||²_Q = (y-r)ᵀ Q (y-r) [penalize output deviation from reference r; Q = weighting matrix]
Control rate: ||Δu||²_R = Δu^T R Δu [penalize change in input; Δu = u_k - u_(k-1); R = control weighting]
Terminal cost: ||y - r||²_P at final prediction step [ensures stability; P = solution to Lyapunov]
Horizons:
N_p: prediction horizon (steps ahead to predict; larger → better reference tracking + more computation)
N_c: control horizon (steps of free control; N_c ≤ N_p; u_(i) = u_(N_c) for i > N_c → reduce DOF)
Typical: N_p = 10–100; N_c = 2–10
Q and R selection:
Large Q: tight output tracking; aggressive control (similar to LQR Q concept)
Large R: slow control changes; penalize actuator wear
Q and R diagonal: independent weighting per output/input channel
Off-diagonal Q: cross-coupling between outputs
Constraint Handling
Types of Constraints
Input constraints (actuator limits):
u_min ≤ u_k ≤ u_max [hard bounds; never violated]
Δu_min ≤ Δu_k ≤ Δu_max [rate of change limits; prevent actuator abuse]
Output/state constraints (process limits):
y_min ≤ y_k ≤ y_max [process constraints; temperature limits, pressure limits, safety]
Can be soft (allowed violations with large penalty) or hard
Soft constraints: y ≤ y_max + ε; add ε²/ρ to cost [ε = slack variable; ρ = constraint penalty]
Example — distillation column:
u₁ = reflux ratio (0.5–5); u₂ = boilup ratio (0.5–4)
y₁ = top composition (purity ≥ 95%); y₂ = bottom composition (impurity ≤ 2%)
Temperature ramp: ΔT/Δt ≤ 10°C/min → input rate constraint on heating rate
Quadratic Program (QP) Formulation
MPC reduces to QP at each step:
min_{U} (1/2 × Uᵀ H U + f^T U) [H = Hessian; f = linear term; from substituting X = Γ x + Φ U]
subject to: A_ineq × U ≤ b_ineq [stacked inequality constraints for u, Δu, y bounds]
QP solvers:
OSQP (open source, fast): solve in ms for N_p = 10–50 with 5–10 states
Quadprog (MATLAB): general; reliable; use for offline tuning
HPIPM, DAQP: embedded; for automotive/aerospace real-time (μs to ms solve time)
For N_p = 100, n = 50 states: solve time ~ 100 ms–1 s (batch MPC; not suitable for fast systems)
Computational requirement:
Real-time MPC: solve must complete within sample period T_s
T_s > 10 × solve_time (stability margin for computation)
For automotive ACC (0.1 s sample): need < 10 ms QP solve → N_p = 20–40, N_c = 5 typical
Offset-Free MPC (Integral Action)
Problem: Output Offset with Unknown Disturbances
Without integral action:
Constant unmeasured disturbance d → output offset (y ≠ r at steady state)
Model mismatch → same effect
Augmented disturbance model:
x_aug = [x; d] [augment state with disturbance model]
A_aug = [A B_d; 0 I]; B_aug = [B_u; 0]; C_aug = [C 0]
Estimator (Kalman or Luenberger) estimates both state and disturbance
MPC uses d̂ in prediction → automatic disturbance rejection → zero steady-state offset
Alternative: velocity form MPC:
Work with Δu (increments) → integrator implicit in plant model → offset free for step setpoints
Linear vs. Nonlinear MPC
Linear MPC (most common)
Suitable for: weakly nonlinear processes; linear process control; MIMO
Fast QP solution → real-time capable for large N_p and N_c
Requires: linearization around operating point; model obtained from step tests or first principles
Linear MPC limitations:
Model valid only near linearization point; poor for large setpoint changes or highly nonlinear systems (batch reactors, biological systems)
Nonlinear MPC (NMPC)
Required when: significant nonlinearity (batch processes, pH control, fuel cell, autonomous vehicles)
NMPC formulation:
Same receding horizon; but prediction uses full nonlinear model f(x, u) → ODE integration
Optimization: NLP (nonlinear programming) instead of QP → much more expensive
Solvers: IPOPT (interior point, open source), ACADO (fast; RTI scheme), CasADi (symbolic autodiff)
Real-Time Iteration (RTI) scheme:
Solve NLP approximately in one SQP step → very fast (< 1 ms for small systems)
Trade-off: slightly suboptimal but real-time feasible
Used in: automotive MPC (ACC, lane keeping), aircraft control, high-performance robotics
NMPC computation cost:
N_p = 20, N_c = 5, n = 10 states: RTI solve ≈ 1–10 ms (typical embedded NMPC)
Economic MPC
Objective: directly minimize economic cost (energy, profit, throughput) instead of tracking error
J_economic = Σ cost_function(x_k, u_k) [e.g., minimize energy consumption + maximize throughput]
Key difference from tracking MPC:
Tracking: cost = 0 at setpoint; minimum at setpoint
Economic: cost never zero; optimal steady-state is problem-dependent; may not correspond to a fixed setpoint
Stability: economic MPC may not be stable without additional terminal constraints
Terminal region constraints or rotated cost function to ensure stability
Application:
Chemical plant: maximize production rate subject to product quality and equipment constraints
Grid energy: minimize electricity cost using forecasted prices with battery/demand constraints
MIMO Applications
Chemical Process Control (Distillation Column)
Distillation column MIMO:
Inputs: u = [reflux (L), vapor boilup (V), feed flow (F)]
Outputs: y = [distillate purity (x_D), bottoms purity (x_B), column pressure (P)]
Strong interaction: L and V coupled → MIMO MPC handles naturally
Transfer function model (linear MPC):
G(s) = Y(s) / U(s) [3×3 transfer function matrix; fit from step response data]
Discretize at T_s = 5 min → A, B, C matrices → MPC
Industrial implementation (Aspentech DMCplus, Honeywell Profit Controller):
N_p = 60 steps (5 h for T_s = 5 min); N_c = 10; QP solve < 30 s
Handles constraint violations, feed disturbances, product spec changes
Automotive ACC (Adaptive Cruise Control)
States: x = [relative distance, relative velocity, ego velocity]ᵀ
Inputs: u = [acceleration/deceleration command]
Constraints: min following distance (safety); max deceleration (-0.3 g); max acceleration (0.2 g)
NMPC for comfort and safety:
N_p = 20 steps at T_s = 0.1 s (2 s lookahead)
Cost: J = w_dist × (d - d_ref)² + w_vel × (v - v_lead)² + w_jerk × (Δa)²
Solve time with RTI: < 5 ms → real-time capable
Lane Keeping: NMPC with kinematic bicycle model; N_p = 20 at T_s = 50 ms; lateral constraints (lane boundaries)
MATLAB MPC Toolbox Implementation
% Define plant model
A = [...]; B = [...]; C = [...]; D = [...];
plant = ss(A, B, C, D, Ts); % Ts = sample time
% Create MPC object
mpc_obj = mpc(plant, Ts);
% Prediction and control horizons
mpc_obj.PredictionHorizon = 20; % N_p
mpc_obj.ControlHorizon = 5; % N_c
% Weights
mpc_obj.Weights.OutputVariables = [1 0]; % Q; first output tracked
mpc_obj.Weights.ManipulatedVariablesRate = [0.1 0.1]; % R
% Constraints
mpc_obj.MV(1).Min = u1_min; mpc_obj.MV(1).Max = u1_max;
mpc_obj.MV(1).RateMin = du1_min; mpc_obj.MV(1).RateMax = du1_max;
mpc_obj.OV(1).Min = y1_min; mpc_obj.OV(1).Max = y1_max;
% Simulate
[y, t, u] = sim(mpc_obj, Nsim, r_ref, d_measured);
Key verification checks:
Constraint satisfaction: all inputs and outputs within bounds throughout simulation
Stability: run step response test → settles to zero offset at steady state (if offset-free)
Performance: compare setpoint tracking speed and overshoot vs. PID baseline
Standards and References
| Source | Scope |
|---|
| Rawlings, Mayne, Diehl "Model Predictive Control" (2017) | Standard MPC textbook |
| Maciejowski "Predictive Control with Constraints" | Practical MPC reference |
| ISO 22179 | FDSS (full-speed range dynamic driving support) — includes MPC for ACC |
| ISA-5.1 | Instrumentation symbols (process control application) |
| MATLAB MPC Toolbox | Official documentation |
Output
Provide: system type (process/automotive/energy), plant model (A, B, C matrices or transfer function; SISO or MIMO), sample time T_s [s], prediction horizon N_p and control horizon N_c, cost function (Q and R matrices with justification), input constraints (u_min, u_max, Δu_min, Δu_max), output/state constraints (y_min, y_max), soft constraint penalty ρ, QP or NLP solver selected and expected solve time [ms] vs. T_s, offset-free mechanism (augmented disturbance model or velocity form), closed-loop performance (settling time [s] and overshoot [%] for step setpoint), constraint violation during transient (checked? none?), comparison to PID (MPC improvement: [%] better tracking or [%] constraint violations reduced), MATLAB code snippet, and applicable reference (Rawlings 2017, MATLAB MPC Toolbox).