Skip to content

Commit 00140e5

Browse files
committed
keep coding
1 parent 8163031 commit 00140e5

File tree

1 file changed

+18
-13
lines changed

1 file changed

+18
-13
lines changed

SLAM/GraphBasedSLAM/graph_based_slam.py

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,18 @@
1414

1515

1616
# Simulation parameter
17-
Qsim = np.diag([0.0, math.radians(0.0)])**2
18-
Rsim = np.diag([0.0, math.radians(00.0)])**2
17+
Qsim = np.diag([0.1, math.radians(1.0)])**2
18+
Rsim = np.diag([0.1, math.radians(5.0)])**2
1919

20-
DT = 5.0 # time tick [s]
21-
SIM_TIME = 20.0 # simulation time [s]
20+
DT = 1.0 # time tick [s]
21+
SIM_TIME = 40.0 # simulation time [s]
2222
MAX_RANGE = 20.0 # maximum observation range
2323
STATE_SIZE = 3 # State size [x,y,yaw]
2424

2525
# Covariance parameter of Graph Based SLAM
2626
C_SIGMA1 = 1.0
27-
C_SIGMA2 = 0.1
28-
C_SIGMA3 = 0.1
27+
C_SIGMA2 = 1.0
28+
C_SIGMA3 = math.radians(35.0)
2929

3030
MAX_ITR = 20 # Maximuma iteration
3131

@@ -50,8 +50,8 @@ def __init__(self):
5050
def cal_observation_sigma(d):
5151

5252
sigma = np.zeros((3, 3))
53-
sigma[0, 0] = (d * C_SIGMA1)**2
54-
sigma[1, 1] = (d * C_SIGMA2)**2
53+
sigma[0, 0] = C_SIGMA1**2
54+
sigma[1, 1] = C_SIGMA2**2
5555
sigma[2, 2] = C_SIGMA3**2
5656

5757
return sigma
@@ -87,6 +87,9 @@ def calc_edge(x1, y1, yaw1, x2, y2, yaw2, d1,
8787
sig2 = cal_observation_sigma(d2)
8888

8989
edge.omega = np.linalg.inv(Rt1 * sig1 * Rt1.T + Rt2 * sig2 * Rt2.T)
90+
# print(edge.omega)
91+
# edge.omega = np.eye(3)
92+
9093
edge.d1, edge.d2 = d1, d2
9194
edge.yaw1, edge.yaw2 = yaw1, yaw2
9295
edge.angle1, edge.angle2 = angle1, angle2
@@ -159,7 +162,8 @@ def graph_based_slam(x_init, hz):
159162
print("start graph based slam")
160163

161164
x_opt = copy.deepcopy(x_init)
162-
n = len(hz) * STATE_SIZE
165+
# n = len(hz) * STATE_SIZE
166+
n = x_opt.shape[1] * STATE_SIZE
163167

164168
for itr in range(MAX_ITR):
165169
edges = calc_edges(x_opt, hz)
@@ -176,7 +180,7 @@ def graph_based_slam(x_init, hz):
176180

177181
dx = - np.linalg.inv(H).dot(b)
178182

179-
for i in range(len(hz)):
183+
for i in range((x_opt.shape[1])):
180184
x_opt[0:3, i] += dx[i * 3:i * 3 + 3, 0]
181185

182186
diff = dx.T.dot(dx)
@@ -270,8 +274,7 @@ def main():
270274
hxTrue = xTrue
271275
hxDR = xTrue
272276
hz = [np.matrix(np.zeros((1, 4)))]
273-
hz[0][0, 3] = -1
274-
# hz = []
277+
hz = []
275278

276279
while SIM_TIME >= time:
277280
time += DT
@@ -283,6 +286,8 @@ def main():
283286
hxTrue = np.hstack((hxTrue, xTrue))
284287
hz.append(z)
285288

289+
hz.append(hz[-1])
290+
286291
x_opt = graph_based_slam(hxDR, hz)
287292

288293
if show_animation:
@@ -291,7 +296,7 @@ def main():
291296
plt.plot(RFID[:, 0], RFID[:, 1], "*k")
292297

293298
plt.plot(np.array(hxTrue[0, :]).flatten(),
294-
np.array(hxTrue[1, :]).flatten(), "-b")
299+
np.array(hxTrue[1, :]).flatten(), "xb")
295300
plt.plot(np.array(hxDR[0, :]).flatten(),
296301
np.array(hxDR[1, :]).flatten(), "-k")
297302
plt.plot(np.array(x_opt[0, :]).flatten(),

0 commit comments

Comments
 (0)