🔍🔩 Parts bench
19 lessons

Mapping: A Floor Plan from a Spinning Laser

Divide the world into little squares and let every lidar ray vote: the hit cell fills toward 'wall', the path toward it clears toward 'free'. Enough votes and a floor plan emerges.

lesson 2 of 3 in this unit

Builds on: 5.1 Odometry: Navigation by Counting Your Steps2.1 Rangefinders: Distance by Stopwatch

The occupancy grid

A robot’s map is charmingly humble: grid the floor into cells (5 cm squares, say) and store in each a single number — the probability it contains something solid. Grey for unknown, sliding toward white for free and black for occupied. This occupancy grid is the working memory behind nearly every indoor robot you have met.

Every lidar ray is two pieces of evidence in one: the cell where it ended holds something (vote it darker) — and every cell along the way to that hit must have been empty, or the beam would have stopped sooner (vote them all lighter). Rays land by the hundred per revolution; votes pile up; the plan emerges out of grey like a photograph developing.

hit cell → more occupied · ray path → more freethe inverse sensor model — each vote is a nudge, never a verdict, so one noisy ray can’t paint a phantom wall

The map is only as good as the ‘where’

To stamp a ray into the grid you must know where it was fired from — and that pose comes from odometry, which rots. Map with rotten odometry and the rot becomes architecture: one lap around a building and the corridor’s end no longer meets its start; walls smear into double images. A smeared map is almost never a lidar problem — it is a pose problem wearing the map’s clothes.

SLAM, in one honest paragraph

The fix must break a circle: a good map would correct the pose (match this scan against the walls we’ve drawn — localization), but a good pose is needed to draw the walls. Doing both at once is SLAM — simultaneous localization and mapping. The emotional core is the loop closure: the robot re-recognises a place it has seen before, and the accumulated drift snaps audibly to zero as the whole map relaxes into consistency. Odometry whispers, the map corrects — Unit 2’s two-witness pattern, at building scale.

Why robot vacuums drive so strangely

The wall-hugging first lap is deliberate: walls are the richest, straightest lidar evidence, and an early loop closure buys a drift-free skeleton for everything after. The strange dance is the algorithm, visible.

⚗️ Lab — The Developing Map

Steer a lidar-equipped robot through an unknown flat (arrow keys or buttons). The grid develops live; an odometry-drift slider corrupts the pose.

  • Zero drift: drive the flat and watch a crisp plan develop — hits darkening walls, ray paths bleaching floors. Note the grey shadows behind obstacles.
  • Now add drift and re-map: walls double and corridors bend. The lidar never lied — the ‘where’ did.
  • Finish a full loop of the flat and compare where the map’s corridor ends meet. That mismatch is what loop closure exists to snap shut.
0
Coverage
0 % of the flat mapped
Pose honesty
perfect — the map will be crisp
Rule
a smeared map is a pose problem, not a lidar problem

Check your understanding

1. Each cell of an occupancy grid stores…

2. A single lidar ray that hits a wall at 3 m provides evidence about…

3. Your finished map shows doubled walls and a bent corridor. The most likely culprit is…

4. A loop closure is the moment when…