Localization of mobile agents

by Daniel Pollithy

In this post I am going to try to explain the basic concepts of localization of mobile agents which I have learned in the lecture “Lokalisierung mobiler Agenten” at the KIT.

The main outline:

  • Wheel and vehicles (one lane kinematic model and differential model)
  • Systems and discretization
  • Euler method
  • Dead reckoning
  • Example: Error accumulating with constant velocity model
  • Static localization (measurements, objective function and least squares)
  • Angular measurements (atan2)
  • Distance measurements (linearizing)
  • Example: GPS
  • Recursive Least Squares
  • Bayesian Filtering Framework (Linear Gaussian Model)
  • Dynamic localization (fusioning principles: BLUE, naive fusion, recursive fusion)
  • Kalman Filter (derivation, optimality)
  • Example: Tracking Car position and velocity
  • Nonlinear Filtering (EKF, UKF, Particle Filter)
  • EKF
  • Wonham Filter
  • Bingham Quaternion Filter
  • SLAM
  • Online SLAM (EKF-SLAM)
  • Full SLAM (Graph-SLAM)
  • Example: EKF-SLAM for 3d pose
  • FAQ

Localization of Mobile Agents

Wheel and vehicles

As we don’t want to spend too much time on modeling forces and we assume that our mobile agents drive with moderate velocity on wheels we use the idealized wheel.

  • It has a radius r, a wheel velocity ,
  • no slip in lateral direction
  • no slip in longitudinal direction.
  • It has point contact to the ground and
  • only rolls into the direction of the steering angle
  • it has no roll resistance.

The Instantaneous Center of Rotation (ICR, “Momentanpool”) is the point where the wheel axis intersect. There are four different cases with our model:

  1. The axes meet at a point inside our outside of the vehicle and move on a circular path around the ICR.
  2. The wheel axes are on the same line. This is the case for the differential drive. The position of the ICR is controlled by the difference of the wheel velocities. If their difference is zero then ICR lays between the wheels.
  3. If wheel axes are parallel then the ICR is located at infinite distance. The vehicle is driving forward without a curved path.
  4. The wheel axes do not intersect at a single point. Within our model the vehicle is unable to move. Other models can handle this but they are a little bit more complex. For example: The dynamic one track model which models the slip angles of the wheels.

The magnitude form of the euler velocity equation (“Betragsform der eulerschen Geschwindigkeitsgleichung”) is used to set the angular velocity and the vehicle velocity into relation.

where is the angular velocity, v the vehicle velocity at a point at the vehicle and p the line from the ICR to the point.

For two different points p1 and p2 on the vehicle with different velocities v1 and v2, we can also use:

Kinematic one track model

lma_1.jpg

Differential drive

lma_2.jpg

Note: If the ICR is at the center of the axis between the two wheels.

Systems

Let be the state of the system, the controllable inputs and the uncontrollable changes to the state (like noise). The system equation holds. A simple specialization of this equation which we are going to use:

If we manage to design in form a linear function then we can write our system in the following form and call it a Linear System:

In the case that the system’s behavior does not change over time, we call it a Linear Time-invariant System (LTI):

In order to access the state of the system at a point in time we can use the the solution for the time-continuous linear time-invariant system:

Discretization

Computers generally do not know how to solve time-continuous differential equations. The main problem is “how to solve the integral”? It is also difficult for humans if the antiderivative cannot be calculated.

For the use in digital computers we have to discretize the with respect to time, only then can we use it together with the discrete state sampling rate. So we introduce discrete timesteps .

Now we assume that the input signal is constant between two timesteps:

Because the system is time-invariant we see that everything expect the x(t) and u(t) is constant, which leads us to the following discrete form:

So we still have an integral here. How do we get A’ and B’?

With the use of the Laplace transformation if possible or numerical approximations.

Euler method

Given a differential equation which describes the system dynamics we want to calculate the state of the system after time t.

We use the Euler Method. It tries to fit small rectangles under the curve of which we want to calculate the integral. If we use the height of the function at timestep as the height of the rectangle we call it Forward/explicit euler. If the we use the height at then it’s called Backward euler.

The backward euler is a little bit extra effort because you have to solve an equation to get to the next state but it has the advantage of being stable (solution can be found with the Newton method).

Instead of using the quotient of differentials we have to use the difference quotient.

In Matlab a continuous system can be transformed numerically with the command c2d: sys_disc = c2d(sys_cont,Ts)

Until rounding errors happen in the computer, a smaller leads to a better approximation.

Solution 3

Constant acceleration or constant velocity models.

Dead reckoning

Definition:

The task of dead reckoning is to get the pose of an object with respect to an external coordinate system.

To solve this task formulate a motion model in the object’s coordinate system.

Advantages:

  • High sampling rate
  • No infrastructure needed
  • low latency

Disadvantages:

  • Pose is only relative
  • Accumulated error which leads to drift

How it works: We measure increments from the last state (change of place, velocity or acceleration). And then we use this measured information as system input to our discrete system model in order to calculate where our current position should be next.

“Schritthaltend”: Abtastrate höher als Rechenzeit für neuen Zustand.

Error

The total error of a linear system depends on all noise vectors:

For linear systems: The longer ago the error has been added, the more influence it has, because the exponentiated system matrix usually becomes larger over time:

Important Note: When talking about the error it is important to realize that the error is not the difference between the estimate and the measurement but it is the difference between the ground truth and the estimate!

(The ground truth could be manually annotated or retrieved with another system, for example with a VICON or GPS)

Static localization

Sensors measure absolute pose in world coordinates.

Advantage

  • No increasing error (“keine Fehlerfortpflanzung”)

Disadvantage

  • External infrastructure necessary

Measurement principles

  • Time-of-Flight
  • Radar
  • visual (cameras)
  • strength of a signal (WLAN, Bluetooth, GSM)

The measurement function z = h(x) generates a measurement from the true pose of the robot.

Example 1: Trilateration

You want to localize the robot by measuring the distance to point landmarks.

lma_3

The ith measurement is the distance to the point i (with coordinates p_x and p_y). The robot’s position is x_x, x_y.

ToDo: Linearize!

The vector z contains the measurements to all the landmarks: And we assume that the measurement function h(x) produced this vector .

This leads us to a non-linear least squares (LSQ) problem with the objective function and the weighting matrix W (pos. definite):

The weighting matrix allows us to express our knowledge about the measurements. Whether we want to trust the measurement of one sensor more than others.

Once we solve this optimization problem we will localize the robot. If we cannot write the measurement function as a linear equation then we could do this numerically.

If we can write the function as a linear equation then we can solve the problem analytically by deriving it, setting the derivation to zero and solving for x. (If we do not knew the orientation of the parabola then we would also have to check whether the optimum is a minimum or a maximum by checking the sign of the second derivation).

Example 2: Trilateration with walls

Let’s go back to the example and see whether we can reformulate the measurement function. Let’s assume that the landmarks are points on walls of a room.

In this case we can model the walls with Hesse’sche Normalform with and the distance to the wall.

lma_4

The distance to the ith wall is

Which is a linear equation.

In the easiest case where we have exactly as many observations as state variables we obtain a quadratic measurement matrix:

=>

We see that it would be convenient to always use a quadratic measurement matrix H but it has the downside that we would not use all of our measurements if we have more walls in the room and therefore we would be more error prone if one of the sensors returns a noisy value.

Least Squares

That’s why we come back to the LSQ which minimizes the sum of the squared errors between our measurements and the estimated state.

Multiplying the terms:

Derive:

Set to zero:

Checking the second derivative:

Check whether it is positive definite:

Important: H has to have at least full column rank otherwise the first bracket could not be inverted. This means that the columns have to be linearly independent of each others. Full column rank is the same as saying that rank(H) = dim(x) which enough to make rank(H) >= dim(x) true.

Note: If the weight matrix W is only semi-definite then the matrix then the inversion is not uniquely determined (infinite solutions). We can still choose one by picking the with the smallest norm ||x||^2.

How to choose W? Diagonal matrix, positive definite. A large entry on the diagonal like 999 becomes 1/999 after inverting the matrix. And the multiplication with such a small value nearly cancels its influence onto . Therefore: Large values in W result in mistrust for the related sensor value.

Example 3: Triangulation

If we can’t measure the distance to known landmark there might be the possibility to measure the angle.

The measurement equation:

is not linear.

A quick reminder. The tan(x) looks like this:

Which is undefined at 90 degree because it is sin(90) / cos(90) and cos(90) is zero.

The atan2 is defined as the angle between the x axis in the range between ]-pi, pi]:

It resolves the ambiguity that -90 degree is the same as 270 degree.

Recursive Least Squares

The normal least squares method has the downside of processing all measurements in one matrix. In reality the measurements are obtained incrementally and we do not want to repeat the processing of the measurement matrix again and again. Especially when it is becoming larger and larger.

The recursive least squares fusions the last result with the newly obtained measurement. The measurement matrix’s size stays constant and therefore the processing time.

We are now going to work with batch matrices. They are matrices whose entries are matrices themselves.

It is important that the block weight matrix W is a diagonal matrix. If that is not the case then we have to diagonalize it: .

Note: can be calculated independently if H and W are independent of the measurements. With this in mind we see that with ~= 0

We obtain recursive equations which we can solve for every timestep in constant time. But how do we start the recursion?

There are two options:

  1. Wait until we have N measurements where N = dim(x). Then H is quadratic so we easily invert it directly. And we calculate
  2. We initialize x with the zero vector and set its uncertainty to infinite by defining where I is the identity matrix and a large positive number.

Information form

With the relationship:

we can transform the prediction:

… to:

Wikipedia states: In the information filter, or inverse covariance filter, the estimated covariance and estimated state are replaced by the information matrix Y and information vector y respectively.

We multiply on both sides left:

And the Inverse Covariance matrix is calculated like this:

But why?

  • In this inverse formulation of the covariance matrix we can define infinite mistrust with a simple zero
  • As long as we do not need any steps in between, we can calculate the information matrix and information vector separated from each others
  • Biggest advantage according to Wikipedia: “The main advantage of the information filter is that N measurements can be filtered at each timestep simply by summing their information matrices and vectors.” (“Kovarianz wird additiv”)

Bayesian Filtering Framework

We are going to approach the localization from a probabilistic context. We treat the state as a probability density function over the state space with its expectation value as the most likely position and the covariance matrix of the pdf as the measure of uncertainty.

This is equivalent to hidden markov models.

Estimate the current state after all the measurements of the past:

With the Markov assumption:

The partition function might not be tractable therefore we continue with a term which is proportional to the last one:

is a probabilistic form of the observation model.

The probability of a state given the past observations is the prediction problem:

We can marginalize this:

If we assume time invariance then we can write:

is the probabilistic version of the system model.

And is the question where we started but one timestep earlier. So we see that we can solve this problem with recursion.

The main problem with this is the integral after the marginalization. A restriction is necessary to solve it.

Linear Gaussian Model

“A linear-Gaussian model is a Bayes net where all the variables are Gaussian, and each variable’s mean is linear in the values of its parents. They are widely used because they support efficient inference. Linear dynamical systems are an important special case. “ - metacedemy

Where:

  • is the system model
  • the input matrix
  • u(k) the controllable input vector
  • the normally distributed white process noise (-> mean=0, cov=)
  • the measurement matrix
  • the normally distributed white measurement noise (cov=)

As a result: x(k) and z(k) are also random variables with and measurement uncertainty .

Summary: The state and the measurement are random variables. The Bayesian Framework is helpful to see how a filter should calculate the posterior distribution from the prior distribution, measurements, the measurement model and the system model. The mentioned restriction of the motion model leads to the fact that we have only one possible predecessor for a given state. As a result, we do not have to build the integral in the Bayesian Framework anymore.

Filter Step without priori knowledge

“Filterschritt ohne Vorwissen”

We start with the measurement equation of the linear system.

Attention: dim(z_k) >= dim(x_k) and H full column rank.

A first non-formal way is to use the deterministic Least Squares for the random variable mapping with the unknown weight matrix W:

And then determine the first and second moment:

Expectation value:

Covariance matrix:

This solution contains the unknown weighting matrix and has no proof of optimality in any way.

Therefore the next step is to derive a better solution with formal restrictions:

  1. Affine estimator (“linear”)
  2. Unbiased
  3. Minimum covariance (“best”)

These requirements form the “Best Linear Unbiased Estimator” (BLUE)

We start with an affine estimator:

We require (2) that the expectation value of the estimator is the same as of the real value (which is unknown)

Now we use the measurement model:

has to be zero in order to let the estimator be unbiased:

Now we add that the expectation values should be the same:

This brings us to the following relationship which is not unique.

This is where our third requirement comes into play: We want the Cov(x_k^e)=C_k^e to be minimal. We can formulate this demand with the inverted observation model and the least squares approach:

with

We calculate the covariance matrix like this:

Note: We get the same result for the formal approach and the initial least squares solution if we use the covariance matrix of the measurement as our weighting matrix.

Optimal fusion

Now we have the case that there are two unbiased but uncertain state estimations with covariance and with .

  1. Linear estimator
  1. Unbiased

and are unbiased.

We can reduce the amount of work by only defining one weighting matrix K and its opposite:

And plug it into the estimator:

The covariance matrix of the estimator becomes:

As with the filter step without bias, we want the uncertainty of the combination to be minimal. We achieve this by projecting the covariance matrix onto a unit vector, deriving this projection, setting the derivate to zero and then solve for the optimal K.

Projection:

Derivative:

Set to zero:

Finally the optimal fusion of two unbiased states:

With the new Cov:

Prediction

First of all we rewrite our linear model a little bit. We assume that the input random vector is a sum of a known input vector and process noise .

The expectation value of the prediction becomes:

Under the assumption that the system noise is not correlated to the old state we obtain the new covariance matrix:

Dynamic Localization

Use the optimal fusion, dead reckoning and prediction to build the naive recursive estimator.

Important: Because we are going to calculate a full state from the given measurement we have to require the

It works as follows:

  1. Get a measurement z
  2. Deduce a state variable from z and C_z
  3. Use the system dynamics to predict the state variable until we have a new measurement
  4. Deduce a new state from the new measurement
  5. Use a BLUE estimator which fusions the predicted state and the deduced state from the new measurement

Kalman filter step

In the Kalman filter step we assume that the dimension of the measurement vector is smaller than the dimension of the state vector and we have priori knowledge.

When a new measurement arrives, the predicted state and the measurement matrix are used to “generate” a predicted measurement that gets compared to the true measurement. The difference between both is called the innovation and it is used to correct the predicted state.

We are looking for a BLUE estimator again:

Linear estimator:

shall be unbiased (the predicted estimation and the z_k are also unbiased):

Third requirement: Minimum variance. Again with projection onto a unit vector and minimizing we get:

A popular interpretation of the Kalman filter step uses a different formulation of the filter:

The difference in the brackets is called “innovation”. And the difference is multiplied by the Kalman Gain Matrix. In block diagrams this can be written as a controller (more specific a “regulator”) that regulates the difference between the measurement and the projected measurement to zero with a proportional factor of K.

Recursive Kalman estimator

The recursive Kalman estimator works the same as the recursive estimator but it uses the Kalman filter step. This means that a new measurement is not transferred into state space instead it gets compared directly to a predicted measurement of the predicted state. The difference is multiplied by the Kalman gain and added to the predicted to state. This way the Kalman filter only stores the mean and covariance of the state estimation and it also does not get more complex with the number of used measurements.

Approximation of general systems

When we are dealing with a nonlinear system and we can’t trick it into linearity then we have to linearize it.

If we don’t do this, then the main problem becomes that we are not mapping from gaussian to gaussian. The following image shows the blue gaussian curve projected by a linear function h(x) and by a nonlinear function h’(x).

We solve this by linearizing the system model and the measurement model . Why? Because all of our equations until now only work with matrices A, B and H.

The first order Taylor polynomial is used:

is the jacobi matrix of function around the point containing the partial derivatives only after u.

This is a linear equation but it still does not look like the system equation that we need for our Kalman filter.

But if we stop modelling the full state of the system and only track the difference between the states () we get the form in which we are interested:

Note: If the system was time invariant or the development point around which we linearized was an equilibrium point, the Jacobi matrices are also time invariant.

We linearize the measurement model in the same way:

The Extended Kalman Filter (EKF) is the regular Kalman filter using these linearized equations.

The predicted state is the linearization point.

???

ToDo: Mitschrieb Vorlesung 12

???

UKF

The problem with EKF is that large uncertainties or large s are not transformed correctly when the nonlinear function is only linearized at one place.

Therefore the Unscented Kalman Filter uses so called sigma points to represent remarkable points of the input normal distribution, transforms them with the nonlinear function and reestimates a new normal distribution from the new sigma points.

Particle Filter

The procedure of the UKF is already close to the Particle filter. Here we represent the priori distribution with particles instead of a parametric function. Then the particles are transformed by the nonlinear function. The function might not be deterministic, it could add random noise.

The predicted particles are weighted according to a distance measure of a new measurement. For example: Particles which are close to the real measurement get a large weighting.

In order to avoid degeneration of the particles we resample the particles by sampling the same number of particles but not uniformly. The distribution from which we sample is the distribution of the samples.

As a result we obtain many particles near the location where a single particle with large weight had been. And random other particles.

The particle filter is also called Sequential Monte Carlo.

SLAM

Simultaneous Localization and Mapping is a “Chicken and Egg” problem. We don’t know the pose of the robot and neither the positions of the landmarks but we want to create a map and localize the robot within.

Challenges:

  • Nonlinearities
  • Data association: which measurement belongs to which landmark
  • Complexity of big maps
  • Non-static environment

Approaches for 2d SLAM:

  • Online SLAM -> Map and last pose. The state contains the last pose and the landmarks: . It has a size of 3 + 2L. The Covariance matrix has the size squared entries.
  • Full SLAM -> Map and trajectory The state contains 3k + 2L entries.

EKF SLAM

Initialization:
  1. Naive init: Estimate the number of landmarks the robot is going to see and initialize the values with zero and infinite uncertainty
  2. Preferred init: Start with a small state vector and expand it every time a new landmark has been measured.

Whether it is a new landmark or a measurement belongs to an already known landmark is called the data association problem and an easy approach is to use 1-Nearest-Neighbour with the Mahalanobis distance that gets weighted according to the uncertainty of the landmarks. If this distance is above a threshold we see a new landmark.

Prediction:

The landmarks are static accordingly they do not move and no change in position has to be predicted. The robots moves as usual. The dead reckoning then adds uncertainty to the robot pose and consequently we also have to increase the uncertainty between the landmarks and the robot’s pose but the uncertainty between landmarks is not updated.

Attention: For the prediction of the mean we just apply the nonlinear motion model to the robot’s pose: . For the prediction of the covariance matrix we do have to linearize with the Jacobi matrix J_{A_k}.

is an all zeros matrix except for the robots covariance which gets an additive noise term due to the system noise.

Only the first column and first row are updated by the prediction step:

Complexity: The prediction step is linear in the number of landmarks.

Filtering

The robot measures an angle and the distance to a landmark. Now we have got two different cases:

  1. Landmark has not been seen before
  2. Landmark has already been measured

Unknown Landmark:

If the landmark is new we initialize the position as follows:

where is the robots orientation. g(…) is the nonlinear function responsible for the mapping. L is the number of landmarks. These two new values are stacked into the state vector.

For the extension of the covariance matrix we have to linearize the function at the robot position and at the new landmark position with the Jacobian and .

is the measurement uncertainty.

With we can initialize the diagonal entry of the extended covariance matrix of the state vector but we also have to add the cross covariance between this landmark and the robot and between this landmark and the other landmarks i . We add these values in the row and column of the new landmarks covariance matrix.

The following image shows where the three new covariance matrices are added to the batch covariance matrix of the state:

2nd case: Known Landmark

We have a nonlinear measurement model which uses the estimated position of the landmark and the estimated position of the robot from the state in order to generate a measurement. The landmark and the robots position are extracted from the state using a selection matrix.

This function h(..) gets linearized and the Jacobi matrix is used to calculate the Kalman gain .

Complexity: The field of view is usually limited and the robot never observes all of the landmarks that is has in its map. The complexity of the matrix inversion in order to calculate the Kalman gain is cubic in the number of observed landmarks but the number of observed landmarks is « total landmarks in the map.

Update

Now we can update the state estimation and its covariance matrix in the previously described EKF way.

Complexity: The update changes all entries of the covariance matrix. Therefore this is quadratic in the number of landmarks. This operation dominates the EKF.

Note: The correlation between the landmarks and the robot is important and cannot be ignored. Otherwise the uncertainties decrease too fast and the robot would be overconfident about the positions of the landmarks and therefore fail.

The landmarks’ uncertainty decreases monotonically that means that they had the largest uncertainty at initialization.

The lower bound for the uncertainty is the robot’s pose uncertainty at the time it made its first landmark measurement. It can’t be lower that that unless other external information (like GPS) is integrated.

Graph SLAM

This is a full slam approach and I assume that the name comes from graphical model.

FAQ

  • How can we see that the Kalman filter minimizes the MSE? -> The Kalman Gain is chosen to minimize the Covariance matrix of the estimate. This matrix can be derived by minimizing the trace of of the covariance which is the same as the mean variance. Which is the same as the mean squared derivation of the correct value. Which is the mean squared error.