Skip to content

Commit 2c245d9

Browse files
authored
enhance histogram filter doc (AtsushiSakai#623)
* enhance histogram filter doc * enhance histogram filter doc * enhance histogram filter doc * enhance histogram filter doc * enhance histogram filter doc * enhance histogram filter doc * Update docs/modules/localization/histogram_filter_localization/histogram_filter_localization.rst * Update docs/modules/localization/histogram_filter_localization/histogram_filter_localization.rst * fix duplicated math lables * fix duplicated math lables * fix duplicated math lables * update doc * update doc * update doc * update doc * update doc * update doc
1 parent 7025517 commit 2c245d9

File tree

8 files changed

+110
-13
lines changed

8 files changed

+110
-13
lines changed

Localization/histogram_filter/histogram_filter.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ def calc_gaussian_observation_pdf(grid_map, z, iz, ix, iy, std):
7171
d = math.hypot(x - z[iz, 1], y - z[iz, 2])
7272

7373
# likelihood
74-
pdf = (1.0 - norm.cdf(abs(d - z[iz, 0]), 0.0, std))
74+
pdf = norm.pdf(d - z[iz, 0], 0.0, std)
7575

7676
return pdf
7777

@@ -88,7 +88,7 @@ def observation_update(grid_map, z, std):
8888
return grid_map
8989

9090

91-
def calc_input():
91+
def calc_control_input():
9292
v = 1.0 # [m/s]
9393
yaw_rate = 0.1 # [rad/s]
9494
u = np.array([v, yaw_rate]).reshape(2, 1)
@@ -113,6 +113,7 @@ def motion_model(x, u):
113113

114114
def draw_heat_map(data, mx, my):
115115
max_value = max([max(i_data) for i_data in data])
116+
plt.grid(False)
116117
plt.pcolor(mx, my, data, vmax=max_value, cmap=plt.cm.get_cmap("Blues"))
117118
plt.axis("equal")
118119

@@ -197,6 +198,7 @@ def motion_update(grid_map, u, yaw):
197198
grid_map.dx -= x_shift * grid_map.xy_resolution
198199
grid_map.dy -= y_shift * grid_map.xy_resolution
199200

201+
# Add motion noise
200202
grid_map.data = gaussian_filter(grid_map.data, sigma=MOTION_STD)
201203

202204
return grid_map
@@ -230,9 +232,9 @@ def main():
230232

231233
while SIM_TIME >= time:
232234
time += DT
233-
print("Time:", time)
235+
print(f"{time=:.1f}")
234236

235-
u = calc_input()
237+
u = calc_control_input()
236238

237239
yaw = xTrue[2, 0] # Orientation is known
238240
xTrue, z, ud = observation(xTrue, u, RF_ID)
@@ -249,8 +251,9 @@ def main():
249251
plt.plot(xTrue[0, :], xTrue[1, :], "xr")
250252
plt.plot(RF_ID[:, 0], RF_ID[:, 1], ".k")
251253
for i in range(z.shape[0]):
252-
plt.plot([xTrue[0, :], z[i, 1]], [
253-
xTrue[1, :], z[i, 2]], "-k")
254+
plt.plot([xTrue[0, 0], z[i, 1]],
255+
[xTrue[1, 0], z[i, 2]],
256+
"-k")
254257
plt.title("Time[s]:" + str(time)[0: 4])
255258
plt.pause(0.1)
256259

docs/modules/localization/extended_kalman_filter_localization_files/extended_kalman_filter_localization.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,10 +120,10 @@ Its Jacobian matrix is
120120

121121
:math:`\begin{equation*}  = \begin{bmatrix} 1& 0 & 0 & 0\\ 0 & 1 & 0 & 0\\ \end{bmatrix} \end{equation*}`
122122

123-
Extented Kalman Filter
123+
Extended Kalman Filter
124124
~~~~~~~~~~~~~~~~~~~~~~
125125

126-
Localization process using Extendted Kalman Filter:EKF is
126+
Localization process using Extended Kalman Filter:EKF is
127127

128128
=== Predict ===
129129

55.8 KB
Loading
193 KB
Loading
96.6 KB
Loading
49.8 KB
Loading

docs/modules/localization/histogram_filter_localization/histogram_filter_localization.rst

Lines changed: 97 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,106 @@ The red cross is true position, black points are RFID positions.
99

1010
The blue grid shows a position probability of histogram filter.
1111

12-
In this simulation, x,y are unknown, yaw is known.
12+
In this simulation, we assume the robot's yaw orientation and RFID's positions are known,
13+
but x,y positions are unknown.
14+
15+
The filter uses speed input and range observations from RFID for localization.
16+
17+
Initial position information is not needed.
18+
19+
Filtering algorithm
20+
~~~~~~~~~~~~~~~~~~~~
21+
22+
Histogram filter is a discrete Bayes filter in continuous space.
23+
24+
It uses regular girds to manage probability of the robot existence.
25+
26+
If a grid has higher probability, it means that the robot is likely to be there.
27+
28+
In the simulation, we want to estimate x-y position, so we use 2D grid data.
29+
30+
There are 4 steps for the histogram filter to estimate the probability distribution.
31+
32+
Step1: Filter initialization
33+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
34+
35+
Histogram filter does not need initial position information.
36+
37+
In that case, we can initialize each grid probability as a same value.
38+
39+
If we can use initial position information, we can set initial probabilities based on it.
40+
41+
:ref:`gaussian_grid_map` might be useful when the initial position information is provided as gaussian distribution.
42+
43+
Step2: Predict probability by motion
44+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
45+
46+
In histogram filter, when a robot move to a next grid,
47+
all probability information of each grid are shifted towards the movement direction.
48+
49+
This process represents the change in the probability distribution as the robot moves.
50+
51+
After the robot has moved, the probability distribution needs reflect
52+
the estimation error due to the movement.
53+
54+
For example, the position probability is peaky with observations:
55+
56+
.. image:: histogram_filter_localization/1.png
57+
:width: 400px
58+
59+
But, the probability is getting uncertain without observations:
60+
61+
.. image:: histogram_filter_localization/2.png
62+
:width: 400px
63+
64+
65+
The `gaussian filter <https://docs.scipy.org/doc/scipy/reference/generated/scipy.ndimage.gaussian_filter.html>`_
66+
is used in the simulation for adding noize.
67+
68+
Step3: Update probability by observation
69+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
70+
In this step, all probabilities are updated by observations,
71+
this is the update step of bayesian filter.
72+
73+
The probability update formula is different by the used sensor model.
74+
75+
This simulation uses range observation model.
76+
77+
The probability of each grid is updated by this formula:
78+
79+
.. math:: p_t=p_{t-1}*h(z)
80+
81+
.. math:: h(z)=\frac{\exp \left(-(d - z)^{2} / 2\right)}{\sqrt{2 \pi}}
82+
83+
- :math:`p_t` is the probability at the time `t`.
84+
85+
- :math:`h(z)` is the observation probability with the observation `z`.
86+
87+
- :math:`d` is the known distance from the RD-ID to the grid center.
88+
89+
When the `d` is 3.0, the `h(z)` distribution is:
90+
91+
.. image:: histogram_filter_localization/4.png
92+
:width: 400px
93+
94+
The observation probability distribution looks a circle when a RF-ID is observed:
95+
96+
.. image:: histogram_filter_localization/3.png
97+
:width: 400px
98+
99+
Step4: Estimate position from probability
100+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
101+
In each time step, we can calculate the final robot position from the current probability distribution.
102+
There are two ways to calculate the final positions:
103+
104+
1. Using the maximum probability grid position.
105+
106+
2. Using the average of probability weighted grind position.
13107

14-
The filter integrates speed input and range observations from RFID for
15-
localization.
16108

17-
Initial position is not needed.
18109

19110
References:
20111
~~~~~~~~~~~
21112

22-
- `PROBABILISTIC ROBOTICS`_
113+
- `PROBABILISTIC ROBOTICS`_
114+
- `Robust Vehicle Localization in Urban Environments Using Probabilistic Maps <http://driving.stanford.edu/papers/ICRA2010.pdf>`_

docs/modules/mapping/gaussian_grid_map/gaussian_grid_map.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
.. _gaussian_grid_map:
2+
13
Gaussian grid map
24
-----------------
35

0 commit comments

Comments
 (0)