Closing the Loop
Imagine you walk around a city block. You start at a coffee shop, turn right at each corner, and eventually... you see the same coffee shop ahead. You've completed a loop.
Here's the problem: if you counted your steps, your estimate says you're 12 meters away from where you started. But you're clearly at the starting point — your odometry drifted. By recognizing you've returned to the start, you can correct all the position errors you accumulated along the way.
That's loop closure in robotics SLAM. It's the moment when the robot realizes "I've been here before" and uses that recognition to fix accumulated errors in both its trajectory and map.
Why Drift Happens
Even the best robots accumulate position errors:
- Wheel slippage — carpets, slippery floors, uneven terrain
- Calibration imperfections — wheel diameter slightly wrong, sensors misaligned
- Sensor noise — every measurement has ±1cm error, and those add up
- Integration errors — small rounding errors accumulate over thousands of calculations
A typical robot might accumulate 1-2% error relative to distance traveled. That's 1-2 meters of error after exploring a 100-meter hallway. Without correction, the map becomes increasingly distorted.
Without loop closure, SLAM maps slowly turn into abstract art. Walls that should connect don't, rooms that should be rectangular become parallelograms, and the robot's estimated position drifts farther from reality.
How Loop Closure Works
Loop closure has three critical steps:
1. Place Recognition
The robot needs to detect when it's returned to a previously mapped location. This is harder than it sounds because:
- The robot's viewing angle might be different
- Lighting or scene contents may have changed
- Similar-looking places might cause false positives
Common techniques:
- Visual features — match camera images using SIFT, ORB, or deep learning
- Geometric features — match LiDAR scans using scan matching algorithms
- Bag-of-words — treat features like words, places like documents, and use text search techniques
2. Constraint Generation
Once the robot recognizes "this is the same place as pose 734," it adds a constraint: "my current pose and pose 734 should be very close together." This constraint contradicts the odometry-based estimate (which says they're far apart).
3. Graph Optimization
The SLAM algorithm re-optimizes the entire pose graph with this new constraint. It adjusts all intermediate poses to satisfy both the odometry constraints (how the robot moved) and the loop closure constraint (start and end should match).
The result: the trajectory "bends" to close the loop, distributing the accumulated error across all poses. The map becomes globally consistent.
False Positives: The Loop Closure Trap
The biggest danger in loop closure is false positives — thinking you've been somewhere before when you haven't. This adds a constraint that says "these two distant places should be the same location," which destroys your map.
Imagine walking around a building, and the robot incorrectly thinks floor 1 and floor 2 are the same place (they might look similar). The map collapses as the algorithm tries to force two entire floors to occupy the same space.
Good loop closure systems require high confidence before accepting a match:
- Multiple feature matches (not just one similar corner)
- Geometric consistency checks (the spatial layout should match, not just individual features)
- Temporal reasoning (you probably haven't returned to the start after only 10 seconds)
- RANSAC or other outlier rejection techniques
You can tune loop closure conservativeness. In exploration mode (discovering new areas), be conservative (fewer false positives). In relocalization mode (definitely in a known area), be aggressive (accept more matches).
Multi-Session Mapping
Loop closure enables something powerful: multi-session SLAM. The robot can:
- Explore an area and save the map
- Shut down, get moved to a different starting point
- Turn back on, recognize landmarks from the saved map
- Continue exploring and expand the map
This is how warehouse robots handle large facilities — they don't map the entire warehouse in one go. They build it up over days, with loop closures stitching each session's exploration into the global map.
Loop Closure in Practice
Different SLAM systems handle loop closure differently:
| System | Loop Closure Approach |
|---|---|
| ORB-SLAM | Bag-of-words image matching with DBoW2 |
| Cartographer (Google) | Scan-to-map matching with branch-and-bound search |
| RTAB-Map | Visual appearance + geometric verification |
| LSD-SLAM | Direct image alignment (no features) |
Some systems do loop closure in real-time, optimizing every few seconds. Others defer it — build a map quickly, then refine it offline during a batch optimization phase.
What's Next?
You now understand the full SLAM pipeline: from occupancy grids to localization, from graph-based optimization to loop closure. The next module will build on this foundation to explore navigation — how robots use maps to plan paths and avoid obstacles in real-time. But that's for another day. For now, you've conquered one of the hardest problems in robotics.