|
17 | 17 | Qsim = np.diag([0.2, math.radians(1.0)])**2
|
18 | 18 | Rsim = np.diag([1.0, math.radians(10.0)])**2
|
19 | 19 |
|
20 |
| -DT = 0.1 # time tick [s] |
| 20 | +DT = 1.0 # time tick [s] |
21 | 21 | SIM_TIME = 50.0 # simulation time [s]
|
22 | 22 | MAX_RANGE = 20.0 # maximum observation range
|
23 | 23 | STATE_SIZE = 3 # State size [x,y,yaw]
|
@@ -105,14 +105,22 @@ def calc_edges(xlist, zlist):
|
105 | 105 | # print(zlist)
|
106 | 106 | xt, yt, yawt = xlist[0, t], xlist[1, t], xlist[2, t]
|
107 | 107 | xtd, ytd, yawtd = xlist[0, td], xlist[1, td], xlist[2, td]
|
108 |
| - dt, anglet, phit = zlist[t][0, 0], zlist[t][1, 0], zlist[t][2, 0] |
109 |
| - dtd, angletd, phitd = zlist[td][0, 0], zlist[td][1, 0], zlist[td][2, 0] |
110 |
| - # input() |
| 108 | + # print(zlist[t]) |
| 109 | + # print(zlist[td]) |
111 | 110 |
|
112 |
| - edge = calc_edge(xt, yt, yawt, xtd, ytd, yawtd, dt, |
113 |
| - anglet, phit, dtd, angletd, phitd, t, td) |
| 111 | + for iz1 in range(len(zlist[t][:, 0])): |
| 112 | + for iz2 in range(len(zlist[td][:, 0])): |
| 113 | + if zlist[t][iz1, 3] == zlist[td][iz2, 3]: |
| 114 | + dt, anglet, phit = zlist[t][iz1, |
| 115 | + 0], zlist[t][iz1, 1], zlist[t][iz1, 2] |
| 116 | + dtd, angletd, phitd = zlist[td][iz2, |
| 117 | + 0], zlist[td][iz2, 1], zlist[td][iz2, 2] |
114 | 118 |
|
115 |
| - edges.append(edge) |
| 119 | + edge = calc_edge(xt, yt, yawt, xtd, ytd, yawtd, dt, |
| 120 | + anglet, phit, dtd, angletd, phitd, t, td) |
| 121 | + |
| 122 | + edges.append(edge) |
| 123 | + break |
116 | 124 |
|
117 | 125 | return edges
|
118 | 126 |
|
@@ -150,6 +158,7 @@ def fill_H_and_b(H, b, edge):
|
150 | 158 |
|
151 | 159 |
|
152 | 160 | def graph_based_slam(u, z, hxDR, hz):
|
| 161 | + print("start graph based slam") |
153 | 162 |
|
154 | 163 | x_opt = copy.deepcopy(hxDR)
|
155 | 164 | n = len(hz) * 3
|
@@ -276,25 +285,25 @@ def main():
|
276 | 285 | hxDR = np.hstack((hxDR, xDR))
|
277 | 286 | hz.append(z)
|
278 | 287 |
|
279 |
| - x_opt = graph_based_slam(ud, z, hxDR, hz) |
280 |
| - |
281 | 288 | # store data history
|
282 | 289 | hxTrue = np.hstack((hxTrue, xTrue))
|
283 | 290 |
|
284 |
| - if show_animation: |
285 |
| - plt.cla() |
| 291 | + x_opt = graph_based_slam(ud, z, hxDR, hz) |
| 292 | + |
| 293 | + if show_animation: |
| 294 | + plt.cla() |
286 | 295 |
|
287 |
| - plt.plot(RFID[:, 0], RFID[:, 1], "*k") |
| 296 | + plt.plot(RFID[:, 0], RFID[:, 1], "*k") |
288 | 297 |
|
289 |
| - plt.plot(np.array(hxTrue[0, :]).flatten(), |
290 |
| - np.array(hxTrue[1, :]).flatten(), "-b") |
291 |
| - plt.plot(np.array(hxDR[0, :]).flatten(), |
292 |
| - np.array(hxDR[1, :]).flatten(), "-k") |
293 |
| - plt.plot(np.array(x_opt[0, :]).flatten(), |
294 |
| - np.array(x_opt[1, :]).flatten(), "-r") |
295 |
| - plt.axis("equal") |
296 |
| - plt.grid(True) |
297 |
| - plt.pause(0.001) |
| 298 | + plt.plot(np.array(hxTrue[0, :]).flatten(), |
| 299 | + np.array(hxTrue[1, :]).flatten(), "-b") |
| 300 | + plt.plot(np.array(hxDR[0, :]).flatten(), |
| 301 | + np.array(hxDR[1, :]).flatten(), "-k") |
| 302 | + plt.plot(np.array(x_opt[0, :]).flatten(), |
| 303 | + np.array(x_opt[1, :]).flatten(), "-r") |
| 304 | + plt.axis("equal") |
| 305 | + plt.grid(True) |
| 306 | + plt.show() |
298 | 307 |
|
299 | 308 |
|
300 | 309 | if __name__ == '__main__':
|
|
0 commit comments