Skip to content

Commit 0d53101

Browse files
committed
keep coding..
1 parent ff66ae5 commit 0d53101

File tree

1 file changed

+30
-21
lines changed

1 file changed

+30
-21
lines changed

SLAM/GraphBasedSLAM/graph_based_slam.py

Lines changed: 30 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
Qsim = np.diag([0.2, math.radians(1.0)])**2
1818
Rsim = np.diag([1.0, math.radians(10.0)])**2
1919

20-
DT = 0.1 # time tick [s]
20+
DT = 1.0 # time tick [s]
2121
SIM_TIME = 50.0 # simulation time [s]
2222
MAX_RANGE = 20.0 # maximum observation range
2323
STATE_SIZE = 3 # State size [x,y,yaw]
@@ -105,14 +105,22 @@ def calc_edges(xlist, zlist):
105105
# print(zlist)
106106
xt, yt, yawt = xlist[0, t], xlist[1, t], xlist[2, t]
107107
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])
111110

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]
114118

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
116124

117125
return edges
118126

@@ -150,6 +158,7 @@ def fill_H_and_b(H, b, edge):
150158

151159

152160
def graph_based_slam(u, z, hxDR, hz):
161+
print("start graph based slam")
153162

154163
x_opt = copy.deepcopy(hxDR)
155164
n = len(hz) * 3
@@ -276,25 +285,25 @@ def main():
276285
hxDR = np.hstack((hxDR, xDR))
277286
hz.append(z)
278287

279-
x_opt = graph_based_slam(ud, z, hxDR, hz)
280-
281288
# store data history
282289
hxTrue = np.hstack((hxTrue, xTrue))
283290

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()
286295

287-
plt.plot(RFID[:, 0], RFID[:, 1], "*k")
296+
plt.plot(RFID[:, 0], RFID[:, 1], "*k")
288297

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()
298307

299308

300309
if __name__ == '__main__':

0 commit comments

Comments
 (0)