Skip to content

Commit 7319c8a

Browse files
committed
Add doc
1 parent 7f07f89 commit 7319c8a

File tree

3 files changed

+153
-4
lines changed

3 files changed

+153
-4
lines changed

Localization/extended_kalman_filter/ekf_with_velocity_correction.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,11 @@ def jacob_f(x, u):
9797
v_{t+1} = v{t}
9898
s_{t+1} = s{t}
9999
so
100-
dx/dyaw = -v*dt*sin(yaw)
101-
dx/dv = dt*cos(yaw)
100+
dx/dyaw = -v*s*dt*sin(yaw)
101+
dx/dv = dt*s*cos(yaw)
102102
dx/ds = dt*v*cos(yaw)
103-
dy/dyaw = v*dt*cos(yaw)
104-
dy/dv = dt*sin(yaw)
103+
dy/dyaw = v*s*dt*cos(yaw)
104+
dy/dv = dt*s*sin(yaw)
105105
dy/ds = dt*v*sin(yaw)
106106
"""
107107
yaw = x[2, 0]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
2+
Extended Kalman Filter Localization
3+
-----------------------------------
4+
5+
.. image:: ekf_with_velocity_correction_1_0.png
6+
:width: 600px
7+
8+
This is a velocity scale factor estimation using Extended Kalman Filter(EKF).
9+
10+
This is for correcting the vehicle speed measured with scale factor errors due to factors such as wheel wear.
11+
12+
The blue line is true trajectory, the black line is dead reckoning
13+
trajectory,
14+
15+
the green point is positioning observation (ex. GPS), and the red line
16+
is estimated trajectory with EKF.
17+
18+
The red ellipse is estimated covariance ellipse with EKF.
19+
20+
Code: `PythonRobotics/extended_kalman_ekf_with_velocity_correctionfilter.py at master ·
21+
AtsushiSakai/PythonRobotics <https://github.com/AtsushiSakai/PythonRobotics/blob/master/Localization/extended_kalman_filter/extended_kalman_ekf_with_velocity_correctionfilter.py>`__
22+
23+
Filter design
24+
~~~~~~~~~~~~~
25+
26+
In this simulation, the robot has a state vector includes 5 states at
27+
time :math:`t`.
28+
29+
.. math:: \textbf{x}_t=[x_t, y_t, \phi_t, v_t, s_t]
30+
31+
x, y are a 2D x-y position, :math:`\phi` is orientation, v is
32+
velocity, and s is a scale factor of velocity.
33+
34+
In the code, “xEst” means the state vector.
35+
`code <https://github.com/AtsushiSakai/PythonRobotics/blob/916b4382de090de29f54538b356cef1c811aacce/Localization/extended_kalman_filter/extended_kalman_ekf_with_velocity_correctionfilter.py#L163>`__
36+
37+
And, :math:`P_t` is covariace matrix of the state,
38+
39+
:math:`Q` is covariance matrix of process noise,
40+
41+
:math:`R` is covariance matrix of observation noise at time :math:`t`
42+
43+
 
44+
45+
The robot has a speed sensor and a gyro sensor.
46+
47+
So, the input vecor can be used as each time step
48+
49+
.. math:: \textbf{u}_t=[v_t, \omega_t]
50+
51+
Also, the robot has a GNSS sensor, it means that the robot can observe
52+
x-y position at each time.
53+
54+
.. math:: \textbf{z}_t=[x_t,y_t]
55+
56+
The input and observation vector includes sensor noise.
57+
58+
In the code, “observation” function generates the input and observation
59+
vector with noise
60+
`code <https://github.com/AtsushiSakai/PythonRobotics/blob/916b4382de090de29f54538b356cef1c811aacce/Localization/extended_kalman_filter/extended_kalman_ekf_with_velocity_correctionfilter.py#L34-L50>`__
61+
62+
Motion Model
63+
~~~~~~~~~~~~
64+
65+
The robot model is
66+
67+
.. math:: \dot{x} = v \cos(\phi)
68+
69+
.. math:: \dot{y} = v \sin(\phi)
70+
71+
.. math:: \dot{\phi} = \omega
72+
73+
So, the motion model is
74+
75+
.. math:: \textbf{x}_{t+1} = f(\textbf{x}_t, \textbf{u}_t) = F\textbf{x}_t+B\textbf{u}_t
76+
77+
where
78+
79+
:math:`\begin{equation*} F= \begin{bmatrix} 1 & 0 & 0 & 0 & 0\\ 0 & 1 & 0 & 0 & 0\\ 0 & 0 & 1 & 0 & 0\\ 0 & 0 & 0 & 0 & 0\\ 0 & 0 & 0 & 0 & 1\\ \end{bmatrix} \end{equation*}`
80+
81+
:math:`\begin{equation*} B= \begin{bmatrix} cos(\phi) \Delta t s & 0\\ sin(\phi) \Delta t s & 0\\ 0 & \Delta t\\ 1 & 0\\ 0 & 0\\ \end{bmatrix} \end{equation*}`
82+
83+
:math:`\Delta t` is a time interval.
84+
85+
This is implemented at
86+
`code <https://github.com/AtsushiSakai/PythonRobotics/blob/916b4382de090de29f54538b356cef1c811aacce/Localization/extended_kalman_filter/extended_kalman_filter.py#L61-L76>`__
87+
88+
The motion function is that
89+
90+
:math:`\begin{equation*} \begin{bmatrix} x' \\ y' \\ w' \\ v' \end{bmatrix} = f(\textbf{x}, \textbf{u}) = \begin{bmatrix} x + v\cos(\phi)\Delta t \\ y + v\sin(\phi)\Delta t \\ \phi + \omega \Delta t \\ v \end{bmatrix} \end{equation*}`
91+
92+
Its Jacobian matrix is
93+
94+
:math:`\begin{equation*} J_f = \begin{bmatrix} \frac{\partial x'}{\partial x}& \frac{\partial x'}{\partial y} & \frac{\partial x'}{\partial \phi} & \frac{\partial x'}{\partial v} & \frac{\partial x'}{\partial s}\\ \frac{\partial y'}{\partial x}& \frac{\partial y'}{\partial y} & \frac{\partial y'}{\partial \phi} & \frac{\partial y'}{\partial v} & \frac{\partial y'}{\partial s}\\ \frac{\partial \phi'}{\partial x}& \frac{\partial \phi'}{\partial y} & \frac{\partial \phi'}{\partial \phi} & \frac{\partial \phi'}{\partial v} & \frac{\partial \phi'}{\partial s}\\ \frac{\partial v'}{\partial x}& \frac{\partial v'}{\partial y} & \frac{\partial v'}{\partial \phi} & \frac{\partial v'}{\partial v} & \frac{\partial v'}{\partial s} \\ \frac{\partial s'}{\partial x}& \frac{\partial s'}{\partial y} & \frac{\partial s'}{\partial \phi} & \frac{\partial s'}{\partial v} & \frac{\partial s'}{\partial s} \end{bmatrix} \end{equation*}`
95+
96+
:math:`\begin{equation*}  = \begin{bmatrix} 1& 0 & -v s \sin(\phi) \Delta t & s \cos(\phi) \Delta t & \cos(\phi) v \Delta t\\ 0 & 1 & v s \cos(\phi) \Delta t & s \sin(\phi) \Delta t & v \sin(\phi) \Delta t\\ 0 & 0 & 1 & 0 & 0 \\ 0 & 0 & 0 & 1 & 0 \end{bmatrix} \end{equation*}`
97+
98+
Observation Model
99+
~~~~~~~~~~~~~~~~~
100+
101+
The robot can get x-y position infomation from GPS.
102+
103+
So GPS Observation model is
104+
105+
.. math:: \textbf{z}_{t} = g(\textbf{x}_t) = H \textbf{x}_t
106+
107+
where
108+
109+
:math:`\begin{equation*} H = \begin{bmatrix} 1 & 0 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 & 0 \\ \end{bmatrix} \end{equation*}`
110+
111+
The observation function states that
112+
113+
:math:`\begin{equation*} \begin{bmatrix} x' \\ y' \end{bmatrix} = g(\textbf{x}) = \begin{bmatrix} x \\ y \end{bmatrix} \end{equation*}`
114+
115+
Its Jacobian matrix is
116+
117+
:math:`\begin{equation*} J_g = \begin{bmatrix} \frac{\partial x'}{\partial x} & \frac{\partial x'}{\partial y} & \frac{\partial x'}{\partial \phi} & \frac{\partial x'}{\partial v} & \frac{\partial x'}{\partial s}\\ \frac{\partial y'}{\partial x}& \frac{\partial y'}{\partial y} & \frac{\partial y'}{\partial \phi} & \frac{\partial y'}{ \partial v} & \frac{\partial y'}{ \partial s}\\ \end{bmatrix} \end{equation*}`
118+
119+
:math:`\begin{equation*}  = \begin{bmatrix} 1& 0 & 0 & 0 & 0\\ 0 & 1 & 0 & 0 & 0\\ \end{bmatrix} \end{equation*}`
120+
121+
Extended Kalman Filter
122+
~~~~~~~~~~~~~~~~~~~~~~
123+
124+
Localization process using Extended Kalman Filter:EKF is
125+
126+
=== Predict ===
127+
128+
:math:`x_{Pred} = Fx_t+Bu_t`
129+
130+
:math:`P_{Pred} = J_f P_t J_f^T + Q`
131+
132+
=== Update ===
133+
134+
:math:`z_{Pred} = Hx_{Pred}`
135+
136+
:math:`y = z - z_{Pred}`
137+
138+
:math:`S = J_g P_{Pred}.J_g^T + R`
139+
140+
:math:`K = P_{Pred}.J_g^T S^{-1}`
141+
142+
:math:`x_{t+1} = x_{Pred} + Ky`
143+
144+
:math:`P_{t+1} = ( I - K J_g) P_{Pred}`
145+
146+
Ref:
147+
~~~~
148+
149+
- `PROBABILISTIC-ROBOTICS.ORG <http://www.probabilistic-robotics.org/>`__

0 commit comments

Comments
 (0)