Mapping Is Localization Turned Inside Out
In the last guide we asked: given a map, where am I? That is localization. Now we flip the question around. Suppose you already know your pose — your exact position and heading at every moment. What can you learn about the world from what your sensors see? That flipped question is robot mapping, and it is the mirror image of localization: instead of using a known map to find your pose, you use a known pose to build the map.
Picture a robot rolling down a hallway with a spinning laser scanner. Each scan tells it: in this direction, the nearest wall is 3.2 metres away; in that direction, 1.8 metres. If the robot knows where it is standing and which way it is facing, every one of those readings points to a real spot in the room. The whole job of mapping is to collect millions of such pointed-at spots and organise them into something a robot can actually use later.
Slicing the World Into Cells
The most popular way to store a map is the occupancy grid map. The idea is wonderfully simple: lay a checkerboard over the floor and chop the world into small square cells — often 5 cm or 10 cm on a side. Each cell holds one number: the probability that something solid sits there. A value near 1 means "almost certainly occupied," near 0 means "almost certainly free," and around 0.5 means "I honestly have no idea."
Those three states — free, occupied, unknown — are exactly what a robot needs to move safely. Free cells are where it can drive. Occupied cells are walls, furniture, and people to avoid. Unknown cells are the frontier: places it has not looked yet, which is precisely where an explorer should head next. Notice the grid never stores "this is a chair" or "this is a doorway"; it only stores how full each little square is. That plainness is its strength.
There is a quiet trade-off baked into the cell size. Tiny cells capture fine detail — a thin table leg, a narrow gap — but a room then needs millions of them, eating memory and slowing every lookup. Big cells are cheap and fast but blur small obstacles into solid blocks. Choosing a cell size is really choosing how much detail you are willing to pay for.
Letting Scans Vote, One Reading at a Time
A single laser or depth reading is never to be fully trusted. LiDAR and depth cameras both suffer sensor noise: a beam might clip a dust mote, glance off glass, or report a distance a few centimetres too long. So instead of letting one reading set a cell in stone, the occupancy grid lets every reading cast a small vote, and the cell believes the crowd, not any single voter.
Here is the trick that makes one beam informative. A range reading tells you two things at once. The spot where the beam stops is probably occupied — something blocked it. But the whole stretch of empty air the beam travelled through to get there must have been free, or it would have stopped sooner. So a single ray nudges one cell toward "occupied" and a line of cells behind it toward "free." This is sometimes called inverse sensor modelling: reading the world backwards from the sensor's report.
- Take one range reading and use the robot's known pose to figure out where in the grid the beam started and where it ended.
- Walk along the line of cells from start to endpoint and nudge each one a little toward "free" — the beam passed through, so they were empty.
- At the cell where the beam stopped, nudge it toward "occupied" — something was there to reflect the beam.
- Repeat for every beam in the scan, and for every scan as the robot moves. Confident cells settle near 0 or 1; flickering, doubtful cells hover near 0.5.
This voting habit is what lets the map shrug off noise. A spurious reflection that paints one cell as occupied gets outvoted the next ten times the beam passes cleanly through. And the grid quietly handles change too: when a person who was standing in a doorway walks away, fresh "free" votes slowly erase them. The map breathes with the room.
When a Grid Is Overkill
An occupancy grid is a dense, metric map: it pins down real-world distances and fills in every square of the floor, whether or not anything interesting is there. That makes it perfect for a vacuum robot weaving around chair legs, but wasteful for a robot crossing a vast empty warehouse — most of those millions of cells just say "free, free, free."
A lighter alternative is the landmark or feature map. Instead of every cell, it remembers only a sparse set of distinctive points — a pillar here, a corner there, a bright sign over the loading dock — and their coordinates. It is far cheaper to store and quick to match against, though it tells you nothing about the blank space between landmarks, so it is less directly useful for steering around clutter.
Lighter still is a topological map, which throws away precise distances altogether and keeps only a graph of places and how they connect: "the lobby links to corridor A, which links to the lab." It is the difference between a scale floor plan and a subway diagram. The contrast between these styles — exact and dense versus sparse and connective — is the heart of metric vs topological maps, and choosing between them is one of the first design calls a robot builder makes.