66
77"""
88
9- import numpy as np
109import math
10+
1111import matplotlib .pyplot as plt
12+ import numpy as np
1213
1314# Estimation parameter of PF
14- Q = np .diag ([0.1 ])** 2 # range error
15- R = np .diag ([1.0 , np .deg2rad (40.0 )])** 2 # input error
15+ Q = np .diag ([0.1 ]) ** 2 # range error
16+ R = np .diag ([1.0 , np .deg2rad (40.0 )]) ** 2 # input error
1617
1718# Simulation parameter
18- Qsim = np .diag ([0.2 ])** 2
19- Rsim = np .diag ([1.0 , np .deg2rad (30.0 )])** 2
19+ Qsim = np .diag ([0.2 ]) ** 2
20+ Rsim = np .diag ([1.0 , np .deg2rad (30.0 )]) ** 2
2021
2122DT = 0.1 # time tick [s]
2223SIM_TIME = 50.0 # simulation time [s]
@@ -37,7 +38,6 @@ def calc_input():
3738
3839
3940def observation (xTrue , xd , u , RFID ):
40-
4141 xTrue = motion_model (xTrue , u )
4242
4343 # add noise to gps x-y
@@ -47,7 +47,7 @@ def observation(xTrue, xd, u, RFID):
4747
4848 dx = xTrue [0 , 0 ] - RFID [i , 0 ]
4949 dy = xTrue [1 , 0 ] - RFID [i , 1 ]
50- d = math .sqrt (dx ** 2 + dy ** 2 )
50+ d = math .sqrt (dx ** 2 + dy ** 2 )
5151 if d <= MAX_RANGE :
5252 dn = d + np .random .randn () * Qsim [0 , 0 ] # add noise
5353 zi = np .array ([[dn , RFID [i , 0 ], RFID [i , 1 ]]])
@@ -64,7 +64,6 @@ def observation(xTrue, xd, u, RFID):
6464
6565
6666def motion_model (x , u ):
67-
6867 F = np .array ([[1.0 , 0 , 0 , 0 ],
6968 [0 , 1.0 , 0 , 0 ],
7069 [0 , 0 , 1.0 , 0 ],
@@ -97,14 +96,15 @@ def calc_covariance(xEst, px, pw):
9796 return cov
9897
9998
100- def pf_localization (px , pw , xEst , PEst , z , u ):
99+ def pf_localization (px , pw , z , u ):
101100 """
102101 Localization with Particle filter
103102 """
104103
105104 for ip in range (NP ):
106105 x = np .array ([px [:, ip ]]).T
107106 w = pw [0 , ip ]
107+
108108 # Predict with random input sampling
109109 ud1 = u [0 , 0 ] + np .random .randn () * Rsim [0 , 0 ]
110110 ud2 = u [1 , 0 ] + np .random .randn () * Rsim [1 , 1 ]
@@ -115,8 +115,8 @@ def pf_localization(px, pw, xEst, PEst, z, u):
115115 for i in range (len (z [:, 0 ])):
116116 dx = x [0 , 0 ] - z [i , 1 ]
117117 dy = x [1 , 0 ] - z [i , 2 ]
118- prez = math .sqrt (dx ** 2 + dy ** 2 )
119- dz = prez - z [i , 0 ]
118+ pre_z = math .sqrt (dx ** 2 + dy ** 2 )
119+ dz = pre_z - z [i , 0 ]
120120 w = w * gauss_likelihood (dz , math .sqrt (Q [0 , 0 ]))
121121
122122 px [:, ip ] = x [:, 0 ]
@@ -223,7 +223,7 @@ def main():
223223
224224 xTrue , z , xDR , ud = observation (xTrue , xDR , u , RFID )
225225
226- xEst , PEst , px , pw = pf_localization (px , pw , xEst , PEst , z , ud )
226+ xEst , PEst , px , pw = pf_localization (px , pw , z , ud )
227227
228228 # store data history
229229 hxEst = np .hstack ((hxEst , xEst ))
0 commit comments