Thrun et al., Chapter 9

Occupancy Grid Mapping

Building maps from sensor data: multi-sensor fusion, inverse measurement models, and MAP occupancy estimation.

Prerequisites: Chapters 2, 4, 6 (Bayes filter, binary Bayes filter, sensor models).
10
Chapters
1
Simulation
10
Quizzes

Chapter 0: Why Mapping?

So far we've assumed the robot has a map. But where do maps come from? Blueprints are rarely accurate — they don't include furniture, open doors, or recent renovations. A truly autonomous robot must build its own map from sensor data.

This chapter tackles a simplified version of the problem: mapping with known poses. We assume the robot knows exactly where it is at all times (perhaps from a very good localization system) and wants to build a map from its sensor readings.

Why this matters: Even though "known poses" is a strong assumption, occupancy grid mapping is enormously useful in practice. Most SLAM algorithms (Chapters 10-14) first estimate the robot path, then use occupancy grid mapping as a post-processing step to generate a clean, navigable map from the estimated poses.

The approach: represent the map as a grid of binary random variables. Each cell is either occupied (wall, furniture) or free (navigable space). The algorithm estimates the posterior probability of occupancy for each cell, given all sensor data collected along the known robot path.

Check: What assumption does occupancy grid mapping make about the robot's pose?

Chapter 1: The Algorithm

The gold standard is the full posterior over the map:

p(m | z1:t, x1:t)

where m is the map, z1:t all measurements, and x1:t the known path. But maps are enormous — tens of thousands of cells. The space of all possible maps is 210,000 or larger. Computing a full posterior is intractable.

The key approximation: factorize the posterior into independent per-cell estimates:

p(m | z1:t, x1:t) ≈ Πi p(mi | z1:t, x1:t)

Each cell mi is estimated independently using the binary Bayes filter from Chapter 4. This ignores dependencies between neighboring cells (e.g., walls are continuous), but makes the problem tractable.

The algorithm is simple: For each cell mi within the sensor cone: update its log-odds using the inverse sensor model. For cells outside the sensor cone: do nothing. That's it. The log-odds representation handles all the Bayesian bookkeeping.
Check: Why does occupancy grid mapping factorize the map posterior?

Chapter 2: Log-Odds Representation

The algorithm maintains a log-odds value for each cell:

lt,i = log p(mi = 1 | z1:t, x1:t) / (1 - p(mi = 1 | z1:t, x1:t))

The update rule is beautifully simple:

lt,i = lt-1,i + inverse_sensor_model(mi, xt, zt) - l0

where l0 = log(p(mi) / (1 - p(mi))) is the prior log-odds (typically 0 for a 50/50 prior).

Log-odds lProbability pMeaning
l << 0p ≈ 0Definitely free
l = 0p = 0.5Unknown (prior)
l >> 0p ≈ 1Definitely occupied
Why log-odds? (1) The update is a simple addition instead of a multiplication — no normalization needed. (2) No numerical instability near 0 or 1. (3) Recovering the probability is easy: p = 1 - 1/(1 + exp(l)). The log-odds representation is the reason occupancy grids are so fast and stable.
Check: What is the log-odds update rule for occupancy grid mapping?

Chapter 3: Inverse Sensor Model

The inverse sensor model p(mi | xt, zt) is "inverse" because it reasons from effects (measurement) to causes (map). Given the robot pose and a range reading, what does this tell us about each grid cell?

For range finders, the model is intuitive:

• Cells before the measured endpoint (range < ztk - α/2): probably free (the beam passed through). Return lfree.

• Cells at the measured endpoint (|range - ztk| < α/2): probably occupied (the beam hit something). Return locc.

• Cells beyond the endpoint or outside the beam cone: unknown. Return l0 (no update).

Parameters α and β: α is the "thickness" of obstacles (how deep behind the endpoint to mark as occupied). β is the beam opening angle. For a laser, β is very narrow (<1°); for sonar, it can be 15-30°. A wider beam means more cells get updated per reading, but with less spatial precision.
Cell LocationReturn ValueInterpretation
In beam, before endpointlfree (< 0)Free space
At beam endpointlocc (> 0)Obstacle
Beyond endpoint / outside beaml0 (= 0)No information
Check: What does the inverse sensor model return for a cell the beam passes through?

Chapter 4: Multi-Sensor Fusion

Robots often have multiple sensor types: lasers, sonars, cameras. How do we combine them into one map?

Approach 1: Naive Bayes fusion. Run the occupancy grid algorithm with all sensors, updating the same log-odds grid. Problem: if sensor A sees an obstacle (a thin pole) but sensor B doesn't (sonar bounces off it), they produce conflicting evidence. The result depends on which sensor fires more often — not ideal.

Approach 2: Conservative fusion (recommended). Build a separate map for each sensor type. Combine them by taking the maximum occupancy:

mi = maxk mik

If any sensor thinks a cell is occupied, the combined map marks it occupied. This is pessimistic (biased toward obstacles) but safe for navigation.

Why conservative fusion wins: Different sensors detect different obstacles. A laser sees glass walls that sonar misses. Sonar detects soft furniture that laser passes through. The max operator ensures no obstacle is overlooked, which is exactly what a path planner needs.
Check: What is the recommended approach for combining maps from different sensor types?

Chapter 5: Learning Inverse Models

The hand-crafted inverse sensor model (Chapter 3) is simple but crude. Can we learn a better one from data?

The challenge: Bayes rule gives us the ideal inverse model:

p(mi | x, z) = η ∫ p(z | x, m) p(m) dm

But this integral is over all possible maps — intractable. We need to marginalize over all maps that agree with a given cell value mi.

The learning approach: Generate training data by sampling random maps, simulating sensor readings (forward model), and recording the (pose, measurement, cell occupancy) tuples. Then train a function approximator (logistic regression, neural network) to predict occupancy from pose and measurement.

Practical impact: Learned inverse models produce smoother, more accurate maps than hand-crafted ones. They can capture subtle sensor characteristics that are hard to model analytically, like sonar multi-path reflections or the reflectance properties of different materials.

However, the hand-crafted model works surprisingly well for laser range finders (which are clean and well-behaved). Learning is most valuable for noisy sensors like sonar or cameras.

Check: How can an inverse sensor model be learned from data?

Chapter 6: MAP Occupancy

The standard occupancy grid makes a strong independence assumption: each cell is estimated independently. This ignores spatial correlations — walls are lines, not random scattered points.

Maximum A Posteriori (MAP) occupancy mapping tries to find the single map that maximizes the full joint posterior:

m* = argmaxm p(m | z1:t, x1:t)

This is the mode of the full posterior, not the product of per-cell modes.

Why the factored approach can fail: Consider two adjacent cells behind a thin wall. One beam hits cell A (evidence: occupied). Another passes between cells (no evidence for either). The factored approach might make A occupied and B free, even though walls don't have gaps. The MAP approach can maintain correlations, producing more coherent maps.

In practice, MAP occupancy mapping is rarely used. The factored approach is fast, simple, and produces maps that are good enough for navigation. MAP methods are important theoretically, showing what we lose through independence assumptions.

Check: What does MAP occupancy mapping maximize?

Chapter 7: Forward Models

An alternative to inverse sensor models: use forward models directly. The forward model p(z | x, m) is the physics-based model we already know from Chapter 6 — beam models, likelihood fields, etc.

Forward models have a clear advantage: they model the actual physics of sensing. They capture occlusion (cell B is hidden behind cell A), cross-cell dependencies, and sensor-specific effects naturally.

The challenge: forward models map from map to measurement, but we need to update the map given a measurement. This requires iterative optimization or sampling — much more expensive than the simple additive log-odds update.

When to use forward models: When the environment has thin structures, occlusions, or complex sensor characteristics that the inverse model cannot capture. For most applications with laser scanners in indoor environments, the inverse model is sufficient and much faster.
ApproachProsCons
Inverse modelFast (additive), simpleIgnores inter-cell dependencies
Forward modelPhysically correct, handles occlusionSlow (iterative), complex
Check: What advantage do forward sensor models have over inverse models for mapping?

Chapter 8: Grid Map Demo

Watch an occupancy grid being built. The robot moves through a simple room, firing range beams. Cells in the beam path turn white (free); cells at beam endpoints turn black (occupied).

Occupancy Grid Mapping

The robot (orange dot) casts beams into the environment. Free cells lighten, occupied cells darken. Click Step to advance the robot and update the map.

Ready. Click Step to begin mapping.
What to notice: After a few steps, the walls of the room emerge clearly as dark cells, while the interior is bright white. The grey background represents unknown cells (log-odds = 0). The map quickly converges because each beam provides evidence for many cells simultaneously.
Check: What does a grey cell (log-odds = 0) in an occupancy grid represent?

Chapter 9: Summary

ConceptKey Idea
Occupancy gridMap as a grid of binary occupancy values, estimated independently per cell
Log-oddsAdditive updates, numerically stable, fast
Inverse sensor modelp(mi | x, z): free before endpoint, occupied at endpoint
Multi-sensor fusionSeparate maps per sensor, combine with max
MAP occupancyMaximize full joint posterior; theoretically better but expensive

Occupancy grid mapping is one of the most successful algorithms in robotics. It is fast, robust, and produces maps that are immediately useful for path planning and navigation. The log-odds representation makes updates trivial, and the algorithm handles noisy sensors gracefully.

What comes next: We assumed known poses. But in reality, the robot doesn't know its pose perfectly. The next chapters tackle the full SLAM problem: building the map and localizing simultaneously. Chapter 10 introduces EKF SLAM, the first and perhaps most influential SLAM algorithm.
"Every beam that passes through a cell
whispers 'free.'
Every beam that stops at a cell
shouts 'occupied.'"
Check: What is the main practical use of occupancy grid mapping?