Grid-based SLAM (RBPF)
Rao-Blackwellized particle filter for SLAM with occupancy grids.
Questions
- Can we solve the SLAM problem with no pre-defined landmarks?
- Are landmarks useful to autonomous robots beyond localization?
- Can we use the ideas of FastSLAM to build occupancy maps?
Reminder — factorization of the SLAM posterior (Rao-Blackwellization):
where is the path posterior and is the map posterior.
Grid-based mapping with known poses
- As with landmarks, the map depends on the poses during data acquisition.
- If the poses are known, grid-based mapping is easy ("mapping with known poses").
If we use poses from raw odometry in the Pygame demo of the previous lesson, the result is poor. Increase the motion noise and the odometry-only map becomes unreadable — the trajectory drifts, walls don't line up, and the cells get smeared. Setting motion noise to 0 gives the perfect map, but that's cheating; real odometry is noisy. We need better pose estimates.
Grid-based mapping with RBPFs
- Each particle represents a possible trajectory of the robot.
- Each particle maintains its own map.
- Each particle updates it via "mapping with known poses".
Problem.
- To get good poses from the particle filter for mapping with "known poses", we need a large number of particles to sufficiently model the motion noise.
- Increasing the number of samples is difficult — each map grows large.
Idea. Improve the pose estimate before applying the particle filter.
Pose correction using scan matching
Maximize the likelihood of the current pose relative to the previous pose and the map built so far:
where is the current measurement, the robot motion, and the map constructed so far.
Note. Often the map used is a submap consisting of the last 10–20 scans.
In a pygame example you'd reduce odometry drift before updating the occupancy grid by aligning the current scan to the current map.
Inputs
- Predicted (odometry) pose:
- Occupancy grid (log-odds) and probabilities
- Scan in the robot frame
Scoring (MAP objective near odometry)
For a candidate pose around :
- Transform beam endpoints to world:
- Correlate with the current map. Discretize to grid cells and accumulate, where is the cell size: where keeps only in-bounds endpoints. This correlation is an agreement score between the scan and the map, if displaced by the candidate pose.
- Add a Gaussian motion prior:
Pose estimate. Pick in a small neighbourhood of .
Search strategy (discrete correlative)
- Coarse → fine window over around .
- Beam subsampling (e.g. every 2nd–4th beam) for speed.
- Optionally ignore max-range beams in the score (limited alignment information).
Pose update and mapping
- Blend odometry with the matched pose, or snap it: .
- Mapping with (better) known pose — integrate the same scan into the grid via the inverse sensor model using .
Grid-based FastSLAM with improved odometry
The first idea was to use scan matching to pre-correct the odometry estimates.
If we try to plug this into FastSLAM directly, a slight problem arises mathematically. The original FastSLAM uses the motion model for proposing poses and the observation model only for weighting. If we use the observation in the proposal distribution, the weight derivation no longer holds.
Note. Mathematically not quite right, but in practice it gives better results than raw odometry.
A better idea was proposed by Hähnel et al. (2003): scan-match in small sequences and feed the corrected sequences into FastSLAM to stitch them together.
- Pre-correct short odometry sequences using scan matching.
- Scan matching provides locally consistent pose correction.
- Fewer particles are needed since the input error is smaller.
But this is still an ad-hoc solution to an improved proposal distribution.
Can we do better? Yes — move to FastSLAM 2.0 with an improved proposal, derived for the grid-based approach.
Goal:
- More precise sampling.
- More accurate maps.
- Fewer particles needed.
The optimal proposal distribution
If we know the map so far from particle , and we know the current controls and current observation, we can estimate where we'll end up:
After applying Bayes' rule we see familiar terms — observation model and motion estimate on top.
To build an efficient algorithm we look at the expected shape of these terms. The observation model is typically much more tightly peaked than the motion model (which accumulates drift from slip, tyre pressure, etc.). Key assumption:
For laser rangefinders, is typically peaked and dominates the product in Eq. (1).
The denominator is the integral:
— the same product as the numerator. Rewriting:
We have a product where one term dominates the other:
- (measurement) locally limits the integration region.
- (odometry) globally limits the integration region.
We approximate by integrating only in the restricted area defined by the dominating term — so the proposal looks like:
A few issues:
- No closed form to sample from.
- We want it Gaussian for efficient sampling and weight computation.
So we approximate Eq. (3) by a Gaussian:
Steps:
- Take the maximum reported by scan matching.
- Sample locally around that maximum.
- Fit a Gaussian.
The per-particle mean and covariance:
where are points sampled around the point that scan matching converged to. This Gaussian can now be used as the proposal in the particle filter.
Computing the importance weight
Same derivation as before; applying Eq. (2):
where are points sampled around the scan-matching maximum.
Resampling
Resampling at every step limits the "memory" of the filter — losing ~25 % of particles per step destroys diversity over time.
Goal: reduce resampling actions.
Selective resampling
Resampling is necessary for convergence but dangerous — important samples can get lost (particle depletion). Resampling is only useful if weights differ significantly.
Key question: when to resample?
The number of effective particles measures how well the target is approximated by samples from the proposal:
- is the inverse variance of the normalized particle weights.
- For equal weights, the approximation is close to the target.
- If our approximation is close to the target, no resampling is needed.
- Resample only when drops below a threshold (typically ).
Note. Weights must be normalized when computing .
Grid-based FastSLAM — quick recap
- A Rao-Blackwellized particle filter where each particle carries a robot pose and its own occupancy grid (log-odds). No per-landmark EKFs — the map is a grid of Bernoulli cells.
- Laser measurements produce a sharp likelihood around the true pose. We exploit this by scan-matching each particle's scan to its own map.
- Core loop (per particle):
- Predict pose from odometry.
- Scan-match the current scan to the particle's grid; build a Gaussian proposal around the matched pose.
- Sample the new pose from that proposal and update the particle's weight with the measurement likelihood.
- Update the grid with the inverse sensor model — cells along each beam become free, the endpoint (if any) becomes occupied (via log-odds increments).
- Selective resampling based on effective sample size.
- Each grid cell is a Bernoulli updated in log-odds; scan matching provides the informative update in pose space.
- A better proposal reduces the number of particles needed, mitigates drift, and improves map consistency in laser-friendly environments.
- Use a likelihood field or correlation map for fast scan scores; subsample beams; clamp log-odds; treat max-range returns as free-space only; perform the endpoint-occupied update outside the inner free-space ray loop.
- Memory / compute scale with one map per particle; weak structure or dynamic scenes can degrade scan-matching; poor initial guesses can cause local-minimum failures.
Grid-based FastSLAM algorithm
- for k = 1..N:# loop particles
- let ⟨x_{t-1}^{[k]}, m_{t-1}^{[k]}, w_{t-1}^{[k]}⟩ be particle k# unpack
- x̄_t^{[k]} ~ p(x_t | x_{t-1}^{[k]}, u_t)# odometry prediction
- x⋆ = ScanMatch(start = x̄_t^{[k]}, map = m_{t-1}^{[k]}, scan = z_t)# scan match
- generate K local samples {x_j} around x⋆# local samples
- for each x_j: τ_j = p(z_t | x_j, m_{t-1}^{[k]}) · p(x_j | x_{t-1}^{[k]}, u_t)# τ = likelihood × motion
- η = Σ τ_j# normalizer
- μ^{[k]} = (1/η) Σ x_j · τ_j# proposal mean
- Σ^{[k]} = (1/η) Σ (x_j − μ^{[k]})(x_j − μ^{[k]})ᵀ · τ_j# proposal covariance
- x_t^{[k]} ~ N(μ^{[k]}, Σ^{[k]})# sample new pose
- w^{[k]} = w_{t-1}^{[k]} · Σ τ_j# importance weight
- for each beam b in z_t: along ray mark free cells, mark endpoint occupied# grid update (inverse sensor model)
- m_t^{[k]} = updated log-odds# save grid
- normalize {w^{[k]}}# normalize weights
- N_eff = 1 / Σ ŵ^{[k]}²# ESS
- if N_eff < N_thresh: X_t = Resample(⟨x_t^{[k]}, m_t^{[k]}, w^{[k]}⟩_k)# selective resample
- else: X_t = {⟨x_t^{[k]}, m_t^{[k]}, w^{[k]}⟩}# else keep
- return X_t

The full Python implementation is in notebooks/2_particle_filters/4_grid_based_slam.ipynb.
Summary
- An approach to SLAM that combines scan matching and FastSLAM.
- Scan matching generates virtual "high-quality" motion estimates.
- Can be viewed as an ad-hoc solution to an improved proposal distribution.
- The idea of FastSLAM applies in the grid-map context as well.
- Improved proposals are essential.
- Similar to scan matching on a per-particle basis.
- Selective resampling reduces the risk of particle depletion.
- Substantially fewer particles required.
Reading material
Grid-FastSLAM with improved proposals
- Grisetti et al. Improved Techniques for Grid Mapping with Rao-Blackwellized Particle Filters, 2007.
- Stachniss et al. Analyzing Gaussian Proposal Distributions for Mapping, 2007.
Grid-FastSLAM & scan matching
- Hähnel et al. An Efficient FastSLAM Algorithm for Generating Maps of Large-Scale Cyclic Environments from Raw Laser Range Measurements, 2003.