Localisation & SLAM, step 3
An EKF with beacons
Track the rover with one Gaussian: predict with the wheels, correct with each beacon it sees, and watch the uncertainty ellipse breathe.
Builds on Combining two sensors and Angles, atan2 & 2-D rotation, from the free Foundations.
Write and run this step in the simulator with ProOne Gaussian instead of many cells
In 2-D, with a heading, a histogram would need millions of cells. When you roughly know where you are, a Gaussian is enough: a best guess and a 3×3 covariance saying how unsure it is. The extended Kalman filter (EKF) keeps both up to date.
Predict with the wheels
Move with step 1's move. The old uncertainty is carried along and the increment's own noise, with covariance , adds to it:
and are the Jacobians of the motion : its partial derivatives. With ,
and 's two columns are the derivatives of by and by . Remember that depends on .
Correct with a beacon
A beacon at reads a range and a bearing. With and , the reading you expect and its Jacobian are
The innovation is the surprise (wrap its bearing). The gain decides how much of it to believe, given the reading's noise covariance :
A large trusts the beacon; a small one trusts the prediction. Noisy Sensors & Kalman Filters builds this update in one dimension.
The program
The rover laps a room with four beacons but only sees those within 25 cm (blue circles). Your estimate is orange, raw odometry grey, and every half second your 2σ ellipse is drawn, five times bigger. It grows while no beacon is in sight and shrinks at each sighting.
Your task
Write motion_jacobians(x, u) → (F, G), ekf_predict(x, P, u, Q) → (x, P), observe(x, b) → (h, H) and ekf_update(x, P, z, b, R) → (x, P), wrapping every angle. The grader checks each on fixed cases, then your estimate and your ellipse against the rover's true path.