Lesson reading
live
1 hr
Start with the lesson question, connect the representations, and test the model with evidence.
Inspect the opening phenomenon
Predict what changes, then name the evidence.
Apply in the lab
Name the evidence before reading the answer.
Read only what helps
Then use the lab and recall check.
More when needed
Transcript and resources stay available below.
Course progress
Maps, Occupancy Grids, and SLAM
Decision challenge
Use the opening example to make a prediction, identify evidence, and explain which model supports it.
SLAM loop closure corrects a broken map only after geometric verification adds a defensible pose-graph constraint.
SLAM loop closure corrects a broken map only after geometric verification adds a defensible pose-graph constraint.
Lesson reading
live
1 hr
Video script
draft
Transcript fallback
available
courses/ai-robotics/modules/07-localization-mapping-and-navigation/lessons/02-maps-occupancy-grids-and-slam/video-transcript.md
Make Drift Visible, Then Close the Loop
published
30 min
Mastery check
live
5 questions / 10 min
# Video transcript The robot returned home, but its map says the start moved. Follow one scan to learn why. Lidar marks crossed cells free and its endpoint occupied. Unobserved cells remain unknown. A scan has no map position alone. The estimated pose transforms it into map cells. Wheel slip creates small pose errors. As the robot travels, odometry drift accumulates. The scan can be correct, yet a wrong pose places walls in the wrong cells. Recognizing a visited place proposes a loop closure: two poses may be one location. Geometry must agree. Verification rejects mirrored or inconsistent rooms before they corrupt the map. A verified loop constrains the pose graph. Optimization redistributes error across the earlier trajectory. Now the path closes and the map agrees. Why can a correct scan still map a wall incorrectly? ## Non-video equivalent An occupancy grid stores sensor evidence as unknown, free, or occupied cells. A measurement does not identify its own map location; SLAM places it using the robot's estimated pose. Odometry error can therefore insert correct measurements into incorrect cells. A geometrically verified revisit establishes a loop-closure constraint. Pose-graph optimization distributes the accumulated error across earlier poses, producing a more consistent trajectory and map. ### Annotated-keyframe reading order 1. **Occupancy evidence:** follow the lidar ray from the robot through free cells to its occupied endpoint; cells outside the observation remain unknown. 2. **Pose drift:** compare the fixed green physical wall with the amber wall placement. Their separation represents pose error, not a different range measurement. 3. **Loop correction:** compare the open amber trajectory with the closed green trajectory. The correction affects connected earlier poses, so their associated scan placements change too.
Reading lab
Connect the lesson's words, diagrams, graphs, evidence, and equations.
It is a structured estimate. A two-dimensional occupancy grid divides space into cells and records what the mapping system currently believes about each cell. Unknown means the robot lacks sufficient evidence; it is not the same as free space. Free means sensor evidence supports traversal under the sensor model. Occupied means evidence supports an obstacle at that resolution.
The map metadata defines resolution, width, height, and origin. For zero-based integer cell coordinates (x, y) in a width-W row-major grid:
index = x + yW
For a world point (X, Y), axis-aligned grid origin (X₀, Y₀), and resolution r meters per cell:
x = floor((X - X₀) / r) and y = floor((Y - Y₀) / r)
Always check bounds and the map origin's pose before indexing. A rotated origin requires a frame transform, not only subtraction.
A laser scan does not arrive already placed in the map. The system transforms each beam from the sensor frame through the robot pose into the map frame. If the pose is wrong, walls smear, duplicate, or bend. But the map is also used to correct the pose. This mutual dependence is the core SLAM problem: estimate the trajectory and map together.
A pose graph stores robot poses as nodes and relative-motion or scan-matching constraints as edges. When the robot recognizes a previously visited place, a loop-closure constraint says that two distant points in the estimated trajectory represent the same physical neighborhood. Optimization distributes the correction across the graph. Earlier poses can move, so the occupancy grid rendered from their scans changes too.
Loop closure is evidence, not magic. A false match can deform a good map. Systems therefore need similarity checks, geometric verification, robust loss functions, and post-optimization residual monitoring.
A cell is -1 and lies directly ahead of the robot. Is it safe to treat it as free? What evidence and policy would you require before planning through it?
A lidar scan accurately measures a wall, yet the wall appears twice in the map. Which estimate should you inspect first, and why? Start with the robot pose associated with each scan: correct range data transformed through inconsistent poses will be inserted into different map cells.
An occupancy grid is an uncertainty-aware spatial representation with explicit geometry and indexing. SLAM places sensor evidence by estimating the robot trajectory at the same time. Loop closure can correct accumulated drift by adding a revisited-place constraint, but only when the match is valid.
Build a small occupancy grid from simulated range observations and compare the map before and after a loop-closure correction.
pose-scan-placement-table.csvUse graph paper or a spreadsheet with a 12×12 grid. Mark cells as ? unknown, . observed free, or # likely occupied. The simulated room is rectangular; the robot follows a loop and returns near its start.
(0, 0).(2.2 m, 3.1 m) to a cell. Record (x, y) and row-major index for width 12.2.0 m at bearing 0°. First associate it with pose A (1.0 m, 1.0 m, 0°); then associate the identical scan with drifted pose A′ (1.5 m, 1.0 m, 0°). Mark each endpoint in the grid.(4, 6) and index 76 for the worked conversion.(3.0 m, 1.0 m) / cell (6, 2) to world (3.5 m, 1.0 m) / cell (7, 2) even though range and bearing are unchanged.Record each transformation in assets/pose-scan-placement-table.csv. Preserve the original estimate and corrected estimate as separate rows rather than overwriting the drifted result. A complete submission includes the table, a before/after grid, and a two-sentence causal explanation.
x + y × width, not y + x × height.0.5 m, exactly one grid cell at this resolution.Complete the same activity as a text table listing pose ID, estimated coordinates, observed cells, constraint, and corrected coordinates. No color distinction is required.
What additional evidence would you inspect before accepting a loop closure on a real robot?
Why is a visually cleaner map after optimization not, by itself, proof that the corrected map is metrically accurate?
Repeat the same-scan test with a 10-degree heading error instead of a position offset. Compare the displaced endpoints, explain why the error grows with range, and state what geometric evidence would be needed before accepting a correcting loop constraint.