Skip to content

Commit ae44021

Browse files
committed
keep implementing
1 parent f0a654e commit ae44021

File tree

1 file changed

+34
-12
lines changed

1 file changed

+34
-12
lines changed

SLAM/EKFSLAM/ekf_slam.py

Lines changed: 34 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
import math
1111
import matplotlib.pyplot as plt
1212

13+
Cx = np.diag([1.0, 1.0, math.radians(30.0)])**2
14+
1315
# Simulation parameter
1416
Qsim = np.diag([0.2])**2
1517
Rsim = np.diag([1.0, math.radians(30.0)])**2
@@ -18,6 +20,9 @@
1820
SIM_TIME = 50.0 # simulation time [s]
1921
MAX_RANGE = 20.0 # maximum observation range
2022

23+
POSE_SIZE = 3 # [x,y,yaw]
24+
LM_SIZE = 2 # [x,y]
25+
2126
# Particle filter parameter
2227
NP = 100 # Number of Particle
2328
NTh = NP / 2.0 # Number of particle for re-sampling
@@ -61,26 +66,43 @@ def observation(xTrue, xd, u, RFID):
6166

6267
def motion_model(x, u):
6368

64-
F = np.matrix([[1.0, 0, 0, 0],
65-
[0, 1.0, 0, 0],
66-
[0, 0, 1.0, 0],
67-
[0, 0, 0, 0]])
69+
F = np.matrix([[1.0, 0, 0],
70+
[0, 1.0, 0],
71+
[0, 0, 1.0]])
6872

6973
B = np.matrix([[DT * math.cos(x[2, 0]), 0],
7074
[DT * math.sin(x[2, 0]), 0],
71-
[0.0, DT],
72-
[1.0, 0.0]])
75+
[0.0, DT]])
7376

7477
x = F * x + B * u
7578

7679
return x
7780

7881

82+
def calc_n_LM(x):
83+
n = int((len(x) - POSE_SIZE) / LM_SIZE)
84+
return n
85+
86+
87+
def jacob_motion(x, u):
88+
89+
Fx = np.hstack((np.eye(POSE_SIZE), np.zeros(
90+
(POSE_SIZE, LM_SIZE * calc_n_LM(x)))))
91+
92+
jF = np.matrix([[0.0, 0.0, -DT * u[0] * math.sin(x[2, 0])],
93+
[0.0, 0.0, DT * u[0] * math.cos(x[2, 0])],
94+
[0.0, 0.0, 0.0]])
95+
96+
G = np.eye(POSE_SIZE) + Fx.T * jF * Fx
97+
98+
return G, Fx,
99+
100+
79101
def ekf_slam(xEst, PEst, u, z):
80102
# Predict
81103
xEst = motion_model(xEst, u)
82-
# [G,Fx]=jacobF(xEst, u);
83-
# PEst= G'*PEst*G + Fx'*R*Fx;
104+
G, Fx = jacob_motion(xEst, u)
105+
PEst = G.T * PEst * G + Fx.T * Cx * Fx
84106

85107
return xEst, PEst
86108

@@ -137,11 +159,11 @@ def main():
137159
[-5.0, 20.0]])
138160

139161
# State Vector [x y yaw v]'
140-
xEst = np.matrix(np.zeros((4, 1)))
141-
xTrue = np.matrix(np.zeros((4, 1)))
142-
PEst = np.eye(4)
162+
xEst = np.matrix(np.zeros((POSE_SIZE, 1)))
163+
xTrue = np.matrix(np.zeros((POSE_SIZE, 1)))
164+
PEst = np.eye(POSE_SIZE)
143165

144-
xDR = np.matrix(np.zeros((4, 1))) # Dead reckoning
166+
xDR = np.matrix(np.zeros((POSE_SIZE, 1))) # Dead reckoning
145167

146168
# history
147169
hxEst = xEst

0 commit comments

Comments
 (0)