Simultaneous Localization and Mapping (SLAM)
Every filter we've looked at so far cheated a tiny bit: it assumed someone already handed the robot a clean map of beacons or corridor walls. In the real world — exploring a collapsed tunnel, a new apartment, or an orchard — you don't get a blueprint ahead of time. You have to build the map while figuring out where you are inside it.
Core ideas covered in this module
- Joint pose & landmark estimation
- Loop closure detection
- Pose graph optimization
The chicken-and-egg problem of SLAM
Simultaneous Localization and Mapping (SLAM) looks impossible at first glance: to localize accurately, you need a reliable map; to place walls and landmarks accurately onto a map, you need to know where the robot was standing when it saw them.
If your odometry slowly drifts 3° while driving down a long loop, every wall you paint onto the map gets slightly rotated. By the time you loop back to where you started, your map shows two slightly offset copies of the same front door instead of one clean room.
Loop closure and pose graph relaxation
Modern SLAM breaks that dead-end with two big ideas. First, instead of throwing away old poses, the robot builds a pose graph: nodes are past robot positions along its drive, and edges are odometry links ('step 4 to step 5 felt like 0.4 m forward') plus landmark sightings.
Second, when the robot loops back and its camera or LiDAR recognizes a corner it visited minutes ago — a loop closure — it adds a new, high-confidence constraint tying the end of the trajectory directly back to the start. Now the graph is over-constrained, and a fast optimizer gently relaxes all the nodes along the loop, spreading the tiny accumulated drift evenly across the whole path until the two doorways snap cleanly into one.
- Front-end SLAM extracts features, matches consecutive scans, and proposes candidate loop closures.
- Back-end SLAM solves the nonlinear least-squares pose graph to align every past pose and landmark consistently.
- Bundle adjustment and factor graphs generalize this exact idea to 3D visual SLAM and LiDAR-inertial mapping.
From maps to persistent spatial memory
Seeing a warped, double-walled map snap into crisp alignment after one loop closure is one of the most satisfying moments in robotics. Suddenly, the robot isn't just surviving moment to moment — it has a consistent geometric memory of the building.
Across Course 5, we've gone all the way from raw noisy wheel clicks, to tracking uncertainty with Bayes rule and Kalman ellipses, to handling ambiguous hallways with particles, and finally to building maps from scratch with SLAM. Next, in Course 6, we look at how modern robot learning and embodied AI connect perception directly to generalizable control.
Pose graph optimization objective
x* = argmin_x Σ || e_odom(x_i, x_{i+1}) ||²_Ω + Σ || e_loop(x_i, x_j) ||²_Ω_loop
SLAM finds the full chain of poses x that minimizes disagreement across both sequential odometry edges and long-range loop-closure links.
A mapping robot drives all the way around a large square courtyard and draws a map whose start and end hallways fail to meet by 1.2 meters. What happens the instant SLAM detects a valid loop closure?
Open-source back-ends like GTSAM, g2o, Cartographer, and ORB-SLAM3 power everything from autonomous drones and home vacuums to AR headsets — turning noisy sensor streams into metric 3D maps in real time.
Hands-On Python Notebook
05 · Pose Graph SLAM & Loop Closure Relaxation
Build a 2D pose graph from drifting odometry constraints, add a loop-closure edge, and relax the entire trajectory via Gauss-Newton.
Try this on your own inside the notebook
- Observe what happens when a single false-positive loop closure is added
- Inspect how uncertainty shrinks along the middle of the loop after closure
In Google Colab, use File → Save a copy in Drive to keep your own edits and notes. Or download the files directly:
uvx marimo edit --sandbox notebooks/course-5/05_slam_pose_graph_loop_closure.pyWrap up this module
Saved automatically in your browser profile so you can pick up right where you left off.