Monte Carlo localization with a lidar
A robot drives through a known floor plan without knowing where it started. Monte Carlo localization tracks its pose with a cloud of particles, each one a guess of the pose, which begins spread over every free part of the map.
Algorithm
Every step:
Move every particle with the noisy odometry.
Weight every particle by how well the lidar scan, placed at its pose, lines up with the walls. The likelihood field scores each beam by the distance \(d_k\) from its endpoint to the nearest wall, read from a distance map computed once:
Resample: particles that explain the scan are copied, the others disappear.
Augmented MCL: keep a fast and a slow average of the scan likelihood, and replace particles by random poses with probability \(\max(0, 1 - w_\text{fast}/w_\text{slow})\), so that a cloud that settled on the wrong place can still find the right one.
Code Link
- Localization.monte_carlo_localization.monte_carlo_localization.log_likelihoods(particles: ndarray, ranges: ndarray, distances: ndarray) ndarray
Log likelihood (N,) of the scan for each particle (N, 3), from the distance between each beam endpoint and the nearest wall.
Standalone project and report
This algorithm is also published as a standalone project, robofan45/monte-carlo-localization, with an installable package, tests that run on Linux, macOS and Windows, and an IEEE-style technical report (PDF) with measurements and a full bibliography.
Reference
S. Thrun, W. Burgard and D. Fox, “Probabilistic Robotics”, MIT Press, 2005
F. Dellaert, D. Fox, W. Burgard and S. Thrun, “Monte Carlo Localization for Mobile Robots”, ICRA, 1999