Kalman: Unterschied zwischen den Versionen

Aus www.wiki.ardumower.de
Wechseln zu: Navigation, Suche
(Idee)
(Idea)
 
(3 dazwischenliegende Versionen desselben Benutzers werden nicht angezeigt)
Zeile 1: Zeile 1:
 
=Idea=
 
=Idea=
  
You have...
+
For the Extended Kalman Filter (EKF) you have...
  
# A description of a robots state at every time (e.g. actual heading, actual heading speed).  
+
# A model of a robots state at every time (e.g. actual heading, actual heading speed).  
 
# A certain number of sensors. Each sensor has a certain measurement error (%).  
 
# A certain number of sensors. Each sensor has a certain measurement error (%).  
  
Zeile 11: Zeile 11:
 
# Correct: we correct the certaincy based on new measurements for each sensor. Does the prediction fit to the sensor measurement, we increase certaincy for that sensor, otherwise we decrease certaincy.
 
# Correct: we correct the certaincy based on new measurements for each sensor. Does the prediction fit to the sensor measurement, we increase certaincy for that sensor, otherwise we decrease certaincy.
  
=Beispiel=
+
=Example=
  
Wir haben einen Kurs (theta) und eine Drehwinkelgeschwindigkeit (omega). Den neuen Kurs kann man vorhersagen als den alten Kurs plus der Drehwinkelgeschwindigkeit mal der vergangenen Zeit:
+
We have a heading (theta) and a heading speed rate (omega). The new heading can be predicted by old heading plus heading rate and delta time:
  
 
  theta = theta_k+1 + omega * dt
 
  theta = theta_k+1 + omega * dt
  
  theta_k+1: neuer Kurs
+
  theta_k+1: new heading
  theta_k: alter Kurs
+
  theta_k: old heading
  omega: Drehwinkelgeschwindigkeit
+
  omega: heading speed rate
  dt: vergangene Zeit
+
  dt: delta time
  
Die Drehänderungsrate ist also modelliert als:
+
The heading speed rate is modelled after this:
 
    
 
    
 
   omega = omega_k+1
 
   omega = omega_k+1
  
Dies ist natürlich nur ein Modell. Die wahre Drehwinkelgeschwindigkeit wird sich oftmals ändern. Dies wird aber beim Kalman-Filter berücksichtigt. Diese beiden Zustands-Gleichungen können nun in Zustands-Raum-Form gebracht werden, welches in erster Linie eine Matrix-Darstellung der beiden Gleichungen ist:
+
This is a model only. The real heading rate will change. The Kalman considers this. Those both state equations can now be turned into state space form which is basically a matrix form of the two equations:
  
 
  x_k = A * x_k+1
 
  x_k = A * x_k+1
  
mit
+
with
 
   
 
   
 
  x = [ theta
 
  x = [ theta
Zeile 38: Zeile 38:
 
       0    1  ]
 
       0    1  ]
  
Wenn man die Matrizen-Gleichung ausmultipliziert, erhält man wieder die beiden Zustands-Gleichungen (probiert es aus!). Der Kalman-Filter benutzt noch weitere Matrizen:
+
If you muliply the matrix equation, you get again both state equations. Kalman filter also uses additional matrizes:
  
 
  y_k = C * yk+1  
 
  y_k = C * yk+1  
  
mit
+
with
 
   
 
   
 
  y = [ theta  
 
  y = [ theta  
Zeile 50: Zeile 50:
 
       0  1 ]
 
       0  1 ]
  
Dabei wandelt C die Meßwerte in die Zustandsvariablen um. Der Kalman-Filter beschreibt nicht nur den Zustand des Systems, sondern auch die Kovarianz Matrix P, welche beschreibt wie gut die Zustandsvariablen und ihre Meßwerte zusammen passen.
+
Matrix C transfers measurements into state variables. The Kalman filter also uses Covariance Matrix P which describes how well state variables and measurements fit.
  
Desweiteren benutzt Kalman eine Meßfehler Matrix R womit man dem Filter mitteilen kann wie stark der Meßfehler für jedes Signal geschätzt wird.
+
Furthermore, Kalman uses a measurement error matrix R where you can estimate the measurement error for each signal.
  
Zu guter letzt gibt es eine Prozessfehler Matrix Q welche den Fehler des Gesamtsystems modelliert (ungenaue Ansteuerung z.B).
+
Finally, there's a process error matrix Q which models the complete system error (due to noise in servos, motors etc).
  
 
=Scilab=
 
=Scilab=
  Beschreibung des Algorithmus mit Hilfe des kostenloen Mathematik-Paketes "Scilab":
+
  Kalman algorithm implemented with free math software "Scilab":
  
  % Initialisierung
+
  % initialize
  A=[1 dt; 0 1]; % Zustandsübergangsmatrix - gibt an wie wir vom aktuellen zum nächsten Zustand kommen
+
  A=[1 dt; 0 1]; % state transition matrix; represents how we get from prior state to next state
  C=[1 0; 0 1]; % Matrix bildet Mess-Zustand auf System-Zustand ab
+
  C=[1 0; 0 1]; % the matrix that maps measurement to system state
  P=[1000 0; 0 1000]; % Start-Kovarianz für anfängliche Unsicherheit
+
  P=[1000 0; 0 1000]; % sets the initial covariance to indicate initial uncertainty
  Q=[0.01 0; 0 0.01]; % Prozess-Fehler; Zum Anpassen/Spielen
+
  Q=[0.01 0; 0 0.01]; % process noise; I just picked some numbers; you can play with these
  R=[0.01 0; 0 0.01]; % Messfehler; Zum Anpassen/Spielen
+
  R=[0.01 0; 0 0.01]; % measurement noise; I just picked some numbers here too
  
  % Durchlauf das folgende für jede neue Messung
+
  % loop the following every time you get a new measurement
  
  % VORHERSAGE
+
  % PREDICT
  % wir sagen den nächsten System-Zustand vorher basierend of dem Wissen (Modell) unseres Systems
+
  % we predict the next system state based on our knowledge (model) of the system
 
  x = A*x;
 
  x = A*x;
  % Wir passen auch die Unsicherheit an. Wenn wir den Systemzustand ohne Messungen vorhersagen, steigt die Unsicherheit
+
  % We also have to adjust certainty. If we're predicting system state
  P = A*P*A' + Q; % Unsicherheit auch mit Zustandsübergang anpassen. Prozess-Fehler addieren
+
% without meausrements, certainty reduces
+
  P = A*P*A' + Q; % adjust certainty with the state transition, too. Add process noise
  % KORREKTUR
+
 
  % Mit den Messungen korrigieren wir die Zustands-Schätzung
+
  % CORRECT
  z=[gpsHdg; gyroHdgRate]; % Dies ist die Mess-Matrix
+
  % With measurements, we correct the state estimate
  % Zunächst Kalman-Verstärkung herausfinden; wie stark vertrauen wir der Schätzung im Vergleich zu den Messungen
+
  z=[gpsHdg; gyroHdgRate]; % this is the measurement matrix
 +
  % First, find the Kalman Gain; how much we trust the estimate vs measurements
 
  K = P*C'*inv(C*P*C' + R)
 
  K = P*C'*inv(C*P*C' + R)
  % Dann den Fehler zwischen Vorhersage und Messungen herausfinden (die "Innovation")
+
  % Then we find out the error between prediction and measurement (the Innovation)
 
  % z-C*x
 
  % z-C*x
  % und korrigiere die Schätzung -- aber nur ein kleines bisschen pro Zeiteinheit,
+
  % and correct the estimate -- but only a little at a time,
  % bestimmt durch die Kalman-Verstärkung
+
  % as determined by the Kalman Gain
 
  x = x + K*(z-C*x)
 
  x = x + K*(z-C*x)
  % Genauso: korrigiere (genauer: erniedrige) Unsicherheit da wir nach jeder Messung ein kleines bisschen
+
  % Likewise, we correct (actually increase) certainty, because any time
  % mehr Sicher sein können über unsere Schätzung
+
  % we have a measurement we can be a little more certain about our estimate
 
  P = (I-K*C)*P
 
  P = (I-K*C)*P

Aktuelle Version vom 27. Februar 2015, 15:19 Uhr

Idea

For the Extended Kalman Filter (EKF) you have...

  1. A model of a robots state at every time (e.g. actual heading, actual heading speed).
  2. A certain number of sensors. Each sensor has a certain measurement error (%).

Kalman fusions all sensors measurements by iterating over and over two phases:

  1. Predict: we predict the next robot's state by help of the old robot's state and a certaincy for each sensor.
  2. Correct: we correct the certaincy based on new measurements for each sensor. Does the prediction fit to the sensor measurement, we increase certaincy for that sensor, otherwise we decrease certaincy.

Example

We have a heading (theta) and a heading speed rate (omega). The new heading can be predicted by old heading plus heading rate and delta time:

theta = theta_k+1 + omega * dt
theta_k+1: new heading
theta_k: old heading
omega: heading speed rate
dt: delta time

The heading speed rate is modelled after this:

 omega = omega_k+1

This is a model only. The real heading rate will change. The Kalman considers this. Those both state equations can now be turned into state space form which is basically a matrix form of the two equations:

x_k = A * x_k+1

with

x = [ theta
      omega ]
A = [ 1    dt 
      0    1  ]

If you muliply the matrix equation, you get again both state equations. Kalman filter also uses additional matrizes:

y_k = C * yk+1 

with

y = [ theta 
      omega ]
C = [ 1   0
      0   1 ]

Matrix C transfers measurements into state variables. The Kalman filter also uses Covariance Matrix P which describes how well state variables and measurements fit.

Furthermore, Kalman uses a measurement error matrix R where you can estimate the measurement error for each signal.

Finally, there's a process error matrix Q which models the complete system error (due to noise in servos, motors etc).

Scilab

Kalman algorithm implemented with free math software "Scilab":
% initialize
A=[1 dt; 0 1]; % state transition matrix; represents how we get from prior state to next state
C=[1 0; 0 1]; % the matrix that maps measurement to system state
P=[1000 0; 0 1000]; % sets the initial covariance to indicate initial uncertainty
Q=[0.01 0; 0 0.01]; % process noise; I just picked some numbers; you can play with these
R=[0.01 0; 0 0.01]; % measurement noise; I just picked some numbers here too
% loop the following every time you get a new measurement
% PREDICT
% we predict the next system state based on our knowledge (model) of the system
x = A*x;
% We also have to adjust certainty. If we're predicting system state
% without meausrements, certainty reduces
P = A*P*A' + Q; % adjust certainty with the state transition, too. Add process noise
% CORRECT
% With measurements, we correct the state estimate
z=[gpsHdg; gyroHdgRate]; % this is the measurement matrix
% First, find the Kalman Gain; how much we trust the estimate vs measurements
K = P*C'*inv(C*P*C' + R)
% Then we find out the error between prediction and measurement (the Innovation)
% z-C*x
% and correct the estimate -- but only a little at a time,
% as determined by the Kalman Gain
x = x + K*(z-C*x)
% Likewise, we correct (actually increase) certainty, because any time
% we have a measurement we can be a little more certain about our estimate
P = (I-K*C)*P