Autonomous Systems ★★★★☆ Advanced

🧭 SLAM: Simultaneous Localization and Mapping

A robot explores a hidden maze it has never seen. A real Monte Carlo particle filter localizes it from noisy lidar-like range readings and noisy odometry, while a Bayesian log-odds occupancy grid builds the map live — genuinely computed each step, not pre-drawn.

Drag to orbit · Scroll to zoom · WASD/Arrows to drive manually when Manual control is on

Localization error
Particle spread
Map coverage
0%
SLAM phase
Bootstrapping
Steps
0
Particles
200
0.15
0.12
200
1.0

How to read this simulation

Green arrow — the true robot (hidden from the algorithm, shown for teaching purposes). Orange marks — particle filter hypotheses; brighter means higher weight. Grey/white cells — the occupancy grid the robot has built from its own noisy sensor data: dark cells are believed free, bright cells are believed occupied, and mid-grey cells are still unknown. Toggle "Show true maze" to compare the built map against the hidden ground truth.

The Particle-Filter SLAM Loop

Predict — every particle's pose is advanced using the same noisy odometry reading the real robot reports, plus extra per-particle motion noise, so the cloud spreads to represent uncertainty.

Weight — each particle casts simulated sensor rays against the occupancy grid built so far from its own hypothesis pose, and is weighted by how closely those predicted ranges match the real robot's actual noisy lidar readings.

Resample — particles are redrawn proportional to weight (systematic resampling), so likely poses multiply and unlikely ones vanish, concentrating the cloud around the true pose over time.

Map — the weighted-mean pose estimate (not the hidden ground truth) is used to trace every sensor ray through the occupancy grid, accumulating Bayesian log-odds evidence for free and occupied cells — this is why the map only sharpens once localization has converged.

🧭 SLAM: Simultaneous Localization and Mapping

About this simulation

A robot wanders a hidden maze using only noisy motion estimates and a noisy lidar-like sensor. A particle filter (Monte Carlo localization) tracks hundreds of hypothesis poses that predict, weight and resample every step, while a Bayesian occupancy grid builds the map from ray-traced sensor hits and misses. Real SLAM stacks on cars, drones and vacuum robots use the same core loop.

How it works

Key equations

w_i ∝ exp(-Σ(z_pred,i − z_obs)² / 2σ²) — particle weight from squared sensor-prediction error, and l_t = l_t-1 + log[p(z|occ)/p(z|free)] — the log-odds occupancy update applied along every ray-traced cell.

Controls

Did you know?

SLAM is sometimes called robotics' "chicken-and-egg problem": accurate localization needs a good map, and a good map needs accurate localization. Every SLAM algorithm — this particle filter included — solves both at once instead of one after the other.