Lab
Apollo Guidance Lab
Fly an Apollo-style lunar guidance scenario with state-space control, noisy sensors, and a live Kalman estimate.
Apollo-style guidance, simplified for play
Mission Presets
Each preset uses a browser-local Moon-centered guidance model. The physics are intentionally lightweight, but the estimator and controller are real.
Recover a safe return corridor after a navigation error on a lunar swingby.
Mission Timeline
White is the nominal corridor, amber is the true spacecraft, and cyan is the Kalman estimate. The pale ghost line is a coast prediction from the estimate.
Controller
Estimator and Vehicle
Diagnostics
Miss distance and estimator error over time. The dashed line is the corridor radius.
On corridor.
How to Read the Graphics
Trajectory view
The main canvas is the state projected into position space. The full state is
x = [p_x, p_y, v_x, v_y],
but the path only shows the position slice. The controller still reacts to all
four state variables.
Ghost path
The pale ghost line is an open-loop prediction from the current estimate. It is the model asking: “if I stop correcting right now, where will this state drift under gravity?”
Covariance ellipse
The ellipse is the position slice of the covariance matrix
P. Small means high
confidence. Long and tilted means the filter is uncertain in a particular
direction, not equally everywhere.
Diagnostics plot
Yellow is tracking error to the corridor. Cyan is estimation error. If cyan rises first, the controller is flying bad state information. If yellow rises first, the controller or thrust authority is not correcting enough.
Live Guidance State
The controller works on the estimate, not the true state. These vectors show what the guidance loop is actually seeing.
Reference x_ref
True x
Estimate x_hat
Error e = x_hat - x_ref
Control u
Innovation
Filter summary
Controller Math
Every step, the lab linearizes the current reference dynamics, discretizes them, and updates the controller and filter gains.
In LQR mode the law is u = -K(x_hat - x_ref).
Continuous model A
Discrete model Ad
Input map Bd
LQR gain K
Kalman gain L
Noise and limits
Math Behind the Motion
1. Dynamics
The plant is a simplified Moon-centered orbital model. In continuous time it
behaves like
x_dot = f(x) + Bu.
Each step the lab linearizes that nonlinear motion near the current reference to
build the local matrix
A.
2. Estimation
The measurements observe position, not velocity. The filter predicts the next
state, compares that prediction to the measurement, forms the innovation
nu = y - Hx_pred,
then uses the Kalman gain to decide how much to trust the sensors versus the
model.
3. Control
In LQR mode the law is
u = -K(x_hat - x_ref).
Bigger entries in
K
mean the controller is more willing to spend thrust to kill errors in that
state component.
Mental model
White is the mission plan. Pink is what the sensors say. Cyan is what the filter believes. Yellow is what the spacecraft is actually doing. The controller never sees yellow directly. It acts on cyan and succeeds only if the estimator stays honest.
What you are seeing
State-space guidance
The controller works on the full state vector: position and velocity. In LQR mode the lab linearizes the local dynamics, solves for a gain matrix, and drives the estimated state toward the reference corridor.
Kalman estimation
Raw measurements are noisy and can be biased. The cyan estimate blends the motion model with those measurements to reduce error and expose when your tuning is too optimistic.
Corridor thinking
Apollo guidance was never about a single perfect line in space. It was about staying inside a corridor where the next burn, the next measurement, and the remaining fuel all still worked in your favor.
This model is simplified
The lab uses a Moon-centered planar model with local linearization. That keeps the interaction fast and legible while still making the estimator-controller tradeoffs real.
Why the gain matrices change over time
This is not a fixed straight-line regulator. The orbital dynamics change with position, so the local Jacobian changes too.
That means the discrete model and the LQR gain both move as the spacecraft moves. The controller is solving a sequence of local linear problems wrapped around one nonlinear trajectory.
The matrix panel matters because it shows how “the same controller” is actually changing as the mission geometry changes.
What it means when the filter starts to drift
If the innovation gets large and the covariance ellipse grows, the filter is admitting that its prediction and the measurements are not matching well.
In practical terms, the controller is then making thrust decisions with worse state information. A good-looking control law can still perform badly if the estimate is off.
That is why the lab shows both tracking error and estimation error. Controls and estimation are coupled.
Challenge 1: save the free-return corridor
Start in Free-Return Correction, switch to Coast, and watch the miss distance drift.
Then turn LQR back on and reduce the miss distance below the corridor radius while keeping delta-v low.
The game is not “burn as hard as possible.” It is “burn enough to recover while preserving future options.”
Challenge 2: break the estimator on purpose
Turn on sensor bias and push measurement noise above 2.0x.
Watch the raw fixes wander away from the corridor, then compare how well the Kalman estimate hangs on. Try different controller modes and see when the score collapses.
This is the practical lesson: a controller can only be as smart as the state it believes.
Security model
Everything runs in your browser. No mission state, measurements, or control inputs are sent anywhere. The propagation, Kalman update, and LQR gain computation all run locally in JavaScript on your device.