v9.1.1
Menu

Loop Closure Detection

Detect potential loop closures based on pose proximity.

Loop closure is one of the most critical components of SLAM. It occurs when a robot returns to a previously visited location, allowing it to correct accumulated drift.

Simple loop closure detection checks if the current pose is close to any past pose:

  • Compute distance to each past pose
  • If distance < threshold, it's a potential loop closure candidate

In practice, loop closure also uses appearance-based methods (comparing images or point clouds), but geometric proximity is a necessary first filter.

Example

Input
detect_loop_closure([0, 0, 0], [[10, 0, 0], [0.5, 0.5, 0], [5, 5, 0]], 1.0)
Output
[1]
Reasoning
  • Inputs: current_pose is (x,y,θ)=(0,0,0)(x, y, \theta) = (0, 0, 0), past_poses holds three earlier poses, and distance_thresh is 1.01.0. Position is what matters for "have I been here before?", so heading θ\theta plays no part in the distance.
  • Math: for past pose ii at (xi,yi)(x_i, y_i), the planar Euclidean distance is di=(x−xi)2+(y−yi)2d_i = \sqrt{(x - x_i)^2 + (y - y_i)^2}.
  • Pose 0 at (10,0)(10, 0): d0=100+0=10d_0 = \sqrt{100 + 0} = 10, far outside the radius.
  • Pose 1 at (0.5,0.5)(0.5, 0.5): d1=0.25+0.25=0.5≈0.707<1.0d_1 = \sqrt{0.25 + 0.25} = \sqrt{0.5} \approx 0.707 < 1.0, a candidate.
  • Pose 2 at (5,5)(5, 5): d2=25+25≈7.071d_2 = \sqrt{25 + 25} \approx 7.071, too far.
  • Output: the positions (not coordinates) of the qualifying poses in their original order, so [1]. Notice the test is strict: a pose at exactly distance 1.01.0 would not count, and if nothing is close the result is an empty list.

Constraints

  • current_pose: [x, y, theta] current robot pose
  • past_poses: list of [x, y, theta] previously visited poses
  • distance_thresh: maximum distance for loop closure candidate
  • Return list of indices of potential loop closures

Learn this in

More from CV: Structure from Motion and SLAM

solution.py

Test results

Sign in to run your code against the test cases.