A robot and a landmark on a line
Before considering the planar robot, we use the simplest possible case to show why SLAM needs one joint belief over the pose and the map. A range measurement depends only on the difference between the landmark and robot positions. The robot and landmark estimates are independent before the measurement. When the robot moves, the landmark stays where it is, so motion changes the robot estimate and leaves the landmark estimate alone. Motion therefore cannot create a correlation between the two estimates. A measurement that involves both positions can, and after the update the estimates are correlated. EKF SLAM stores such correlations in the off-diagonal entries of its covariance matrix. The example also shows how the filter divides a correction between the two positions. The robot is at an estimated position of 1 m, with a standard deviation of 20 cm. A landmark is estimated to be at 4 m, with a standard deviation of 10 cm. Assume that the two estimates are initially independent. We would therefore expect the sensor to report a distance of 3 m. Suppose it reports 3.1 m instead. We could account for the extra 10 cm by moving the estimated landmark position to 4.1 m, by moving the estimated robot position to 0.9 m, or by changing both estimates. The Kalman filter must decide how to distribute the correction, taking into account the uncertainty in each position and in the measurement.Code
Code
Correlation from a single update
Notice the change in the covariance matrix. Its off-diagonal entries, which were initially zero, are now positive. To interpret these entries, we need a different plot from the previous one. Put the robot position on the horizontal axis and the landmark position on the vertical axis. A point in this plot specifies an entire configuration of our one-dimensional world. If the sensor were exact, all configurations consistent with the measurement would satisfy This line is the measurement line. For instance, and both satisfy this equation. We cannot tell them apart using range alone. With a noisy sensor, configurations near the line are more likely than those far from it.What did the measurement tell us about the map?
The quantity measured by the sensor was the relative position . Before the update its variance was After the update we must account for the cross-covariance: The standard deviation of the relative position has gone from 22.4 cm to 9.1 cm. Compare this with the uncertainty in the individual positions:Where the variance of the relative position comes from
Where the variance of the relative position comes from
Write each position as its mean plus an error, and . The error of is then , and its variance is the expected square of that error:The last term is the cross-covariance, the off-diagonal entry of . Before the update the two estimates are independent, so and the two variances simply add: , a standard deviation of 22.4 cm.After the update, with , and ,a standard deviation of 9.1 cm. The positive covariance enters with a minus sign. It means the errors and tend to have the same sign: if the robot is estimated too far to the right, the landmark probably is too. In the difference the two errors largely cancel, so the gap between robot and landmark is known much better than either position.The same number follows without . Before the update the relative position is known with variance 0.05. The sensor measures that same quantity with variance . Combining two independent estimates of one quantity adds their inverse variances:This is the one-dimensional Kalman update applied to directly. The result, 9.1 cm, is slightly better than the sensor’s 10 cm, because the prior adds a little information.In matrix form, with , which is . For the prior, is the term that appears in the innovation variance .
The EKF SLAM state
We now return to a planar robot. Let be its pose and let be the coordinates of landmark . With landmarks in the map, the state is As in EKF localization, the filter approximates its belief by a Gaussian, . The difference is that the Gaussian now describes a -dimensional state. Thrun, Burgard and Fox also store a signature for each landmark (equation 10.7); we omit that component because the landmarks in our example are indistinguishable by appearance. It is useful to partition the covariance according to the pose and map: The block describes pose uncertainty. The block includes the uncertainty of individual landmarks as well as their mutual cross-covariances. The rectangular block describes how the pose estimate is correlated with each of the landmark estimates. By symmetry, . The small example above explains why we cannot simply discard the off-diagonal blocks. They describe dependencies produced by past measurements. In a SLAM map, these dependencies also arise when several landmark positions are inferred from an uncertain pose.Prediction
Suppose the robot executes an action . We already know from EKF localization how to predict the new pose using the motion model . What should happen to the map? The landmarks are stationary, so their estimated coordinates do not change during prediction. Let and be the Jacobians of the motion model with respect to the pose and the wheel speeds, respectively, and let be the wheel-speed noise covariance. The pose process noise is . Assuming independent process noise and a static map, the augmented prediction is Multiplying out the blocks gives Here the blocks on the right belong to time . The map’s marginal distribution remains unchanged, but its relationship to the robot’s new pose generally changes. This is why propagating only the pose covariance is insufficient.Measurements of known landmarks
Suppose the robot detects landmark and that we know which landmark produced the measurement. As in localization, the measurement consists of a range and bearing: In localization, the landmark coordinates were constants when we differentiated . Now both and belong to the state. The full measurement Jacobian has two potentially nonzero blocks: The two nonzero blocks are , of size , and , of size . Both are evaluated at the predicted mean. Here is a block of zeros with rows and columns. The first zero block covers landmarks to and the second covers landmarks to . These columns are zero because a measurement of landmark does not depend on where the other landmarks are. Write and , wrapping the bearing component of the innovation to . For example, bearings just below and just above are close to one another, not almost a full revolution apart. The EKF correction is The first two equations are familiar from localization. Look more closely at the rows of corresponding to a different landmark . Write for the block of with the rows of and the columns of , and for the block with the rows of and the columns of . Since is nonzero only in the columns of and , these rows are Although the measurement function does not depend on , this gain need not be zero. If it is nonzero, an observation of landmark can change our estimate of landmark through the correction . We do not need to observe again in order to refine its position. Think of walking through a town without GPS. You count your steps and mark each shop on a paper map where you think it is. Your position error grows as you walk, and each shop gets the error you had when you marked it. After an hour you return to your hotel and find that your map puts you 200 m east of it. You correct your own position, and you also move the shops you marked late in the walk west, because they carry the same error. You never saw those shops again. The cross-covariances and hold this shared error. When the robot returns to a previously visited area, observations of familiar landmarks can therefore correct portions of the map that are no longer visible. This is the role of loop closure in EKF SLAM. The correction depends on the cross-covariances and on the quality of the association; it is not guaranteed to improve every estimate in a particular realization.Unknown correspondences
In practice, the sensor reports a range and bearing but may not identify the landmark. If several landmarks look alike, we must first decide which entry in the map corresponds to the observed landmark. We may also be seeing a landmark for the first time. For an observation and a candidate landmark , define the squared Mahalanobis distance again wrapping the bearing residual. In the correspondence estimation section, we derived the maximum likelihood criterion . The EKF SLAM algorithm in Table 10.2 of Thrun, Burgard and Fox uses just . The criteria agree when the innovation covariances have the same determinant, and may give different associations otherwise. The algorithm uses a threshold to decide whether any existing landmark is a plausible match. If the smallest distance exceeds , the implementation initializes a new landmark. For approximately Gaussian, correctly associated innovations, is approximately chi-squared with two degrees of freedom. The implementation uses , close to the 99.9th percentile. Thus a correct association would fail this gate about once in a thousand measurements under the ideal model. This does not mean that a newly initialized landmark has a 99.9% probability of being real, or that a false association is equally unlikely.Adding a landmark
Suppose the measurement comes from a new landmark. Given a range and bearing , we can estimate its position from the current pose by inverting the observation model: This construction requires both range and bearing. A monocular bearing-only measurement does not determine depth from a single view; triangulation requires another view with sufficient parallax (or additional information). We return to this in visual SLAM. The new landmark is uncertain for two reasons: the robot pose is uncertain, and the range and bearing are noisy. Both must enter its covariance. Let and be the Jacobians of the placement function above with respect to the pose and measurement. Using first-order uncertainty propagation, assuming the measurement noise is independent of the existing state, we obtain Here consists of the three pose rows of the existing covariance. The block therefore includes the new landmark’s cross-covariance with every existing state component. Append the two new coordinates to the mean and augment the covariance: This is the inverse-measurement initialization used in the implementation, following Corke (Corke, 2023). Thrun, Burgard and Fox instead start each new landmark from a diffuse prior. For subsequent observations in the same time step, use the current estimate and covariance in place of the predicted quantities above. The first observation of an otherwise unconstrained new landmark cannot tell us where the robot is in the world. Any shift in the robot pose can be accommodated by placing the landmark accordingly. We use this measurement to initialize the landmark; we must not then reuse the same measurement as an independent correction. A later observation provides a constraint between the new robot pose and the stored landmark estimate.Limitations of EKF SLAM
The preceding discussion assumes correct landmark associations, stationary landmarks, and a sufficiently accurate linearization. Each assumption has practical consequences. The pose and map are defined relative to a reference frame. Without an external position or heading reference, translating or rotating the entire trajectory and map together leaves the relative measurements unchanged. We usually choose the initial pose to define the world frame. Loop closure improves the internally estimated geometry, but does not supply an absolute geographical reference. The EKF approximates a nonlinear posterior by a Gaussian. Large uncertainty, particularly in heading, can make the local linearization inaccurate. Repeated linearization can also make the estimator overconfident in directions that are not observable (Huang et al., 2010). A small reported covariance is not by itself evidence of a correct map. A wrong correspondence can cause a large correction to the pose and map. The nearest-neighbor method described here does not revisit earlier association decisions. Practical systems may maintain provisional landmarks, reject ambiguous observations, or remove landmarks that repeatedly fail to be detected. The simple implementation does not use missed detections as measurements. That is a limitation of its observation model, not a general prohibition on incorporating negative information into probabilistic estimation. Finally, with landmarks the covariance has entries. A single measurement has a two-dimensional innovation, so the correction can be computed as a rank-at-most-two update in time. Computing as a general dense matrix product instead can cost . A full search through candidate landmarks also adds work. The implementation uses only eight landmarks, so clarity of the code is more important than exploiting every available sparsity. For larger maps, methods such as FastSLAM, submaps, and sparse information filters avoid some of the costs of the dense joint covariance. Graph-based SLAM takes a different approach, retaining pose and measurement constraints and exploiting the sparsity of the resulting optimization problem. See Thrun, Burgard and Fox, Chapters 12 and 13, for the former approaches.From theory to implementation
In the next section, we will run EKF SLAM on a TurtleBot in a room whose landmarks are eight identical pillars. The LIDAR and depth camera provide different ways of obtaining range-bearing observations, but the prediction, correction, and landmark initialization equations are the same. As you examine the resulting maps, pay particular attention to what happens when a landmark is observed again after a period of motion.Notation reference
Lectures
Key references: (Thrun et al., 2005; Corke, 2023; Dissanayake et al., 2001; Huang et al., 2010)
References
- Corke, P. (2023). Robotics, vision and control: Fundamental algorithms in python. DOI
- Dissanayake, M., Newman, P., Clark, S., Durrant-Whyte, H., Csorba, M. (2001). A solution to the simultaneous localization and map building (SLAM) problem. IEEE Trans. Rob. Autom. DOI
- Huang, G., Mourikis, A., Roumeliotis, S. (2010). Observability-based rules for designing consistent EKF SLAM estimators. Int. J. Rob. Res. DOI
- Thrun, S., Burgard, W., Fox, D. (2005). Probabilistic Robotics. Link
Found an error on this page? Report an issue.

