TL;DR:
SLAM (simultaneous localization and mapping) builds a map of an unknown place while tracking the robot's position in it.
The two problems depend on each other: a good map needs a good pose, and a good pose needs a good map.
A front end turns sensor data into constraints, and a back end adjusts the whole trajectory and map to fit them best.
Carry a robot into an apartment it has never seen and switch it on. It has no map, so it cannot say where it is. It could build a map, but to place each wall correctly it needs to know where it was when it saw it. This chicken-and-egg problem is what SLAM solves.
The two problems that depend on each other
Localization finds the robot's pose on a map (see localization). Mapping builds the map from sensor readings taken at known poses (see occupancy grid maps). Each one is easy if you are given the other. SLAM, simultaneous localization and mapping, is the case where you are given neither, only a stream of sensor data and the robot's own motion.
Worked example: a robot exploring a new apartment
Take a robot with a lidar and wheel odometry that starts in the hallway.
First scan. The robot sees the hallway walls. It declares its starting pose to be the origin and draws the walls relative to it. The map has a few meters of wall.
It moves 2 m into the living room. Odometry says it moved 2.0 m, but wheel slip means it might have moved 1.95 m or 2.04 m. A new scan shows walls, and many of them are the same walls seen from a new angle.
Scan matching. The robot shifts and rotates the new scan until it overlays the old one as well as possible. If the walls line up best after a shift of 1.97 m, that is a better estimate of the motion than odometry alone, and it corrects the pose. The new scan then adds the living room to the map.
Repeat. Each step adds a new bit of map and a new pose, corrected by comparison with what was seen before.
Drift. Each correction is a little imperfect. Suppose the pose error grows by 2 cm per meter driven (an example figure). After a tour of 40 m through the apartment, the position error could be
40 × 0.02 = 0.8 m. The robot returns to the hallway and finds that the hallway wall it mapped at the start appears 0.8 m away from where it expects it, so the map looks like two hallways.Loop closure. When the robot recognizes that it is back in the hallway, it adds a constraint: this pose is the same place as the first one. The whole trajectory is then adjusted to satisfy it, and the double hallway merges into one. That step is the subject of loop closure.
The map improves the pose, and the pose improves the map. Neither is known in advance.
Front end and back end
Most modern SLAM systems split the work into two parts.
The front end deals with the raw sensor data. It matches scans or camera features between times, estimates the motion between two moments (a relative pose), and notices when the robot may have come back to a place it has seen. Its output is a set of constraints: "pose 7 is 1.97 m ahead of pose 6," "pose 40 is at the same place as pose 1."
The back end takes all those constraints and finds the set of poses (and map) that best fits them all together. Each constraint is uncertain, so the back end weighs them by their confidence and solves a large least-squares problem. The usual picture is a pose graph: nodes are poses, edges are constraints. The back end moves the nodes until the edges are as relaxed as possible, like a network of springs.
An older family of methods did this recursively with a Kalman-type filter (see the Kalman filter), keeping the robot and landmark estimates and their correlations. Graph-based methods are more common now because they can revisit and adjust the entire history.
Different sensors, same idea
SLAM works with a lidar, a camera, a depth camera, or wheel and inertial data. A camera version tracks visual features such as corners across frames. The details differ, but the front end and back end structure remains.
Where it goes wrong
Featureless places. A long plain corridor looks the same everywhere, so scan matching cannot tell how far the robot moved along it.
Moving things. People and doors that open break the assumption that the world is still.
False loop closures. Two similar rooms can be mistaken for the same one. A wrong constraint can fold the whole map. Good systems check candidates carefully.
Fast motion. Blurred or sparse data from a fast robot gives poor matches.
Computation. Large maps need efficient methods. Real systems limit what they keep or only optimize recent parts often.
Not a plan. SLAM gives the robot a map and a pose. It does not decide where to go.
Safety: Do not put your face near an operating lidar or open the unit, because its laser can harm eyes if the housing is broken or modified. While the robot explores a place it has never seen, keep speed low, keep a hardware emergency stop, and keep an independent obstacle sensor active, since a map built a few seconds ago may not match reality.
How real robots use it
Robot vacuums, warehouse robots, and research vehicles use SLAM to enter a new space and work in it without a pre-made map. Some systems run SLAM once to build a map, then save it and only localize afterward. The glossary entry on SLAM gives the short definition.
Try it yourself
With a pencil and tracing paper, draw a floor plan from your own position. Walk a loop through three rooms and sketch each room as you go from your own step counts, without looking back at earlier sketches. When you return, compare your first room with your last sketch of it. The mismatch is the drift, and fixing it by fitting all the sketches together is what the back end does.
Frequently asked questions
Why not just use GPS?
GPS does not work well indoors, and its accuracy is not enough for tight spaces. SLAM works from the robot's own sensors in any place.
Is SLAM one algorithm?
No. It is a problem, with many solutions that use different sensors and methods. Most share a front end that makes constraints and a back end that optimizes them.
