Planning & Control · 5 Interactives

Imagine Three Seconds Ahead. Act Once. Repeat.

Model Predictive Control never commits to a full plan. Every step it imagines a short window of futures, picks the best one, executes only the first action — then throws the rest away and imagines again. No training, no learning: just relentless replanning. Drive the car below and feel why that moving window is so hard to knock over — and exactly how to break it.

The moving window Fan of futures Push the car The cul-de-sac The price of foresight
EP 01

Planning as a moving window — never the whole trip, always the next stretch

The car below follows the grey road past two obstacles. It has no route memorized. At every single step it imagines a short trajectory (the white dashed line — its current best plan), drives one step of it, then re-imagines from wherever it actually is. The gold trail is what really got driven; the dashed line is a plan that is constantly being thrown away. Slide the horizon and watch the imagination window stretch and shrink while the car keeps driving.

The planner is a real random-shooting MPC running in your browser: 79 candidate steering sequences are rolled out through the car's physics every step, scored on road-distance, obstacle hits and progress, and the winner's first action is executed.

The mental model: MPC = a chess player who only ever calculates a few moves deep, plays one move, then recalculates. Nothing is learned and nothing is remembered — the plan's shelf life is exactly one step. This receding window is how rockets land, how chemical plants hold temperature, and how robot dogs place their feet.
EP 02

Inside one heartbeat — 79 futures in, one steering command out

Freeze time and look inside a single planning step. Press sample futures: the planner rolls 79 candidate steering sequences through its physics model — the grey fan. Each gets a cost (off-road distance + obstacle penalties − progress). The green trajectory is the cheapest. Now press execute first action: the car moves one step along the winner (thick gold segment) — and the other 99% of the plan, including the rest of the green line, is discarded and re-sampled from scratch.

Costs are computed live from the rollouts — lower is better. This sampling flavor of MPC (random shooting / MPPI-style) is exactly what many model-based RL agents use for control.

Why only the first action? Because by the next step the world has already answered — and the freshest plan always starts from reality, not from an old prediction. Committing to step 2 of an old plan means acting on stale information. Tesla-style trajectory planners and MuZero-style agents both live by this rule.
EP 03

Shove it — why replanning beats the perfect plan

Two identical cars follow the same road. The gold car runs MPC, replanning every step. The red car planned once at the start — a flawless open-loop script of steering commands — and executes it blindly. While they drive, hit push: both cars get knocked sideways by the same shove. Watch what each does next. MPC never even notices it was disturbed — it just replans from the new position, like it does every step anyway. The red car keeps executing a plan for a world that no longer exists.

The red car's script was produced by the very same planner — it is not a strawman. The only difference is when planning happens: once, versus every step.

✓ Good case: robustness to surprises without any learning — MPC recovers instantly because recovery is just another replan. ✗ Bad case: any open-loop plan, however optimal, is only as good as its forecast of the future. This is why walking robots survive kicks in demos: they aren't balancing better, they're re-deciding 100 times a second.
EP 04

The cul-de-sac — when the window is too short to see the trap

The goal is the green dot. Straight ahead lies a dead-end pocket — a wall shaped like a bracket, open toward the car. A short-horizon planner only scores where it ends up a few steps from now, and every step into the pocket looks like progress… until the wall. Run it with a short horizon and watch the car dive in, panic at the cap, U-turn, exit — and dive right back in, forever. Then lengthen the horizon until the rollouts are long enough to reach the back wall in imagination, and the detour around suddenly scores best.

Press Run.

Nothing else changes between the two runs — same cost function, same candidates, same physics. Only how far the imagination reaches.

✗ Bad case: a horizon shorter than the trap makes greedy look optimal — the planner literally cannot represent "this road ends". Real-world versions: a delivery drone circling a courtyard, a game agent farming a local reward. The fix is not more compute per step, it's a longer window — or a learned value function stapled to the horizon's end, which is exactly what MuZero and AlphaGo do.
EP 05

The price of foresight — compute explodes, and your model lies more the further it looks

So just crank the horizon to 1000? Two things stop you. One: every extra step multiplies rollout compute — watch the meter. Two: the planner imagines with a model, and models are wrong. Here the model misjudges steering strength and doesn't know about a crosswind. The white dashed line is what it imagines will happen; the red line is what actually happens if you execute that whole plan open-loop — they peel apart, and the error compounds with every imagined step. The gold line is MPC executing one step and replanning: the same wrong model, kept honest by constant contact with reality.

The compute figure counts real rollout steps this page just simulated (79 candidates × horizon). Our sampler's cost grows linearly, but with a fixed sample budget a longer horizon searches an exponentially bigger action space ever more sparsely — real trajectory optimizers pay far more than linear.

The sweet spot: long enough to see the trap (EP 04), short enough that compute fits the control loop and model error hasn't compounded into fiction. ✗ Bad case: a huge horizon buys you expensive, confidently-wrong predictions. ✓ Good case: a modest horizon plus replanning — model error never gets more than one step of runway. That trade-off, not any single number, is the actual engineering of MPC.
Keep playing
Reinforcement Learning
The Sim2Real Gap
Train a hopping robot in a perfect simulator, deploy it onto messy real floo
Reinforcement Learning
Curriculum Learning
Watch a real learner fail at a hard task, then master it through staged diff…