Localization with a known map
EKF localization with known correspondences
EKF localization tracks the pose of a ground robot such as the TurtleBot, , with the extended Kalman filter. Its belief is a single Gaussian, which has one peak, so the filter has to start from a rough estimate of where the robot is. It cannot express a belief like “the robot is in one of these two places”, which is what you get when the starting pose is unknown. The particle filter can represent such a belief.Landmarks, observations and signatures
There are two fundamentally different ways to construct a measurement model from sensor data. A beam-based measurement model, operates directly on the ranges returned by a LIDAR. Given a robot pose and an occupancy map, it predicts each range by ray casting and evaluates how well the predicted scan agrees with the observed scan. This approach is not naturally suited to the EKF. A small change in the robot pose can cause a beam to intersect a different obstacle, producing an abrupt change in the predicted range. Consequently, a local linear approximation of the measurement function may be unreliable. Furthermore, the beam measurement model accounts for several types of measurement errors, resulting in a likelihood that is not Gaussian. An alternative is a landmark detector, which Probabilistic Robotics (Section 6.6) calls a feature extractor. It reduces each raw measurement to a short list of landmark observations, such as the range and bearing of each identifiable landmark in view. Once an observation is associated with a known landmark, its expected range and bearing are differentiable functions of the pose, and their errors are close to Gaussian, which is what the EKF needs. This section takes that approach. Scan-based localization usually runs on a particle filter, as Nav2’s AMCL does. Five terms describe the landmarks and the robot’s observations of them:- A landmark is a distinct object in the world that the robot uses for navigation, such as a pole, a door post or a chair.
- The map lists the known landmarks, indexed by . Landmark has a position in the map frame and a signature . Such a landmark map, which Thrun, Burgard and Fox call a feature-based map, records where the landmarks are and what they look like, and nothing about the space between them.
- A signature describes how a landmark looks. Thrun, Burgard and Fox allow a number such as an average color, an integer for the landmark’s type, or a vector such as height and color (Probabilistic Robotics, Section 6.6).
- A landmark observation is one perceptive detection of a landmark at one time step, in the robot’s frame: . Its geometric measurement is the range and bearing of the landmark, and is its observed signature. The index counts the observations of step . The detector turns the raw measurement , a whole scan or image, into the list . A superscript therefore marks the range and bearing of one observation, while without it is the raw measurement of the Bayes filter. Landmarks stay in the map, while observations are produced anew at every step, and their number changes as landmarks come into and out of view.
- The correspondence says that observation came from landmark : counts the observations of one step, and counts the landmarks of the map. Thrun, Burgard and Fox also allow for an observation that matches no landmark, such as a spurious detection. Nothing in the definition stops two observations from having the same landmark. For observations from one camera image that assignment is wrong, since two image regions are two places in the world, and data association usually adds this constraint, called mutual exclusion (Probabilistic Robotics, Section 7.8).
Thrun, Burgard and Fox call the whole triple a feature and write it (Probabilistic Robotics, Section 6.6). In computer vision, a feature is a vector that a network computes from an image, such as the appearance embedding in the example below. We stick to the term landmark observation for the triplet. The probabilistic model is the same as in the book.
Example: detected objects as landmark observations
An office map has four landmarks, each specified by the position of its center and a signature with two parts. The class label names the object class. The appearance embedding is a vector of a few hundred numbers that a CNN computes from an image of the object. Embeddings of two views of the same object point in nearly the same direction. Embeddings of two different objects of the same class point in different directions only if the network was trained to tell individual objects apart, not just classes.
The robot stands at the origin, facing along the axis. Its RGB-D camera sees to either side, so only the gray office chair () and the trash can () are in view. The fire extinguisher, at a bearing of , and the armchair, at , produce no observations. An object detector draws a box around each object it recognizes, and the depth pixels inside a box give the centroid of the visible part of the object. The centroid’s range and bearing, measured counterclockwise from the heading so that positive is to the left, form the geometric measurement of an observation. The class label and the embedding of the image inside the box form its signature . The detector reports the trash can first and the chair second:
Code
Code
Data association
Data association finds for each observation. The first observation is a trash can, and the map has only one, so : the order in which the detector reports the observations says nothing about the order of the map. The second observation is a chair, and the map has two. The class label cannot decide between them, so we compare the observed embedding with the stored ones. Say their cosine similarities are so . The predicted range and bearing can also decide a correspondence, but only when the pose is already well known. If the two chairs were of the same model, their embeddings would be nearly equal, and only the predicted range and bearing could tell them apart. Localization solves the reverse problem. It estimates the pose from which the associated landmarks would appear at the measured ranges and bearings. From , for example, the chair would appear at 1.41 m and , far from the measured 2.27 m and , so that pose is unlikely.Probabilistic measurement model
With the robot at and a known correspondence , the range and bearing1 that landmark would produce without noise are The measured range and bearing are these values plus noise: This is the probabilistic model of linear regression with a nonlinear mean: gives the conditional mean of the measurement given the pose, and gives its covariance. The range and bearing noises are taken as independent, so is diagonal. The bearing error is wrapped to , since bearings of and are only apart. A Gaussian on the wrapped bearing error is a local approximation to a distribution on the circle, and it is accurate when is a few degrees. For a real sensor, and are estimated from calibration data, by measuring landmarks at known positions. An observation also carries the signature , so its full likelihood has a second factor, , which scores how well the observed signature matches the one stored for landmark . The model assumes that this appearance factor is independent of the geometric error and of the pose. The second assumption is an approximation, since a real image of an object, and its embedding, change with the viewpoint. Under it, and with a known correspondence, the appearance factor is constant in the pose and cancels when the posterior is normalized, so the EKF uses only . The appearance factor is what finds the correspondence, as in the example. Correspondence estimation defines it for a class label and an embedding and adds it to the score of each candidate landmark. Given the correspondences, the errors of different observations are taken as independent. The likelihood of all the observations of a step is then the product of their likelihoods, and the filter can process the observations one at a time. The product takes the number of observations as given. It does not model which landmarks the detector finds and which it misses.Modeling assumptions: detector errors, other sensors and the map
Modeling assumptions: detector errors, other sensors and the map
This model assumes a sensor that detects every landmark in view and whose only error is zero-mean noise on the measured position. A detector also misses objects, reports objects that are not there and confuses classes. Its centroid lies on the visible surface of the object, closer to the camera than the object’s center. That offset depends on the size of the object and the viewing angle, so it is a bias, which zero-mean noise does not describe. The confusion matrix covers class confusion. The filter handles the other errors outside the model. A missed object gives no observation, the validation gate of line 7 below rejects observations far from their prediction, and correspondence estimation assigns observations that carry no ID.The filter is the same for every sensor. What changes is , which landmarks are visible, and whether the signature gives the correspondence. A camera that reads fiducial markers gets each landmark’s ID, and with it . A 2D LIDAR such as the TurtleBot3’s LDS-01 measures range and bearing more precisely than a depth camera, but it reports no class label or embedding, so landmarks extracted from its scan need correspondence estimation. A dark object that absorbs the laser returns nothing at all. The Perception overview lists what each sensor supplies.The landmark positions are treated as exact. If each landmark’s position error is independent of the others, its covariance can be propagated through and added to . When the landmark positions are estimated together with the pose, the problem becomes SLAM.
Linearization of the measurement model
The EKF update needs linearized at the predicted mean . With the landmark and the map fixed, maps the 3-dimensional pose to the 2-dimensional geometric measurement, . Write and . Differentiating the two rows of with respect to gives the Jacobian Each row says how one measurement changes for a small change of the pose. The zero in the range row says that turning in place does not change the distance to a landmark. The last entry of the bearing row is : the bearing falls by one radian for each radian the robot turns counterclockwise. Both and are undefined when the robot stands on the landmark, , and the bearing row grows as close to it. A real system rejects observations with a very small predicted range. With of size , and are and the gain is , as in the size table of the EKF section.The signature as a third measurement row (Table 7.2 of Probabilistic Robotics)
The signature as a third measurement row (Table 7.2 of Probabilistic Robotics)
Table 7.2 of Probabilistic Robotics takes a scalar numerical signature with Gaussian noise. It predicts all three parts of the observation and linearizes them at the predicted mean :with measurement noise covariance . The last row of is zero because the signature of a landmark does not depend on where the robot stands.The zero row means the signature cannot move the estimate. Since is diagonal, the innovation covariance is block diagonal, with the range-bearing block in the top left and in the bottom right. The third column of the gain is then zero. In line 9 of the algorithm below, the signature innovation is multiplied by that zero column. In line 10, the term picks up only through the same zero column, and uses only the first two rows of . Deleting the third row of , and therefore gives exactly the same mean and covariance. The one place the two forms differ is the gate of line 7: with the third row, the squared Mahalanobis distance gains the term and has 3 degrees of freedom instead of 2.The label and embedding of the example have no such row, because there is no difference to linearize, so for them the gate keeps 2 degrees of freedom. The code uses the two-row form above.
Motion model
The action is the pair of wheel speeds . As derived in nonholonomic robots, they set the forward speed and the turning rate . Holding and constant for is a constant body twist . The new pose is then the planar screw motion of motion representations, , which moves the robot along an arc of radius . Multiplying out the two matrices and reading off the position and the heading gives the motion model The noise comes from the wheels. Each wheel turns at its commanded speed plus Gaussian noise that stays constant during the step. is the covariance of that noise, in wheel-speed units of . The two wheels have separate motors and encoders, so their noises are taken as independent and is diagonal. The standard deviation of each wheel grows with its commanded speed, on top of a floor: The parameter scales the noise with the speed, and is the noise that remains when a wheel is nearly still. Both depend on the robot and are estimated from driving data. Probabilistic Robotics (Section 5.3) puts the noise on the velocities , with variances that grow with the commanded velocities through four robot-specific parameters to . Noise on the wheel speeds has the same diagonal structure, one entry per wheel. The two terms of stand for two kinds of error. The term covers errors that are a fixed fraction of the motion. If the real wheel radius is 1% smaller than the in the model, because the tire is worn or the robot carries a load, each wheel turn covers 1% less ground at any speed. Slip on the floor and the lag of the motor’s speed controller also grow with the speed. These act like a percentage error, so the standard deviation is proportional to : a wheel that turns twice as far during the step has twice the error. The floor covers errors that do not shrink as the wheel slows down. The encoder counts whole ticks, so it measures the speed only to within about one tick per sampling period. Near zero speed the gears have play and the motor needs a minimum current to overcome static friction, so a wheel commanded to turn slowly may stall and then jerk forward. The floor also keeps positive definite when a wheel is commanded to stop. Without it, a robot told to stand still would add no uncertainty to its pose, and the filter would become more confident the longer it waits. With the values of the example below, and rad/s, the robot that drives a circle of radius 1.5 m at 0.2 m/s commands and rad/s. Then and rad/s, about 7% of each wheel’s speed, and the floor contributes about a quarter of each. Errors on the two wheels affect the pose in different ways. A common error, both wheels too fast, changes how far the robot goes. A difference between them changes how much it turns. For this robot and a step of s, the wheel noise above gives a distance error of about 5 mm and a heading error of about per step. The heading error matters more: driving on with a wrong heading turns it into a sideways position error that grows with the distance driven. That is where the banana shape of the predicted poses comes from. Diagonal is an approximation. A slippery patch of floor or a low battery slows both wheels at once, which would add an off-diagonal term.Linearization of the motion model
The prediction step needs linearized at the previous mean and the commanded wheel speeds, once with respect to the state and once with respect to the action. The Jacobian with respect to the state is It is derived the same way as the simpler model of the overconfident EKF prediction section, one row of at a time. Only the heading enters nonlinearly, so the third column holds the derivatives of the first two rows with respect to , and the rest of is the identity. Line 2 of the algorithm uses it to propagate the previous covariance, . The Jacobian with respect to the wheel speeds, , maps the wheel noise into the state, so the motion noise covariance is .Deriving the motion noise Jacobian V_t
Deriving the motion noise Jacobian V_t
The wheel speeds enter only through and , so the chain rule splits into two factors:The second factor is a constant matrix, because and are linear in the wheel speeds:Each column of belongs to one wheel. An error in one wheel’s speed changes by times that error and by times it, so noise on a single wheel both moves the robot forward and turns it.The first factor is the derivative of the arc. Write for the heading at the end of the step. Differentiating with respect to givesand with respect to , where also depends on ,The two columns form the matrix , anda matrix evaluated at and the commanded wheel speeds. With of size , the motion noise is , the size of the state covariance. already contains , so it turns the wheel-speed covariance into a pose covariance directly, and needs no extra factor of . For the same reason must describe wheel speeds, not wheel angles.When both wheels turn at the same speed, and the formulas above divide by zero. Their limit as is the straight drive:A turn-rate error during a straight drive moves the robot sideways by an amount that grows with , because the heading error it causes grows during the step. The code uses these limits when the turn per step is tiny, . Near the arc formulas subtract nearly equal numbers and divide by a small , which loses precision. The function
V in the code below implements both cases.The algorithm
One step takes the previous belief, the action, the observations and their correspondences, and the map: Lines 1 and 2 are the prediction step of the EKF, with the motion model and its noise . Line 3 loops over the observations of step in the order the sensor reported them. Each observation arrives with its landmark , so no search over the landmarks is needed. Lines 9 and 10 overwrite and , so each observation starts from the belief the previous one left. When no landmark is in view the loop does not run, and line 11 returns the prediction. Line 4 computes the predicted measurement , the range and bearing the sensor would report from the current if there were no noise, and the Jacobian at the same point, so each observation is linearized at the mean the previous one left. For a linear-Gaussian model with independent measurement noises, updating with one observation at a time gives exactly the same result as one update with all of them stacked. For the EKF the two can differ, because a stacked update linearizes once, at the predicted mean, and the sequential result can also depend on the order of the observations. The difference grows with how strongly bends over the spread of the belief, and it is not always small. In the office example, say the prediction step puts the robot at the origin facing along the axis, . Observation 1 came from the trash can at m, so line 4 gives The code below computes line 4 for both observations, and the figure draws the result.Code
Code
Code
Code
One step with one landmark
We revisit the robot from the overconfident EKF prediction example, but now introduce a landmark observation. The robot drives straight for 1 m with a nominal heading of . Its initial position uncertainty is 2 cm and its heading uncertainty is . A landmark is located at m. The robot’s actual heading differs from the nominal heading by , so it stops at approximately m. It then measures the range and bearing to the landmark, with measurement noise of cm and . We compare the EKF’s prediction and measurement update against a Monte Carlo approximation of the corresponding distributions. Our objective is to understand how much a landmark observation can correct an inaccurate prediction.Code
Code
- The bearing helps determine which side of the predicted trajectory the robot is on.
- The range helps determine how far the robot is from the landmark.
Why one bearing shrinks the uncertainty in x so much
Why one bearing shrinks the uncertainty in x so much
After the prediction, and carry the same error. A heading error of radians moves the robot meters sideways over the 1 m drive, so the predicted covariance correlates and almost perfectly. At the predicted mean, the bearing row of is . A heading error therefore changes the predicted bearing by about : once because the robot is turned, and once because the robot sits to the side of the landmark. With , the predicted bearing has a standard deviation of about . The sensor measures the bearing to , about 30 times finer. Since one error drives both and , a bearing that fixes fixes both of them, and both standard deviations shrink by about that factor of 30. The update leaves with about 2 cm and with about .
Driving among landmarks
Over many steps, the code below drives a simulated TurtleBot3 Waffle around a circle of radius 1.5 m at 0.2 m/s for 70 s, about one and a half laps. Three landmarks stand outside the circle. The sensor is idealized: it sees every landmark within 1.5 m, in any direction, with nothing in the way. A camera has a limited field of view, and one landmark can occlude another, which would leave more steps without a measurement. Even so, on parts of the circle no landmark is within range. Each wheel of the simulated robot turns at its commanded speed plus noise drawn from the motion model’s , with and rad/s, and the filter uses the same . The sensor noise is the same as in the single step. The filter starts from the nominal starting pose, and the true starting pose is drawn from the filter’s initial belief, so the initial error matches the initial covariance. For comparison, the same filter also runs without any measurements, which is dead reckoning from the wheel speeds alone. The gate is off.Code
Code
Checking consistency over many runs
A filter is consistent when its error has the covariance the filter claims. The normalized estimation error squared (NEES) tests this for the whole state at once: For a consistent filter follows a chi-square distribution with 3 degrees of freedom, the size of the state, so its mean is 3. The NEES needs the true state, which only a simulation has. The normalized innovation squared (NIS) needs only the measurements, so a real robot can compute it. It is the squared Mahalanobis distance of line 7, with mean 2 for a consistent filter. The code below repeats the drive 50 times with different noise and averages the NEES over the runs at each time step. A consistent filter’s average falls inside a band given by the chi-square distribution 95% of the time. The code does this once with the gate off and once with it on.Code
Code
Where road maps come from
Lane-level road maps have been built by surveying. The markings are either measured with surveying instruments such as a total station, which takes a long time when an area has many markings (arXiv:2209.07737), or extracted from the point clouds of vehicles that carry 3D LIDAR, which is expensive (arXiv:2601.19536). A pipeline that uses only cameras costs less than either. In such a pipeline, each frame is warped to a bird’s-eye view with the homography of the road plane, and the lane markings are segmented in that view. The marking positions and the homography are then refined until a marking seen in many frames has the same position on the road in all of them. In the first paper, the vehicle poses come from RTK-GNSS, and only the markings and the homography are refined. In the second paper, the vehicle poses are refined as well. Mobileye’s REM collects lane markings and landmarks from the cameras of production cars and merges them in the cloud into one map. Cars then localize against that map by detecting its landmarks (Mobileye). The REM map also contains lane markings, while the map in this section contains only point landmarks. Localization against it has the same predict and correct structure as the filter in this section: the car predicts where each map landmark should appear, and it corrects its pose from the difference between the predicted and the observed positions.Found an error on this page? Report an issue.
Footnotes
- is the two-argument arctangent: the angle of the point , measured counterclockwise from the positive axis, in . In terms of the ordinary arctangent, , and it is undefined at . It differs from , which depends only on the ratio and returns angles in . The points and both give , while gives and . The two agree when , and is also defined at . ↩

