Optimal Control & Planning, Part 1

Plan the whole control schedule before the robot moves. On this drifting hovercraft, iLQR finds the cheapest schedule in 2 iterations. Gradient descent on the same cost needs about 100.

Press Optimize and watch both planners bend the path. Then raise the effort cost and run it again. After that we build each piece: the problem, the backward pass, iLQR, Newton's method and trust regions.

You need matrix multiply and inverse, a little Python, and the idea of cost-to-go from Lecture 7. We build the rest from zero.

Lecture 13 of 25 in Introduction to Robot Learning, CMU 16-831 (Spring 2024), taught by Guanya Shi. Slides on the course lectures page. Every idea is re-taught here in our own words and devices. Before this: Lecture 12, Model-Based Control Basics.

Race two planners on one cost

0.05

Illustrative toy. The hovercraft starts drifting north at 2.2 m/s with air drag. It must stop on the pad 4 m east after 4 s (40 steps of 0.1 s). Cost: effort times the sum of squared thrusts, plus misses at the end. Both planners start from zero thrust.

Chapter 0

Plan the Whole Throw

Choose every control before you act, and let a known model carry the plan

You throw a ball into a bucket 6 m away. Once the ball leaves your hand, you cannot steer it. So you pick the angle and the speed first, and physics does the rest.

That is trajectory optimization: choose a whole sequence of controls, before acting, so that a known model carries the system to the goal at the lowest cost. It is also called open-loop optimal control or planning. Open loop means the plan does not look at the world while it runs.

Throw into the bucket

Set the angle and the speed, then watch where the ball lands. Press Plan to let an optimizer pick both.

30°
7.0 m/s

Illustrative toy with no air drag and g = 9.81 m/s². The planner minimizes 5 × miss² + 0.01 × speed², so it wants the slowest throw that still lands.

Many throws land in the bucket. The planner prefers the one that costs least, here the slowest: 45° at about 7.7 m/s. The range is speed² × sin(2 × angle) / g, and 45° gives the most range per unit of speed. Every method in this lesson trades the same two costs: reach the goal, and spend little effort.

Planning is possible because of cost-to-go: the cheapest cost from a state to the end. If you know what the rest of the trip costs, you can weigh "cost now" against "cost later" at each step.

The failure, as symptom, measurement and fix

The symptom is a plan that is perfect on paper and misses in the world. To measure it, run the plan with a small push and record the miss at the end. The fix is feedback: LQR returns gains that correct the plan (Chapters 3 and 8), and the next lecture plans again at every step.

The road

  1. The problem: the cost, the dynamics constraint, and why some problems are hard.
  2. Shooting and collocation: two ways to hand a trajectory to a solver.
  3. Cost-to-go stays a bowl: the Bellman step that gives the LQR gain.
  4. The backward pass by hand: the Riccati update with numbers, checked two ways.
  5. iLQR: linearize, solve LQR, roll out on the true model, repeat.
  6. Newton and DDP: why iLQR needs so few iterations.
  7. SCP: obstacles, local half-planes and the trust region.
  8. The planner bench: the hero's full version, with drag and a gust.
  9. The field guide: terms, numbers, code, links and credit.
What makes a problem open-loop trajectory optimization, rather than a feedback policy?

Chapter 1

The Problem, Written Down

Write one optimization that every method in the lesson attacks, and find what makes it hard

Every algorithm here solves one problem. Name its parts first.

The state x-t is everything you need to know at step t, such as position and speed. The control u-t is what you command, such as a thrust. The cost c-t scores one step. The dynamics f give the next state. The horizon T is the number of steps.

Say it aloud

Minimize over x and u the sum over t of c-t of x-t and u-t, such that x-t-plus-one equals f of x-t and u-t.

minx,u
minimize over x and u search all state and control sequences for the cheapest one.
Σt
the sum over t add one cost term for each step from 1 to T.
ct(xt, ut)
c-t of x-t and u-t the cost of being in state x-t and pushing with u-t: distance from the goal plus effort.
xt+1 = f(·)
x-t-plus-one equals f of x-t and u-t the dynamics constraint. A legal control must lead to each state.
In plain words

Pick the controls u-t. Run them through f to get the states x-t. Add up the step costs c-t. Find the controls that make the total smallest.

With numbers

With made-up numbers: f(x, u) = 2x + u, step cost ½x² + ½u², x-1 = 2, T = 3. Try u-1 = −3 and u-2 = −1. Then x-2 = 1 and x-3 = 1. Total = ½(4 + 9) + ½(1 + 1) + ½(1) = 8. Chapter 4 shows no schedule does better.

The dynamics constraint is the whole difficulty. Without it, you set every state to the goal at zero cost. With it, f threads the path together, one step at a time. Real problems add constraints too: stay out of the obstacle, keep thrust under the motor limit.

Some problems are convex: the average of two allowed paths is always an allowed path. Then any local minimum is the global one. An obstacle breaks this, even with linear dynamics.

Blend two safe paths

The top and bottom paths both miss the obstacle and both obey the dynamics. Slide the blend between them and watch the middle.

50% top

Illustrative toy: a mass that you push (double integrator), rest to rest from (0, 0) to (10, 0). Effort is the sum of squared pushes. A blend of two paths uses the blend of their pushes, so it obeys the same linear dynamics.

The 50% blend is the cheapest path on the slider, and it runs through the obstacle. "Go left or go right" is a choice, not a slope. That one fact decides the tool:

ProblemToolWhere
Linear dynamics, quadratic cost, no constraintsLQR, exact in one backward passChapters 3, 4
Nonlinear dynamicsiLQR, DDP: linearize, solve LQR, repeatChapters 5, 6
Constraints such as obstaclesSCP, SQP: convexify, solve a QP, repeatChapter 7

The failure, as symptom, measurement and fix

The symptom is a solver that returns a bad path with full confidence. To measure it, start the solver from two different first guesses and compare the costs. The fix is a better first guess, or a method that searches more widely (Lecture 14).

Why can you not set every state x-t equal to the goal and get zero cost?

Chapter 2

Two Ways to Write a Trajectory

Choose the variables a solver sees: controls only, or states and controls tied by defects

Before you solve, decide what the variables are. There are two classic answers.

In single shooting, only the controls are variables. You get the states by simulation: apply u-1 to x-1 through f, then u-2, and so on. The dynamics hold by construction. The name comes from artillery: aim, fire, see where it lands, adjust.

The flaw is sensitivity. A push at step 1 changes every later state, so early controls swing the end far more than late ones.

Nudge a control, or close the gaps

Shooting: nudge one control and the whole path after it moves. Collocation: the states are free dots, and red gaps show where they break the dynamics. Drag the solver's progress to close them.

1
0.20

Illustrative toy: x-next = x + v and v-next = v + u, with 1 s steps, from rest at 0 to rest at 10 in 15 steps. The grey plan is the least-effort answer. The progress slider blends the first guess into it; a real solver takes its own route.

In direct collocation, both states and controls are variables. The solver may propose any states, so the dynamics become explicit constraints. Call the mismatch at step t the defect d-t.

Say it aloud

d-t equals x-t-plus-one minus f of x-t and u-t, and it must equal zero.

dt
d-t the defect at step t: how far the plan breaks physics there.
xt+1
x-t-plus-one the next state the solver proposes, a free variable.
f(xt, ut)
f of x-t and u-t where the dynamics say you land from the proposed state and control.
= 0
equals zero the constraint the final answer must meet at every step.
In plain words

For each step, apply f to the proposed state x-t and control u-t. Subtract that from the proposed next state x-t-plus-one. The solver must drive every defect d-t to zero.

With numbers

From the device's first guess: x-t = 4.00 m, speed 0, push 0, so f gives 4.00 m. The guess says x-t-plus-one = 4.67 m. d-t = 4.67 − 4.00 = 0.67 m. The guess is not physical yet.

EncodingVariablesDynamicsGood at
Single shootingT controlshold by simulationshort horizons, simple code
CollocationT states + T controlsdefect constraintslong horizons; each defect touches only two neighbours

Chapters 3 to 6 use the shooting view, because it makes the dynamic programming clean. Chapter 7 handles constraints in the collocation spirit. In the lab, shooting meets the simplest improver: sample control sequences, keep the cheapest, refit.

The failure, as symptom, measurement and fix

The symptom is a shooting solver that stalls on a long horizon. To measure it, compare how far the end moves for the same nudge at step 1 and at the last step. The fix is collocation, or a method that uses the time structure, like LQR.

In single shooting, how do the dynamics constraints hold?

Chapter 3

Cost-to-Go Stays a Bowl

Derive the LQR gain from one Bellman step, and see why the best control is a line in the state

One special case has an exact answer. The Linear Quadratic Regulator (LQR) assumes three things: linear dynamics x-t-plus-one = A x-t + B u-t, a quadratic cost ½xᵀQx + ½uᵀRu, and no constraints. A moves the state alone, B carries the push. Q prices distance from zero, R prices effort. Lecture 12 used LQR as a controller; here we derive it.

Work backward from the end. Call the cost-to-go from state x at step t V-t(x). The guess, which the algebra confirms, is a bowl: V-t(x) = ½xᵀP-t x for some matrix P-t. At the last step there is no future, so P-T = Q. The Bellman recursion links one step to the next.

Say it aloud

V-t of x equals the min over u of: one half x-transpose Q x, plus one half u-transpose R u, plus V-t-plus-one of A x plus B u.

Vt(x)
V-t of x the cheapest cost from state x at step t to the end.
minu
the min over u try every control now and keep the cheapest total.
½xᵀQx
one half x-transpose Q x the state cost now. For one number x, it is ½Qx².
½uᵀRu
one half u-transpose R u the effort cost now, ½Ru² for one number.
Vt+1(Ax+Bu)
V-t-plus-one of A x plus B u the cost-to-go from where this control lands you, ½P-t-plus-one (Ax + Bu)² for one number.
In plain words

For each control u, add the cost now to the cost-to-go from the landing state Ax + Bu. Pick the u with the smallest total. That total is V-t(x).

With numbers

With made-up numbers: A = 2, B = 1, Q = R = 1, P-t-plus-one = 1, x = 1. Total(u) = ½ + ½u² + ½(2 + u)². The bottom is at u = −1, with total 1.5. So V-t(1) = 1.5, which is ½ × 3 × 1²: P-t = 3.

Find the bottom of one Bellman step

The yellow curve is the total over every control u. Move the state x and watch the best control slide along a straight line. Raise P-t-plus-one or R and the line tilts.

1.0
1.0
1.0

Scalar toy with A = 2 and B = 1: the state doubles each step unless you push. Q = 1.

The total is a bowl in u. Set its slope to zero: (R + BᵀP-t-plus-one B) u + BᵀP-t-plus-one A x = 0. Solve for u.

Say it aloud

u-star equals minus K-t x, where K-t equals the inverse of R plus B-transpose P-t-plus-one B, times B-transpose P-t-plus-one A.

u*
u-star the best control at step t.
Kt
K-t the feedback gain at step t: how hard to push per unit of state.
(R + BᵀPt+1B)−1
the inverse of R plus B-transpose P-t-plus-one B divide by the price of pushing: effort now plus the future cost a push stirs up.
BᵀPt+1A
B-transpose P-t-plus-one A how much a push now lowers the cost-to-go.
In plain words

Take what a push saves later, BᵀP-t-plus-one A. Divide by what a push costs, R + BᵀP-t-plus-one B. That ratio is K-t. Push with minus K-t times the state.

With numbers

Same made-up numbers: K-t = (1 + 1 × 1 × 1)−1 × 1 × 1 × 2 = 2 / 2 = 1. At x = 1, u* = −1, as the bowl showed. Double R to 2 and K-t drops to 2 / 3.

The surprise. We set out to plan a sequence, and LQR hands back a gain K-t for every step. The plan is a feedback rule, u = −K-t x, that works from any state.

The failure, as symptom, measurement and fix

The symptom is a gain that explodes or flips sign. To measure it, print R + BᵀP B at each step; it must stay positive definite. The fix is a positive definite R, so the bowl always has a bottom.

You raise R, the effort price. What happens to the gain K-t?

Chapter 4

Run the Backward Pass by Hand

Sweep the cost-to-go matrix from the end to the start, then check it against a forward rollout

Put u* back into the Bellman step. The total is a bowl in x again, which confirms the guess. Its matrix is the new P-t. Call the price of pushing S-t = R + BᵀP-t-plus-one B.

Say it aloud

P-t equals Q, plus A-transpose P-t-plus-one A, minus K-t-transpose S-t K-t.

Pt
P-t the cost-to-go matrix at step t. V-t(x) = ½xᵀP-t x.
Q
Q the state cost you pay now.
AᵀPt+1A
A-transpose P-t-plus-one A the future cost if you did not push at all.
KtᵀStKt
K-t-transpose S-t K-t what the best push saves. S-t is R + BᵀP-t-plus-one B.
In plain words

Start from P-T = Q. At each step back, add the cost now Q to the do-nothing future AᵀP-t-plus-one A. Subtract the saving K-tᵀS-t K-t. Store K-t on the way. This update is the discrete-time Riccati equation.

With numbers

With made-up numbers A = 2, B = 1, Q = R = 1, T = 3. P-3 = 1. Step 2: S = 2, K = 1, P-2 = 1 + 4 − 2 = 3. Step 1: S = 4, K = 3 × 2 / 4 = 1.5, P-1 = 1 + 12 − 9 = 4.

Check it forward.

Start at x-1 = 2. Push u-1 = −1.5 × 2 = −3, landing at x-2 = 4 − 3 = 1. Push u-2 = −1, landing at x-3 = 1. The cost is ½(4 + 9 + 1 + 1 + 1) = 8. The backward pass predicted ½P-1 x-1² = ½ × 4 × 4 = 8. Doing nothing costs ½(4 + 16 + 64) = 42.

Sweep P backward

Yellow bars are P-t, filled from the right. The purple line is the gain K-t. Press Sweep, then lengthen the horizon and watch both settle away from the end.

3
1.0

Scalar toy: A = 2, B = 1, Q = 1, start x-1 = 2. The read-out rolls the gains forward and compares the cost with ½P-1 x-1².

With R = 1, P settles at 2 + √5 = 4.24 and K at 1.62. That limit is the infinite-horizon LQR of Lecture 12. Two more facts make LQR the building block:

The failure, as symptom, measurement and fix

The symptom is a backward pass whose forward cost does not match ½xᵀP x. To measure it, roll the gains forward and compare the two numbers. The usual fix is an index error: K-t must use P-t-plus-one, not P-t.

The backward pass gives P-1 = 4 for x-1 = 2. What does the forward rollout cost?

Chapter 5

iLQR: Linearize, Solve, Repeat

Turn a nonlinear problem into a string of LQR problems around the current guess

Real robots are not linear. A pendulum has a sine in it. The hovercraft has drag that grows with speed squared. LQR is exact only for the linear case. Iterative LQR (iLQR) uses it anyway, around the current guess:

  1. Linearize the dynamics around the current path x̄-t, ū-t: A-t = ∂f/∂x and B-t = ∂f/∂u, a different pair at each step.
  2. Quadratize the cost around the same path.
  3. Backward pass: solve that local LQR. Get a gain K-t and a feed-forward step k-t for each step.
  4. Forward pass: roll out the new controls on the true nonlinear dynamics.
  5. Repeat until the path stops moving.

The forward pass applies this rule at each step. The bar over a letter means "on the current path".

Say it aloud

u-t equals u-bar-t, minus K-t times x-t minus x-bar-t, minus alpha k-t.

ut
u-t the new control at step t.
ūt
u-bar-t the control on the current path.
Kt
K-t the feedback gain from the local LQR.
xt
x-t the state the true dynamics reached in this rollout.
x̄t
x-bar-t the state on the current path.
α
alpha the step size, from 1 down to small, chosen by a line search.
kt
k-t the feed-forward change that lowers the cost.
In plain words

Start from the old control u-bar-t. Add the improvement alpha k-t. Then correct for drift: if the true state x-t has left the old path x-bar-t, push back with K-t. If the cost went up, halve alpha and roll again.

With numbers

With made-up numbers: u-bar-t = 0, K-t = 0.9, x-t − x-bar-t = 0.5, alpha = 1, k-t = −1.2. u-t = 0 − 0.45 + 1.2 = 0.75. The feedback term took 0.45 off the planned push.

Step iLQR one pass at a time

Grey is the current path. Pink dashes are where the linear model predicts the new controls will go. Teal is where the true dynamics take them. Press Iterate.

1.00

The hero's hovercraft with effort 0.05. The prediction uses the linearized A-t and B-t of the grey path. The dynamics are exact; the drag is a toy.

At drag 1, the first prediction ends 6.5 m east, but the true rollout ends at 3.7 m. The cost still falls from 210 to 3.3, because the forward pass runs on the true model with K-t correcting the drift. Set drag to 0 and iLQR is plain LQR: one iteration and done.

The failure, as symptom, measurement and fix

The symptom is a cost that goes up after an iteration. To measure it, log the cost at every alpha tried. The fix is the line search: halve alpha until the cost falls. If R + BᵀPB is near singular, add a small number to its diagonal.

What is the difference between iLQR's backward and forward passes?

Chapter 6

iLQR Is Newton's Method; DDP Adds Curvature

See why a step scaled by curvature beats a step scaled by one learning rate

In the hero, gradient descent needed about 100 iterations and iLQR needed 2. The reason is Newton's method. Say you minimize a function h of one number a. Call its slope at the current point g and its curvature H. Newton fits a parabola there and jumps to its bottom.

Say it aloud

a-next equals a minus g over H.

anext
a-next the new guess.
a
a the current guess.
g
g the slope of h at a: which way is downhill, and how steep.
H
H the curvature of h at a: how fast the slope changes. For many numbers it is the Hessian matrix and we divide by its inverse.
In plain words

Measure the slope g and the curvature H. Step against the slope, divided by the curvature. A flat direction gets a long step, a steep one a short step. Gradient descent uses one learning rate eta instead: a-next = a − eta g.

With numbers

The device's function at a = −2.5: g = −8.75 and H = 8.5. a-next = −2.5 + 8.75 / 8.5 = −1.47. The best answer is a = 0.

Race Newton down a stretched bowl

Grey is gradient descent with the largest safe learning rate. Teal is Newton. Stretch the bowl, then press Run.

20

Illustrative function h(a, b) = ½(a² + stretch × b²) + 0.1a⁴, started at (−2.5, 1). The learning rate is 1.8 divided by the largest curvature on the way, just under the limit of 2 where it diverges. "Done" means the slope is under 0.001.

Gradient descent must keep its learning rate safe for the steepest direction, so it crawls along the flat one. A shooting cost has just this stretch: early controls move the end far more than late ones (Chapter 2).

Write the cost with the states replaced by the dynamics: c-1(x-1, u-1) + c-2(f(x-1, u-1), u-2) + ... Each term nests f one level deeper. iLQR is an approximate Newton step on it. The Riccati sweep builds and inverts its curvature in one pass that grows linearly with T.

MethodUses of the dynamicsStep
Gradient descentfirst derivatives, for the slope onlyone learning rate
iLQRfirst derivatives A-t, B-tapproximate Newton
DDP (differential dynamic programming)first and second derivatives of ffull Newton

DDP keeps how f itself curves. It is the exact second-order method. In practice iLQR is often preferred: second derivatives of f are costly and can make the step unstable, and iLQR converges well already. Both solve an unconstrained LQR each iteration.

The failure, as symptom, measurement and fix

The symptom is a Newton step that goes uphill. To measure it, check the sign of the curvature; a negative H points the step to a maximum. The fix is damping: add a positive number to H, which iLQR does as regularization.

What is the exact difference between iLQR and DDP?

Chapter 7

SCP: Convexify Inside a Trust Region

Replace a round obstacle with a straight line near the current path, solve, and move a little at a time

iLQR has no natural place for hard constraints such as an obstacle or a thrust limit. Sequential convex programming (SCP) and its relative sequential quadratic programming (SQP) make the same move as iLQR. The easy problem is now a QP: a quadratic program, with a quadratic cost and linear constraints.

  1. Affinize the dynamics around the current path: x-t-plus-one ≈ A-t x-t + B-t u-t + g-t.
  2. Quadratize the cost.
  3. Linearize the constraints.
  4. Solve the QP, with a trust region: no point moves more than ε from where it was.
  5. Repeat until the path stops changing.

Take a round obstacle. Call its centre c and its radius r. Call the i-th path point p-i, and the unit arrow from c toward the current p-i n-i. Near the current path, the circle becomes a straight line.

Say it aloud

n-i transpose, times p-i minus c, is at least r.

niᵀ
n-i transpose the unit arrow from the centre toward the current point. Multiplying by it measures distance along that arrow.
pi
p-i the new position of path point i, the variable.
c
c the obstacle's centre.
r
r the obstacle's radius, in metres.
In plain words

Draw the line that touches the circle where the arrow n-i leaves it. Keep p-i on the far side of that line. Every point there is outside the circle, and the rule is linear, so the QP stays convex.

With numbers

From the device: c = (5, 0.6), r = 1.6, current p-i = (5, −0.2), so n-i = (0, −1). The rule says −(y − 0.6) ≥ 1.6, so y ≤ −1.0. A trust region of 0.5 lets the point reach only y = −0.7, so the next iteration goes on.

Peel a path off an obstacle

Press SCP step. The pink line is the straight-line stand-in for the circle at the middle point; dashed purple circles are trust regions. Then bend the first guess over the top and solve again.

0.30 m
0.50 m

Illustrative toy: 25 points from (0, 0) to (10, 0); the cost is the sum of squared gaps between neighbours. 400 steps of projected gradient solve each QP. Here the straight-line stand-in is always safe, so a big trust region does not break it.

Why the trust region? The affine dynamics and the quadratic cost are true only near the current path. A free QP may jump to where the approximation is wrong, and the new path can be worse or even unsafe. The trust region is a leash, with the same job as iLQR's line search.

SCP is a heuristic. It can miss the best answer, or any safe answer, and it depends on the first guess. Bend the guess over the top and it settles on a route 0.76 m longer. It still powers real systems, from rocket landing to legged robots.

The failure, as symptom, measurement and fix

The symptom is a safe but poor path. To measure it, solve from several first guesses and compare the costs. The fix is a better start: the previous plan shifted by one step, a sampling planner such as RRT, or a learned guess.

Why does SCP add a trust region to each sub-problem?

Chapter 8

The Planner Bench

Plan with iLQR, then fly the plan through a gust with and without its gains

This is the hero with every knob. Drag sets how nonlinear the world is. Effort sets the trade between reaching the pad and saving thrust. The gust hits at 1.5 s, after the plan is fixed.

Plan, then fly through a gust

Purple dashes are the plan. Grey flies the plan's thrusts blind. Teal flies the plan plus its gains K-t. Set the knobs, then press Fly.

0.35
0.05
1.0 m/s

Illustrative toy. The gust adds a sudden southward speed at step 15. The gains are the K-t from iLQR's last backward pass. We count gradient descent iterations until it is within 1% of iLQR's cost, up to 3,000.

Things to try:

The gains help because the planner's last backward pass is an LQR around the plan. Lecture 14 goes one step further with model predictive control: it plans again from the measured state at every step.

Chapter 9

The Field Guide

Keep the methods, the terms and numbers, a checklist and the core backward pass in code

Every method here makes one move. Build a local problem you can solve exactly, and solve it. Take the answer as the next guess, with steps small enough to trust.

MethodHandlesSolves each iterationCost in horizon T
LQRlinear dynamics, quadratic cost, no constraintsone backward pass, no iterationslinear
iLQRnonlinear dynamics, no hard constraintsa local LQR from A-t, B-tlinear
DDPnonlinear dynamics, no hard constraintsa local LQR plus second derivatives of flinear
SCP, SQPnonlinear dynamics and constraintsa convex QP in a trust regioncubic for a generic QP

Terms and numbers

TermOne lineNumber to remember
Trajectory optimizationmin of the summed cost such that x-t+1 = f(x-t, u-t).Throw: 45° at 7.7 m/s for 6 m
Defectd-t = x-t+1 − f(x-t, u-t), zero at the answer.First guess: 0.67 m
Shooting sensitivityAn early push moves the end most.0.2 at step 1: 2.8 m; at step 14: 0.2 m
LQR gainK-t = (R + BᵀP-t+1 B)⁻¹ BᵀP-t+1 A; u = −K-t x.A = 2, P = 1: K = 1
Riccati updateP-t = Q + AᵀP-t+1 A − K-tᵀS-t K-t, from P-T = Q.P: 1, 3, 4; cost 8 both ways
Steady stateLong horizons settle to infinite-horizon LQR.A = 2, R = 1: P = 4.24, K = 1.62
iLQR forward passu-t = ū-t − K-t(x-t − x̄-t) − αk-t on the true model.Hero: 2 iterations against about 100
Newton stepa-next = a − g / H.−2.5 to −1.47 in one step
Linearized obstaclen-iᵀ(p-i − c) ≥ r inside a trust region ε.Wrong first guess: 0.76 m longer

Before you trust a planner

  1. Is the model right? The plan is only as good as f.
  2. Is the problem LQR? If yes, do one backward pass and stop.
  3. Does the forward cost match ½xᵀP x? If not, look for an index error.
  4. Does every iteration lower the cost? If not, use a line search or a smaller trust region.
  5. Do two first guesses agree? If not, you found a local answer.
  6. Will the world push back? Keep the gains, or plan again at every step.

The core backward pass in code

pythonimport numpy as np

def lqr_backward(A, B, Q, R, T):
    P = Q.copy()                              # P_T = Q: no future at the last step
    Ks = []
    for t in range(T - 1, 0, -1):
        S = R + B.T @ P @ B                   # price of pushing
        K = np.linalg.solve(S, B.T @ P @ A)    # gain: saving over price
        P = Q + A.T @ P @ A - K.T @ S @ K       # Riccati update
        Ks.append(K)
    return Ks[::-1], P                     # gains for t = 1..T-1, and P_1

# A = 2, B = 1, Q = R = 1, T = 3  ->  gains 1.5, 1.0 and P_1 = 4

Keep going on this site

The takeaway. Plan against a known model by sweeping cost-to-go backward. When the world is not linear or not free, solve a local LQR or QP, step, and repeat.

This lesson follows Lecture 13, Optimal Control and Planning, Part 1, of CMU 16-831 Introduction to Robot Learning, Spring 2024, taught by Guanya Shi. The slides are on the lectures page. The worked numbers and toys are ours.

Now press Present or Teach and explain from memory: the problem, shooting against collocation, the backward pass, the iLQR loop and the trust region. Then go back to the race, set the effort high, and say why both planners stop short of the pad.

Introduction to Robot Learning · CMU 16-831 · Lecture 13: Optimal Control and Planning, Part 1
Next: Optimal Control and Planning, Part 2 · Back to Gleams