30% off your first 3 months

Get the deal

Loop closure: how SLAM fixes drift

by DuckyHelperNov 12, 20265 min read
Robotics

TL;DR:

  • Loop closure notices that the robot is back at a place it has already mapped, and adds a constraint that ties the two poses together.

  • The back end then spreads the correction over the whole trajectory, so the error is fixed everywhere, not only at the end.

  • A false loop closure is worse than none, so systems check candidates with care.

A robot drives around a square building and comes back to the door it started from. On its map, though, the door appears 0.8 m away from the one it began with. The robot has drawn the same door twice. Nothing is wrong with the sensors: small errors added up along the way. Loop closure is what lets the robot say, "This is the same door," and fix the whole drawing.

What drift looks like

Every step of motion estimation has a small error (see odometry and why its errors add up). Scan matching reduces it, but not to zero. Over a long trip the errors accumulate, and the estimated path slowly separates from the true one. On a map, this shows up as a loop that does not close, walls that appear twice, or a corridor that bends when it should be straight.

Recognizing a place

Loop closure has two parts. First, detection: working out that the current surroundings match a place seen earlier. The robot might compare the current lidar scan with stored scans from poses that are near its estimated position, or compare camera images by looking for the same visual features, or a compact "fingerprint" of each place. It proposes a candidate and checks it by trying to align the two views.

Second, correction: once the match is accepted, the system has a new constraint, "the current pose is at the same location as pose number 1, give or take a small error." Then the back end adjusts all the poses in between.

Worked example: returning to the starting room

The robot drives a 40 m loop and records a pose every 1 m, so there are poses numbered 0 to 40. Pose 0 is the start. Because of drift of a steady 2 cm per meter (an example), the robot's estimate of pose 40 is wrong by 40 × 0.02 = 0.8 m along the direction of the drift.

At pose 40 the robot recognizes the start room. Scan matching says: the true pose 40 is at the same place as pose 0. But the estimate puts it 0.8 m off. The loop closure error is 0.8 m.

A simple way to picture the correction is to spread it evenly along the trajectory, in proportion to how far along each pose is. Pose k is shifted by (k / 40) × 0.8 m = 0.02 k meters, back along the drift:

  • Pose 10: shifted by 0.02 × 10 = 0.2 m.

  • Pose 20: shifted by 0.4 m.

  • Pose 30: shifted by 0.6 m.

  • Pose 40: shifted by 0.8 m, so it now sits on pose 0, and the loop is closed.

  • Pose 0: not shifted.

Check: shift grows linearly from 0 to 0.8 m, matching the way the drift grew, so the corrected path is close to the truth. Every wall seen by the robot at those poses moves with its pose, and the double wall merges into one.

Real systems do not simply spread the error. They build a pose graph (see SLAM explained) in which every relative motion and the loop closure is a constraint with an uncertainty, and a least-squares solver finds the poses that disagree with the constraints as little as possible. If the drift was larger in one part of the trip, the solver can put more of the correction there. The linear spread is the intuition, and the solver is the real method.

Why it fixes more than the end

After the correction the map is better everywhere, not only at the closing point, because the whole chain of poses is adjusted. This is why loop closure is the key step that keeps large maps consistent. A pose graph without loop closures is just a long chain of dead reckoning.

Where it goes wrong

  • False positives. Two hallways with identical doors can look the same. If the system accepts the wrong match, it pulls two different places together and warps the map. This is called perceptual aliasing. Defense: require a good alignment score, check consistency with the estimated position and with other constraints, and be able to discard a bad constraint.

  • False negatives. The robot revisits a place from another angle, or the place has changed, and the match is missed. The drift stays.

  • Large initial error. If the drift is bigger than the area the system searches, it never looks in the right place.

  • Cost. Comparing the current view against every past view gets slower as the map grows, so systems use indexes and only search likely candidates.

  • Moved furniture. Changes in the place reduce the match quality.

  • One-shot correction. A large sudden correction can make the robot's estimated pose jump. A planner has to handle that without throwing the robot off course.

Safety: A loop closure can shift the robot's estimate of its position by tens of centimeters in an instant. Do not command fast motion directly from that estimate near people, stairs or drop-offs, and keep a live obstacle sensor and an emergency stop active. Smooth or limit position jumps before they reach the motion controller.

How real robots use it

Robots that map large buildings, warehouses or outdoor sites rely on loop closure to keep maps consistent. Visual systems use image fingerprints for place recognition, and lidar systems use scan matching against nearby poses. Without loop closure, a map is accurate only over short distances. The glossary entry on SLAM places this in the bigger picture.

Try it yourself

Draw a square path of 4 sides on graph paper from your own step counts, with a small error built in, such as drawing every 5.0 m side as 5.2 m. Mark where the path ends and where it should have ended. Measure the gap. Then shift each point along the path by a fraction of the gap, proportional to how far along it is, and see how the loop closes.

Frequently asked questions

What is a loop in loop closure?

It is a path that returns to a place the robot has already visited. Recognizing the return gives a strong constraint that reveals and corrects the accumulated drift.

Why is a wrong loop closure so bad?

It tells the optimizer that two different places are the same, and it will bend the map to satisfy that. The result can be a badly distorted map.

Get started

DuckyHelper can
do more

It sees your screen and works in any app you use. Try it for 10 minutes, no card.

Get it for Mac, Windows or Linux

Share

Questions and jobs

Do anything

Ask it a question or hand it a job, in any app.

Doing jobs for you is in early access on Mac. Asking works on Mac, Windows and Linux.