Localisation & SLAM, step 4
Finding a lost rover with particles
Scatter guesses over the whole maze, move them like the wheels, weigh them against the lidar and resample: the cloud collapses onto the rover.
Builds on Bonus: Probability & Bayes' rule, from the free Foundations.
Write and run this step in the simulator with ProWhen the rover could be anywhere
Switched on somewhere in a maze, the rover could be in any corridor. One Gaussian can't say "here, or there, or over there", but a crowd of guesses can. A particle filter keeps particles: particle is a pose with a weight . It runs the same predict–update loop as your histogram filter.
Predict and update
Predict: move every particle with step 1's sample_motion, so each takes its own noisy version of the trip.
Update: the lidar returns hit points in the rover's frame. Seen from particle , a point lands in the world at
From the right pose every point lands on a wall. The likelihood field wall_distance gives each point's distance to the nearest wall, and
with = SIGMA. Log-likelihoods can be hundreds below zero, and is 0 in floating point, so subtract the largest before exponentiating: it cancels when you normalise.
Resample
Soon most particles carry almost no weight. When the effective number falls below , resample: copy particles in proportion to their weights, then reset every weight to . Low-variance resampling draws one in and lays evenly spaced pointers along the running sum of the weights. Each pointer picks the particle whose slice it lands in.
The program
The rover wanders a maze it knows from an unknown spot, with a lidar that sees 240° ahead. The compass gives the heading, so 10,000 particles start on free floor, all facing that way. Watch the cloud split into a few clusters, then collapse onto the rover.
Your task
Write log_likelihood(particles, points), reweight(weights, loglik), low_variance_resample(particles, weights, r) and estimate(particles, weights), the weighted mean pose. Work on every particle at once with numpy. The grader checks each on fixed cases, then that your estimate stays within 3 cm of the rover from 6 s on.