Skip to main content
Open In Colab The Markov localization section applies the Bayes filter to a robot with a known map, and contrasts global localization, where the initial pose is unknown, with tracking, where it is approximately known. This section treats the tracking case with a Gaussian belief, first in one dimension and then for a ground robot with the extended Kalman filter.

Tracking

Just like localization, tracking can refer to location prediction of the agent itself or the objects that the agents perceives in its environment. For tracking we are given the initial pose s0s_0 that is approximately known. It is common to initialize the belief with a narrow Gaussian distribution around s^0\hat{s}_0. bel(s0)=N(s0−s^0,Σ)\mathtt{bel}(s_0) = \mathcal{N}(s_0-\hat s_0, \Sigma) Lets look at a similar example to the localization problem: robot-doors-problem Example environment for tracking - a hallway with three identical and labeled doors The original belief is a normal distribution centered around door 1 where the agent is initially placed. As the robot moves to the right, its belief is convolved with the Gaussian transition / motion model. The resulting belief is a shifted Gaussian of increased width. Now suppose the robot detects that it is in front of door 2. Folding this measurement probability into the robot’s belief yields the posterior shown in (c). Note that the variance of the resulting belief is smaller than the variances of both the robot’s previous belief and the observation density. This is natural, since integrating two independent estimates should make the robot more certain than each estimate in isolation. After moving down the hallway, the robot’s uncertainty in its position increases again, since the tracker continues to incorporate motion uncertainty into the robot’s belief.

EKF localization with known correspondences

The hallway examples use a one-dimensional state. A ground robot such as the TurtleBot has the pose st=(x,y,θ)s_t = (x, y, \theta), and the extended Kalman filter tracks a Gaussian belief over it. Like the tracking example above, EKF localization needs a good initial guess: the belief is a single Gaussian, so it cannot represent the multimodal beliefs of global localization. The map mm is a set of point landmarks with known positions mj=(mj,x,mj,y)m_j = (m_{j,x}, m_{j,y}). At each step the robot measures the range rtir^i_t and the bearing ϕti\phi^i_t to every landmark it can see, zti=(rti,ϕti)z^i_t = (r^i_t, \phi^i_t). Known correspondences means that it also knows which landmark produced each measurement: the correspondence variable cti=jc^i_t = j names the landmark. A robot gets this for free when every landmark carries a unique code, such as a fiducial marker whose ID the camera reads.

Motion model

The action is the pair of wheel speeds at=(uL,uR)a_t = (u_L, u_R). As in the EKF section, they set the forward speed v=r2(uL+uR)v = \frac{r}{2}(u_L + u_R) and the turning rate ω=r2d(uR−uL)\omega = \frac{r}{2d}(u_R - u_L). Holding vv and ω\omega constant for Δt\Delta t moves the robot along an arc of radius v/ωv/\omega: g(at,st−1)=[x−vωsin⁡θ+vωsin⁡(θ+ωΔt)y+vωcos⁡θ−vωcos⁡(θ+ωΔt)θ+ωΔt].g(a_t, s_{t-1}) = \begin{bmatrix} x - \frac{v}{\omega}\sin\theta + \frac{v}{\omega}\sin(\theta + \omega\Delta t) \\ y + \frac{v}{\omega}\cos\theta - \frac{v}{\omega}\cos(\theta + \omega\Delta t) \\ \theta + \omega\Delta t \end{bmatrix}. Its Jacobian with respect to the state is Gt=[10vω(cos⁡(θ+ωΔt)−cos⁡θ)01vω(sin⁡(θ+ωΔt)−sin⁡θ)001],G_t = \begin{bmatrix} 1 & 0 & \frac{v}{\omega}\left(\cos(\theta + \omega\Delta t) - \cos\theta\right) \\ 0 & 1 & \frac{v}{\omega}\left(\sin(\theta + \omega\Delta t) - \sin\theta\right) \\ 0 & 0 & 1 \end{bmatrix}, evaluated at μt−1\mu_{t-1}. The noise comes from the wheels. Each wheel turns at its commanded speed plus Gaussian noise, with covariance MtM_t in wheel-speed space. The Jacobian Vt=∂g/∂atV_t = \partial g / \partial a_t maps that noise into the state, so the motion noise covariance is Rt=VtMtVt⊤R_t = V_t M_t V_t^\top.

Measurement model

For landmark jj, write δ=(mj,x−x,  mj,y−y)\delta = (m_{j,x} - x,\; m_{j,y} - y) and q=δ⊤δq = \delta^\top\delta. The predicted measurement and its Jacobian are h(st,j,m)=[qatan2⁡(δy,δx)−θ],Hti=1q[−q δx−q δy0δy−δx−q],h(s_t, j, m) = \begin{bmatrix} \sqrt{q} \\ \operatorname{atan2}(\delta_y, \delta_x) - \theta \end{bmatrix}, \qquad H^i_t = \frac{1}{q}\begin{bmatrix} -\sqrt{q}\,\delta_x & -\sqrt{q}\,\delta_y & 0 \\ \delta_y & -\delta_x & -q \end{bmatrix}, evaluated at the predicted mean μˉt\bar\mu_t, with measurement noise covariance Qt=diag⁡(σr2,σϕ2)Q_t = \operatorname{diag}(\sigma_r^2, \sigma_\phi^2).

The algorithm

One step takes the previous belief, the action, the measurements and their correspondences, and the map: 1:μˉt=g(at,μt−1)2:Σˉt=Gt Σt−1 Gt⊤+VtMtVt⊤3:for each observed feature zti with j=cti:4:z^ti=h(μˉt,j,m),and Hti at μˉt5:Kti=ΣˉtHti⊤(HtiΣˉtHti⊤+Qt)−16:μˉt←μˉt+Kti(zti−z^ti)7:Σˉt←(I−KtiHti)Σˉt8:μt=μˉt,Σt=Σˉt\begin{array}{ll} 1: & \bar\mu_t = g(a_t, \mu_{t-1}) \\ 2: & \bar\Sigma_t = G_t\, \Sigma_{t-1}\, G_t^\top + V_t M_t V_t^\top \\ 3: & \text{for each observed feature } z^i_t \text{ with } j = c^i_t: \\ 4: & \qquad \hat z^i_t = h(\bar\mu_t, j, m), \quad \text{and } H^i_t \text{ at } \bar\mu_t \\ 5: & \qquad K^i_t = \bar\Sigma_t H^{i\top}_t \left(H^i_t \bar\Sigma_t H^{i\top}_t + Q_t\right)^{-1} \\ 6: & \qquad \bar\mu_t \leftarrow \bar\mu_t + K^i_t \left(z^i_t - \hat z^i_t\right) \\ 7: & \qquad \bar\Sigma_t \leftarrow \left(I - K^i_t H^i_t\right) \bar\Sigma_t \\ 8: & \mu_t = \bar\mu_t, \quad \Sigma_t = \bar\Sigma_t \end{array} The loop folds in one landmark at a time. Each update starts from the belief left by the previous one, which is exact for a linear-Gaussian model when the measurement noises are independent. The bearing residual in line 6 is wrapped to (−π,π](-\pi, \pi], since an angle error of 2π−0.012\pi - 0.01 is really −0.01-0.01. This algorithm follows the EKF localization algorithm in Chapter 7 of Probabilistic Robotics (Thrun, Burgard and Fox), with ss for the state, aa for the action, and wheel speeds for the action.

One step with one landmark

Start with a single step, the setting of the EKF section. The robot drives straight down the page, at heading θ=−90°\theta = -90°, at 0.25 m/s for 4 s. Its belief knows the starting position to 2 cm but the heading only to 30°30°, and the motion noise is left out to isolate the heading. A single landmark, m1=(0,−2)m_1 = (0, -2) m, stands straight ahead. The robot’s true heading during the drive was 25°25° off the nominal one, so it really stopped at about (0.42,−0.91)(0.42, -0.91) m. From there its sensor measures the range and bearing to m1m_1, with noise σr=5\sigma_r = 5 cm and σϕ=2°\sigma_\phi = 2°. The code runs one step of ekf_localization. For comparison it also computes the exact posterior: it pushes samples of the starting pose through gg, weights each one by the likelihood of the measurement, and resamples.
Output from cell 5 The predicted samples form the banana from the EKF section, opening upward because the robot drives down the page. The EKF’s prediction ellipse is wide in xx, where a heading error moves the robot sideways. In yy, the direction of travel, it is only 2 cm tall, because the Jacobian passes no heading uncertainty into the forward position. The two parts of the measurement do different jobs. The bearing, −0.82-0.82 rad or about −47°-47°, puts the landmark well to the robot’s right. Only samples on the right arm of the banana agree with that, so the bearing removes the left-right ambiguity that a range alone would leave. The EKF uses it too. At the predicted mean the bearing row of HtH_t couples xx and θ\theta, and the update moves the mean to x=0.41x = 0.41 m, close to the true 0.42 m, with 2 cm of uncertainty. The range, 1.257 m against a predicted 1.0 m, says the robot stopped short. Here the EKF falls short. Its predicted yy uncertainty was only 2 cm, so it moves yy only from −1.0-1.0 to −0.965-0.965 m, and the true y=−0.906y = -0.906 m ends up about three of its standard deviations away. The exact posterior, centered at (0.44,−0.89)(0.44, -0.89) m, has no such problem. This is the overconfidence from the EKF section, now inside a localization step.

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 range-bearing sensor sees a landmark only within 1.5 m, so on parts of the circle no landmark is visible. Each wheel of the simulated robot turns at its commanded speed plus noise, with a standard deviation of 5% of the speed plus 0.1 rad/s. The filter knows this noise model, which gives it MtM_t. The sensor noise is the same as in the single step. The filter starts from the true pose with a small uncertainty. For comparison, the same filter also runs without any measurements, which is dead reckoning from the wheel speeds alone.
Output from cell 7 Output from cell 8 The first figure shows the paths and every tenth 2σ2\sigma ellipse of the EKF. Without measurements the estimate drifts: after 70 s dead reckoning is 35 cm from the true position, against 9 cm for the EKF. The EKF ellipses grow while no landmark is in view and shrink again as soon as one comes into range, the same pattern as the hallway tracking example, now in two dimensions with heading. The second figure checks whether the filter is honest about its uncertainty. A consistent filter keeps its error inside the ±2σ\pm 2\sigma band about 95% of the time. The band widens in the gray stretches with no landmark in view and narrows when a landmark appears. Here the robot drives on gentle arcs and its heading uncertainty stays small, so linearization works well: the error stays inside the band at 98 to 99% of the steps. With a wide heading belief the same filter can become overconfident, as the EKF section shows. Key references: (Sabinasz, 2017; Li et al., 2018; Khan et al., 2004; Hofmann et al., 2013; Peršić et al., 2019)

References

  • Hofmann, M., Wolf, D., Rigoll, G. (2013). Hypergraphs for Joint Multi-view Reconstruction and Multi-object Tracking. 2013 IEEE Conference on Computer Vision and Pattern Recognition.
  • Khan, Z., Balch, T., Dellaert, F. (2004). A Rao-Blackwellized particle filter for EigenTracking. Proceedings of the 2004 IEEE Computer Society Conference on Computer Vision and Pattern Recognition, 2004. CVPR 2004.
  • Li, X., Ylioinas, J., Kannala, J. (2018). Full-Frame Scene Coordinate Regression for Image-Based Localization. arXiv [cs.CV].
  • Peršić, J., Petrović, L., Marković, I., Petrović, I. (2019). Spatio-Temporal Multisensor Calibration Based on Gaussian Processes Moving Object Tracking. arXiv [cs.RO].
  • Sabinasz, D. (2017). Robot Localization II: The Histogram Filter.

Found an error on this page? Report an issue.