Skip to content

Commit dc60b71

Browse files
committed
remove np.matrix from lqr_speed_steer_control.py
1 parent 31d4c1c commit dc60b71

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

PathTracking/lqr_speed_steer_control/lqr_speed_steer_control.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ def solve_DARE(A, B, Q, R):
6363
eps = 0.01
6464

6565
for i in range(maxiter):
66-
Xn = A.T * X * A - A.T * X * B * \
67-
la.inv(R + B.T * X * B) * B.T * X * A + Q
66+
Xn = A.T @ X @ A - A.T @ X @ B @ \
67+
la.inv(R + B.T @ X @ B) @ B.T @ X @ A + Q
6868
if (abs(Xn - X)).max() < eps:
6969
break
7070
X = Xn
@@ -83,9 +83,9 @@ def dlqr(A, B, Q, R):
8383
X = solve_DARE(A, B, Q, R)
8484

8585
# compute the LQR gain
86-
K = np.matrix(la.inv(B.T * X * B + R) * (B.T * X * A))
86+
K = la.inv(B.T @ X @ B + R) @ (B.T @ X @ A)
8787

88-
eigVals, eigVecs = la.eig(A - B * K)
88+
eigVals, eigVecs = la.eig(A - B @ K)
8989

9090
return K, X, eigVals
9191

@@ -99,7 +99,7 @@ def lqr_steering_control(state, cx, cy, cyaw, ck, pe, pth_e, sp):
9999
v = state.v
100100
th_e = pi_2_pi(state.yaw - cyaw[ind])
101101

102-
A = np.matrix(np.zeros((5, 5)))
102+
A = np.zeros((5, 5))
103103
A[0, 0] = 1.0
104104
A[0, 1] = dt
105105
A[1, 2] = v
@@ -108,21 +108,21 @@ def lqr_steering_control(state, cx, cy, cyaw, ck, pe, pth_e, sp):
108108
A[4, 4] = 1.0
109109
# print(A)
110110

111-
B = np.matrix(np.zeros((5, 2)))
111+
B = np.zeros((5, 2))
112112
B[3, 0] = v / L
113113
B[4, 1] = dt
114114

115115
K, _, _ = dlqr(A, B, Q, R)
116116

117-
x = np.matrix(np.zeros((5, 1)))
117+
x = np.zeros((5, 1))
118118

119119
x[0, 0] = e
120120
x[1, 0] = (e - pe) / dt
121121
x[2, 0] = th_e
122122
x[3, 0] = (th_e - pth_e) / dt
123123
x[4, 0] = v - tv
124124

125-
ustar = -K * x
125+
ustar = -K @ x
126126

127127
# calc steering input
128128

0 commit comments

Comments
 (0)