Contents · Optimal Control
Part 0 · LQR
Part 1 · Dynamic Programming
Part 2 · Trajectory Optimization
- iLQR and Trajectory Optimization
Part 3 · MPC
Part 4 · Continuous Optimal Control
Part 2 · Trajectory Optimization
iLQR and Trajectory Optimization
LQR solved one problem exactly: linear dynamics, quadratic cost, a closed-form feedback gain. Real robots are neither linear nor cheap to write in closed form. Trajectory optimization keeps the objective and drops the restriction: minimize a cost over an entire control sequence subject to the true nonlinear dynamics. iLQR and its second-order sibling DDP are the model-based workhorse, and they get there by solving, over and over, the one problem you already know how to solve.
The problem
Fix a horizon and search over the controls :
The dynamics are equality constraints, so the states are not free: once the controls are chosen, a rollout of fixes them. The decision variable is the control sequence alone.
Take a pendulum. State with measured from the downward vertical, so hangs straight down and balances upright. The continuous dynamics are with the torque bounded, . A semi-implicit Euler step gives the discrete map :
A cost that asks for the tip upright at the end with little effort spent:
whose terminal term is exactly when and at the bottom. When the torque cannot hold the arm horizontal, let alone lift it in one push, so any optimal solution has to pump: swing back to build energy, then up.
The iLQR loop
iLQR never touches the nonlinear problem directly. Given the current controls and their rollout , it repeats three steps.
1. Local model. Linearize the dynamics and quadratize the cost about . Writing , ,
with and replaced by their second-order Taylor models. That is precisely a time-varying LQR problem in the deviations .
2. Backward pass. Run the LQR / Riccati recursion of the previous chapter on this local model. It returns an affine update
a feedforward correction plus a feedback gain . This is a Newton-like step on the whole trajectory, not a coordinate-wise nudge.
3. Forward pass. Apply the update to the true dynamics with a line-search scale ,
roll out the nonlinear , and accept if dropped, shrinking otherwise. Iterate to a local optimum. DDP is the same loop but keeps the second-order dynamics terms in the backward pass; iLQR drops them (a Gauss-Newton step), which is cheaper and, for many problems, more robust.1 Hard limits enter as a small box-constrained QP solved inside the backward pass.2
Reading the gradient
Before the full second-order machinery, the first-order picture makes the mechanism concrete. A rollout is a composition of maps, so is an ordinary function of , and comes from one reverse sweep, the discrete adjoint (back-propagation through time):
A two-step toy. Set , , , , , start at , and guess . The forward rollout is
so . With the Jacobians are
Seed the adjoint with and sweep backward. From the last step, and ; from the first,
Both components are negative, so raises both torques and drives toward : the swing-up direction. And , because the earlier control propagates through more steps and so has more leverage on the terminal state. One gradient step with gives , a new , and .
iLQR replaces that fixed- nudge with the LQR step , which folds in the cost and dynamics curvature and converges in a handful of iterations rather than thousands, and it returns the gain , so the output is a controller, not just an open-loop plan. One detail the toy exposes: at the exact bottom , , so a zero-torque guess has zero gradient. A swing-up needs a non-trivial initial guess, which is why the demo seeds small random controls.
Swing-up by optimizing the controls
The demo runs the first-order version end to end: a torque-limited pendulum starting at rest at the bottom, steps, with computed by exact back-propagation through the two-state dynamics and plain gradient descent on the torques. Watch the replayed trajectory morph from a useless wiggle into a pump-and-swing as the cost falls.
trajectory · x = [θ, θ̇]
torque u = 0.29 / ±5
cost J vs. iteration
iteration 0 / 2500
final tip: 179.9° from upright
Optimize seeds a small random control sequence, then runs 2500 gradient steps u ← u − α ∇uJ with ∇uJ from back-propagation through time. The pendulum replays the current controls; the plot is cost per iteration.
Why it is the workhorse
iLQR is model-based: it needs and the Jacobians . Minimal-coordinate engines supply exactly these in closed form, which is what makes differentiable simulation drop straight into the loop. One solve yields an open-loop plan together with local feedback gains; re-solve a short-horizon version every control step and the same machinery becomes model predictive control, the method underneath most modern legged and manipulation controllers. LQR gave the local model; iLQR iterates it into a plan for a nonlinear world.
Footnotes
-
Todorov & Li, A generalized iterative LQG method for locally-optimal feedback control of constrained nonlinear stochastic systems (ACC 2005). ↩
-
Tassa, Mansard & Todorov, Control-Limited Differential Dynamic Programming (ICRA 2014). ↩