Hyoungseo Son
Optimal Control
Contents · Optimal Control

Part 0 · LQR

Part 2 · Trajectory Optimization

Part 3 · MPC

  • Model Predictive Control

Part 4 · Continuous Optimal Control

Part 3 · MPC

Model Predictive Control

A linear-quadratic regulator hands you one gain matrix, computed once, that knows nothing about the torque and joint limits your hardware actually has. Model predictive control keeps the same quadratic cost but re-plans from the current state at every step, and that is exactly what lets it respect constraints. It is why MPC runs modern legged locomotion and manipulation controllers.

Re-solve every step

At the measured state xkx_k, MPC solves a finite-horizon optimal control problem over the next NN steps,

minu0,,uN1  j=0N1 ⁣(ejQej+ujRuj)+eNQfeN,\min_{u_0,\dots,u_{N-1}} \; \sum_{j=0}^{N-1}\!\left( e_j^{\top} Q\, e_j + u_j^{\top} R\, u_j\right) + e_N^{\top} Q_f\, e_N ,

subject to the dynamics and the limits,

xj+1=Axj+Buj,x0=xk,ujU,xjX,x_{j+1} = A x_j + B u_j, \quad x_0 = x_k, \quad u_j \in \mathcal{U}, \quad x_j \in \mathcal{X},

with ej=xjxrefe_j = x_j - x_{\text{ref}}. It applies only the first control u0u_0^{\star}, throws away the rest of the plan, advances to xk+1x_{k+1}, and solves the whole problem again from there. That re-solving from the fresh state is the receding horizon, and it is what closes the loop: disturbances and model error get absorbed because every step starts from where the system really is.

The unconstrained core is a finite-horizon LQR

Drop the constraints (U=Rm\mathcal{U} = \mathbb{R}^m, X=Rn\mathcal{X} = \mathbb{R}^n) and the inner problem has a closed form. Dynamic programming backward in time gives the discrete Riccati recursion,1 started from the terminal cost,

PN=Qf,P_N = Q_f, Kj=(R+BPj+1B)1BPj+1A,K_j = \left(R + B^{\top} P_{j+1} B\right)^{-1} B^{\top} P_{j+1} A , Pj=Q+APj+1AAPj+1BKj,j=N1,,0.P_j = Q + A^{\top} P_{j+1} A - A^{\top} P_{j+1} B\, K_j , \qquad j = N-1, \dots, 0 .

The optimal plan is the time-varying feedback uj=Kjeju_j = -K_j\, e_j. MPC applies its first entry u0=K0e0u_0 = -K_0\, e_0, steps, and reruns the backward pass at the next state.2

One backward pass by hand

Take a double integrator: position and velocity x=[p, v]x = [p,\ v]^{\top} driven by an acceleration uu,

pk+1=pk+vkΔt,vk+1=vk+ukΔt,p_{k+1} = p_k + v_k\, \Delta t, \qquad v_{k+1} = v_k + u_k\, \Delta t ,

so with Δt=1\Delta t = 1,

A=[1101],B=[01],Q=Qf=[1001],R=1.A = \begin{bmatrix} 1 & 1 \\ 0 & 1 \end{bmatrix}, \quad B = \begin{bmatrix} 0 \\ 1 \end{bmatrix}, \quad Q = Q_f = \begin{bmatrix} 1 & 0 \\ 0 & 1 \end{bmatrix}, \quad R = 1 .

Run the horizon N=2N = 2 backward from P2=Qf=IP_2 = Q_f = I. The last step (j=1j = 1):

BP2B=1,S=R+1=2,BP2A=[01],B^{\top} P_2 B = 1, \quad S = R + 1 = 2, \quad B^{\top} P_2 A = \begin{bmatrix} 0 & 1 \end{bmatrix}, K1=12[01]=[00.5],P1=Q+AP2AAP2BK1=[2112.5].K_1 = \tfrac{1}{2}\begin{bmatrix} 0 & 1 \end{bmatrix} = \begin{bmatrix} 0 & 0.5 \end{bmatrix}, \qquad P_1 = Q + A^{\top} P_2 A - A^{\top} P_2 B\, K_1 = \begin{bmatrix} 2 & 1 \\ 1 & 2.5 \end{bmatrix} .

The first step (j=0j = 0), now using P1P_1:

BP1B=2.5,S=3.5,BP1A=[13.5],B^{\top} P_1 B = 2.5, \quad S = 3.5, \quad B^{\top} P_1 A = \begin{bmatrix} 1 & 3.5 \end{bmatrix}, K0=13.5[13.5]=[0.2861.0].K_0 = \tfrac{1}{3.5}\begin{bmatrix} 1 & 3.5 \end{bmatrix} = \begin{bmatrix} 0.286 & 1.0 \end{bmatrix} .

Two things to read off. The applied gain K0=[0.286, 1.0]K_0 = [0.286,\ 1.0] weighs position error, while the one-step-ahead gain K1=[0, 0.5]K_1 = [0,\ 0.5] sees only velocity: a longer horizon changes the very first move. And MPC uses K0K_0 alone, applies u0=K0e0u_0 = -K_0\, e_0, then at the next measured state runs P2P1P0P_2 \to P_1 \to P_0 again from scratch.

Constraints make each step a QP

Real actuators saturate: uumax|u| \le u_{\max}. The moment U\mathcal{U} or X\mathcal{X} is a bounded set, the backward Riccati recursion no longer applies, because the minimization is now over a constrained quadratic. Stack the controls into one vector u=[u0,,uN1]\mathbf{u} = [u_0, \dots, u_{N-1}]^{\top}, eliminate the states through xj+1=Axj+Bujx_{j+1} = A x_j + B u_j, and the horizon cost collapses to a single quadratic program,

minu  12uHu+gus.t.uuu,\min_{\mathbf{u}} \; \tfrac{1}{2}\, \mathbf{u}^{\top} H \mathbf{u} + g^{\top} \mathbf{u} \quad \text{s.t.} \quad \underline{u} \le \mathbf{u} \le \overline{u} ,

with H0H \succ 0 assembled from Q,R,A,BQ, R, A, B and gg from the current xkx_k. That QP is what MPC actually solves each step. It is convex, so it solves reliably, and handling the box on u\mathbf{u} is exactly the machinery LQR's single gain cannot provide.2

The loop, live

The demo runs the constrained loop on the double integrator. Every control step it runs the full backward pass to get K0K_0, applies u=clamp(K0e, ±umax)u = \operatorname{clamp}(-K_0\,e,\ \pm u_{\max}), advances the true system, and re-solves. The faint blue curve is the planned NN-step trajectory rolled out from the current state, position against prediction step, redrawn every step.

Receding-horizon MPC · double integratorinteractive

position axis (drag to move target) · plan rises with prediction step

p
-4.00
v
0.00
u applied
+0.00
p − p_ref
-6.500

Re-solving the horizon every step and applying only K_0.

Drag the dashed marker to move the target. Short N: the plan is too short to see the target coming, so with the control clamped the cart arrives fast and overshoots. Long N: the plan brakes early and the approach is smooth. Raise u_max to relax the clamp; gold means the control is saturated.

Watch the blue plan lengthen as NN grows: a short horizon draws a plan that has not yet started decelerating, so the first control drives hard toward the target and, once clamped, cannot brake in time. A long horizon draws a plan that curves back onto the target, and applying its first step yields the smooth approach. Either way only K0K_0 is ever applied; the rest of the plan is advisory and is recomputed at the next state.

This is the constrained sibling of the finite-horizon LQR, and its inner solve is warm-started iLQR when the dynamics are nonlinear, which is how the same receding loop scales from this cart to a whole-body quadruped.

Footnotes

  1. Bertsekas, Dynamic Programming and Optimal Control.

  2. Rawlings, Mayne & Diehl, Model Predictive Control: Theory, Computation, and Design (2nd ed.). 2