Skip to main content
Open In Colab A LIDAR scan is a set of points on the surfaces around the robot. Two scans taken from nearby poses see the same walls, and the motion between the poses is the rigid transform that lays one scan on top of the other. Finding that transform is scan registration. It gives a motion estimate from the LIDAR alone, which LIDAR odometry chains from scan to scan, and it gives the relative pose between two visits to the same place, which a pose graph uses as a loop closure. The standard method is the iterative closest point algorithm (ICP) of Besl and McKay (1992). As the correspondence estimation section explains, its difficulty is the pairing: the scans do not say which point in one is the same surface point as a point in the other. ICP guesses the pairs from the current alignment, fits the transform to the guessed pairs, and repeats. The section builds ICP in steps. It starts with the fit for known pairs, which has a closed-form solution, and then adds the iteration over guessed pairs. It writes the same fit as a least-squares problem solved by Gauss-Newton, which allows two improvements: measuring the error to the local wall instead of to a single point, and weighting down pairs that do not belong to the same surface.

Two scans of a room

The code simulates a 2D LIDAR with 180 beams and 1 cm range noise in a 10 m by 6 m room with a box and a partition. The reference scan is taken at (2,2)(2, 2) m with heading 0. The new scan is taken 1.2 m away and turned by 20°. Each scan is returned in the frame of the sensor that took it. A person stands in the room for the new scan only; the code leaves it out until the part on outliers.

The fit for known pairs

Suppose the pairs were known: point pip_i of the new scan is the same surface point as qiq_i of the reference, for i=1,…,ni = 1, \ldots, n. The rotation RR and translation tt that align them minimize E(R,t)=∑i=1n∥Rpi+t−qi∥2.E(R, t) = \sum_{i=1}^{n} \lVert R p_i + t - q_i \rVert^2 . The minimum has a closed form (Arun, Huang and Blostein, 1987). Setting the derivative with respect to tt to zero gives t=qˉ−Rpˉt = \bar q - R \bar p, where pˉ\bar p and qˉ\bar q are the centroids of the two point sets. The best translation moves the rotated centroid of one set onto the centroid of the other. Substituting it back, with centered points pi′=pi−pˉp_i' = p_i - \bar p and qi′=qi−qˉq_i' = q_i - \bar q, leaves E(R)=∑i∥Rpi′−qi′∥2=∑i(∥pi′∥2+∥qi′∥2)−2∑iqi′⊤R pi′,E(R) = \sum_i \lVert R p_i' - q_i' \rVert^2 = \sum_i \left( \lVert p_i' \rVert^2 + \lVert q_i' \rVert^2 \right) - 2 \sum_i q_i'^\top R\, p_i' , because a rotation does not change lengths. Minimizing EE is the same as maximizing ∑iqi′⊤R pi′=tr⁡(RH),H=∑ipi′qi′⊤,\sum_i q_i'^\top R\, p_i' = \operatorname{tr}(R H), \qquad H = \sum_i p_i' q_i'^\top , where HH is the 2×22 \times 2 cross-covariance of the centered pairs. Write its singular value decomposition H=UΣV⊤H = U \Sigma V^\top. Then tr⁡(RH)=tr⁡(Σ V⊤RU)\operatorname{tr}(RH) = \operatorname{tr}(\Sigma\, V^\top R U). The matrix V⊤RUV^\top R U is orthogonal, so its diagonal entries are at most 1, and the trace is largest when V⊤RU=IV^\top R U = I: R=VU⊤,t=qˉ−Rpˉ.R = V U^\top, \qquad t = \bar q - R \bar p . If the points are nearly collinear or very noisy, VU⊤V U^\top can come out as a reflection, with determinant −1-1. The rotation closest to it is obtained by flipping the sign of the last column of VV. The code applies the fit to the new scan with the true pairs, which the simulation knows because both scans can be cast from the same beams. It recovers the pose up to the noise.

Iterating over guessed pairs

In practice the pairs are unknown, and the two scans do not even hit the walls at the same points. ICP replaces the true pairs with a guess and refines the guess:
  1. Transform the new scan with the current estimate of (R,t)(R, t).
  2. Pair each transformed point with its nearest point in the reference.
  3. Fit (R,t)(R, t) to these pairs with the closed form above.
  4. Repeat until the estimate stops changing.
Each iteration cannot increase the error. Step 3 lowers it for fixed pairs, and step 2 lowers it for a fixed transform, because every point moves to a partner at least as close. The error therefore converges, but only to a local minimum, and which one depends on the starting estimate. In a robot the start comes from odometry or an IMU. The code starts from an odometry guess that is 0.36 m and 8° off and records the pairs of every iteration.
Four panels of the room: the reference scan in blue on the walls and the new scan in orange, with green lines joining each new point to its nearest reference point. At iteration 0 the new scan is rotated and shifted and many lines are long; by iteration 3 it lies almost on the walls; at the final iteration the two scans overlap. ICP from the odometry guess. Green lines join every second point of the new scan (orange) to its nearest point in the reference scan (blue); these are the pairs the next fit uses. The walls of the map are drawn in gray for orientation and are not used. In the first iterations many pairs join points that are not the same surface point, some of them across a corner. Most still point roughly the right way, so each fit moves the scan closer, and the mean pair distance falls from 0.29 m to 0.12 m in five iterations. After 16 iterations the estimate is within 1.1 cm and 0.16° of the true pose. The mean pair distance stops at 6 cm, not zero, because the two scans hit the walls at different points. The starting estimate decides which minimum ICP reaches. The code repeats the run from the true position with the heading off by 70°.
ICP stops at a heading of 112°, 92° from the true one, and 0.68 m from the true position. The scan has turned by about a quarter turn, so its walls lie along the other pair of walls of the room, and no small change of the pose lowers the error. The mean pair distance, 0.67 m, is more than ten times the 0.06 m of the converged run. A residual this large marks a failed registration. The converse does not hold: in a room with repeated structure, such as a corridor of identical doors, a wrong alignment can also have a small residual.

ICP as least squares

The closed form works only for the squared distance between paired points. Other errors need a general method. Parameterize the pose by x=(tx,ty,θ)x = (t_x, t_y, \theta) and stack the residuals ei(x)=R(θ) pi+t−qi∈R2.e_i(x) = R(\theta)\, p_i + t - q_i \in \mathbb{R}^2 . They are linear in tt and nonlinear in θ\theta. Gauss-Newton linearizes them around the current estimate. The Jacobian of eie_i with respect to xx is Ji=[I2R′(θ) pi],R′(θ)=[−sin⁡θ−cos⁡θcos⁡θ−sin⁡θ],J_i = \begin{bmatrix} I_2 & R'(\theta)\, p_i \end{bmatrix}, \qquad R'(\theta) = \begin{bmatrix} -\sin\theta & -\cos\theta \\ \cos\theta & -\sin\theta \end{bmatrix}, and the update solves the normal equations Δx=−(∑iJi⊤WiJi)−1∑iJi⊤Wi ei,x←x+Δx,\Delta x = -\left( \sum_i J_i^\top W_i J_i \right)^{-1} \sum_i J_i^\top W_i\, e_i , \qquad x \leftarrow x + \Delta x , with a weight matrix WiW_i for each pair, the identity for now. For point pairs, one Gauss-Newton step per iteration reaches the same pose as the closed form, here in the same 16 iterations. Its advantage is that any residual with a Jacobian fits the same loop, and the weights WiW_i can differ from pair to pair. The next two parts use both.

Point-to-line error

The two scans sample a wall at different points. Even at the true pose a point of the new scan lies between two reference points, a few centimeters from either, so the point-to-point error never reaches zero, and it pulls the scan along the wall toward the sampled points. The error that matters is the distance across the wall. Chen and Medioni (1992) measured it from each point to the plane through its partner; in 2D the plane is a line. With nin_i the unit normal of the reference scan at qiq_i, the residual becomes a scalar, ei(x)=ni⊤(R(θ) pi+t−qi),Ji=ni⊤[I2R′(θ) pi].e_i(x) = n_i^\top \left( R(\theta)\, p_i + t - q_i \right), \qquad J_i = n_i^\top \begin{bmatrix} I_2 & R'(\theta)\, p_i \end{bmatrix} . A point can slide along the wall without cost, and only its distance from the wall counts. The normals come from the reference scan: for each point, fit a line to it and its four nearest neighbors, and take the direction of least spread as the normal.
Position error in centimeters against iteration on a log scale for point-to-point and point-to-line ICP, both starting from the same odometry guess. Position error of the estimate at each iteration, for the point-to-point and point-to-line residuals, from the same odometry guess. Point-to-line ICP reaches its final estimate after three iterations and stops after six. Point-to-point needs 16, and both end within about 1 cm of the true position. Point-to-point closes in slowly because each pair pulls a point toward a sampled point, which can lie along the wall in the wrong direction. Near the end its error even rises again, from 0.5 cm to 1.1 cm, as the pairs change. Point-to-line ignores motion along a wall, so it converges in a few steps as long as the scan contains walls in at least two directions. In this run its final heading error, 0.41°, is larger than the 0.16° of point-to-point. A likely cause is the noise in normals estimated from only five neighbors.

Outliers

Not every point of the new scan has a partner in the reference. A person who walked in between the scans, a door that moved, or a part of the room that only one scan sees all produce points whose nearest neighbor lies on a different surface. Least squares gives each of them a weight that grows with the square of its residual, so a few of them can pull the whole alignment. A robust error replaces the square with a function that grows more slowly for large residuals. In the Gauss-Newton loop this only changes the weights: each pair gets a weight wiw_i computed from its current residual rir_i, and the weighted problem is solved as before. The Huber weight with threshold δ\delta is wi={1∣ri∣≤δδ/∣ri∣∣ri∣>δw_i = \begin{cases} 1 & |r_i| \le \delta \\ \delta / |r_i| & |r_i| > \delta \end{cases} which keeps the square for small residuals and makes the cost linear beyond δ\delta. A cruder alternative drops every pair with a residual above a threshold. The code repeats the point-to-line run with a new scan that also sees the person, standing between the two poses, once with plain least squares and once with Huber weights and δ=5\delta = 5 cm.
Two panels of the room after point-to-line ICP with a person present in the new scan only. Points on the person are marked with black crosses. The titles give the final position and heading error for plain least squares and for Huber weights. The new scan after point-to-line ICP when it also sees a person (pink, crosses mark the points on the person). Left: plain least squares. Right: Huber weights. The titles give the remaining position and heading error. Seven of the 180 points fall on the person. With plain least squares they pair with points on the box about 1.4 m away and drag the scan toward it, and the estimate ends 15.2 cm from the true position. Huber weights cap the influence of each of those pairs, and the estimate ends within 0.1 cm and 0.16°.

ICP in practice

Real implementations add a few things that the code above leaves out. They find nearest neighbors with a k-d tree or a voxel grid instead of comparing every pair of points. They subsample dense scans, often to one point per voxel. They reject pairs farther apart than a threshold that shrinks as the alignment improves, which combines the trimming above with the robust weights. And they check the result: a large final residual, or a Hessian ∑iJi⊤WiJi\sum_i J_i^\top W_i J_i that is nearly singular, as in a long featureless corridor where the scan can slide along the walls, marks an alignment that should not be trusted. KISS-ICP (Vizzo et al., 2023) is a recent LIDAR odometry system built almost entirely from these parts: point-to-point ICP on a voxel map, a motion prediction from the previous scans as the starting estimate, and a robust kernel whose threshold adapts to how well recent scans have aligned. Not every 2D SLAM system uses ICP. slam_toolbox, the default SLAM package of Nav2, matches scans with a correlative matcher that evaluates a grid of candidate poses against a likelihood map, which does not depend on a good starting estimate in the same way.

References

  • Arun, K. S., Huang, T. S., and Blostein, S. D. (1987). Least-squares fitting of two 3-D point sets. IEEE Transactions on Pattern Analysis and Machine Intelligence.
  • Besl, P. J., and McKay, N. D. (1992). A method for registration of 3-D shapes. IEEE Transactions on Pattern Analysis and Machine Intelligence.
  • Chen, Y., and Medioni, G. (1992). Object modelling by registration of multiple range images. Image and Vision Computing.
  • Vizzo, I., Guadagnino, T., Mersch, B., Wiesmann, L., Behley, J., and Stachniss, C. (2023). KISS-ICP: In defense of point-to-point ICP, simple, accurate, and robust registration if done the right way. IEEE Robotics and Automation Letters.

Found an error on this page? Report an issue.