Skip to content

Commit 8dcc6f0

Browse files
committed
fix bug
1 parent 8f74420 commit 8dcc6f0

File tree

1 file changed

+16
-14
lines changed

1 file changed

+16
-14
lines changed

SLAM/GraphBasedSLAM/graph_based_slam.py

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ def cal_observation_sigma(d):
6565
def calc_rotational_matrix(angle):
6666

6767
Rt = np.array([[math.cos(angle), -math.sin(angle), 0],
68-
[math.sin(angle), math.cos(angle), 0],
69-
[0, 0, 1.0]])
68+
[math.sin(angle), math.cos(angle), 0],
69+
[0, 0, 1.0]])
7070
return Rt
7171

7272

@@ -136,13 +136,13 @@ def calc_edges(xlist, zlist):
136136
def calc_jacobian(edge):
137137
t1 = edge.yaw1 + edge.angle1
138138
A = np.array([[-1.0, 0, edge.d1 * math.sin(t1)],
139-
[0, -1.0, -edge.d1 * math.cos(t1)],
140-
[0, 0, -1.0]])
139+
[0, -1.0, -edge.d1 * math.cos(t1)],
140+
[0, 0, -1.0]])
141141

142142
t2 = edge.yaw2 + edge.angle2
143143
B = np.array([[1.0, 0, -edge.d2 * math.sin(t2)],
144-
[0, 1.0, edge.d2 * math.cos(t2)],
145-
[0, 0, 1.0]])
144+
[0, 1.0, edge.d2 * math.cos(t2)],
145+
[0, 0, 1.0]])
146146

147147
return A, B
148148

@@ -190,7 +190,7 @@ def graph_based_slam(x_init, hz):
190190
dx = - np.linalg.inv(H) @ b
191191

192192
for i in range(nt):
193-
x_opt[0:3, i] += dx[i * 3:i * 3 + 3,0]
193+
x_opt[0:3, i] += dx[i * 3:i * 3 + 3, 0]
194194

195195
diff = dx.T @ dx
196196
print("iteration: %d, diff: %f" % (itr + 1, diff))
@@ -223,8 +223,10 @@ def observation(xTrue, xd, u, RFID):
223223
phi = pi_2_pi(math.atan2(dy, dx))
224224
if d <= MAX_RANGE:
225225
dn = d + np.random.randn() * Qsim[0, 0] # add noise
226-
anglen = angle + np.random.randn() * Qsim[1, 1] # add noise
227-
zi = np.array([dn, anglen, phi, i])
226+
angle_noise = np.random.randn() * Qsim[1, 1]
227+
angle += angle_noise
228+
phi += angle_noise
229+
zi = np.array([dn, angle, phi, i])
228230
z = np.vstack((z, zi))
229231

230232
# add noise to input
@@ -240,12 +242,12 @@ def observation(xTrue, xd, u, RFID):
240242
def motion_model(x, u):
241243

242244
F = np.array([[1.0, 0, 0],
243-
[0, 1.0, 0],
244-
[0, 0, 1.0]])
245+
[0, 1.0, 0],
246+
[0, 0, 1.0]])
245247

246248
B = np.array([[DT * math.cos(x[2, 0]), 0],
247-
[DT * math.sin(x[2, 0]), 0],
248-
[0.0, DT]])
249+
[DT * math.sin(x[2, 0]), 0],
250+
[0.0, DT]])
249251

250252
x = F @ x + B @ u
251253

@@ -271,7 +273,7 @@ def main():
271273

272274
# State Vector [x y yaw v]'
273275
xTrue = np.zeros((STATE_SIZE, 1))
274-
xDR = np.zeros((STATE_SIZE, 1)) # Dead reckoning
276+
xDR = np.zeros((STATE_SIZE, 1)) # Dead reckoning
275277

276278
# history
277279
hxTrue = xTrue

0 commit comments

Comments
 (0)