Skip to content

Commit 93053ca

Browse files
committed
remove np.matrix from lqr_steer_control
1 parent 3afe984 commit 93053ca

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

PathTracking/lqr_steer_control/lqr_steer_control.py

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

7575
for i in range(maxiter):
76-
Xn = A.T * X * A - A.T * X * B * \
77-
la.inv(R + B.T * X * B) * B.T * X * A + Q
76+
Xn = A.T @ X @ A - A.T @ X @ B @ \
77+
la.inv(R + B.T @ X @ B) @ B.T @ X @ A + Q
7878
if (abs(Xn - X)).max() < eps:
7979
X = Xn
8080
break
@@ -94,9 +94,9 @@ def dlqr(A, B, Q, R):
9494
X = solve_DARE(A, B, Q, R)
9595

9696
# compute the LQR gain
97-
K = np.matrix(la.inv(B.T * X * B + R) * (B.T * X * A))
97+
K = la.inv(B.T @ X @ B + R) @ (B.T @ X @ A)
9898

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

101101
return K, X, eigVals
102102

@@ -108,28 +108,28 @@ def lqr_steering_control(state, cx, cy, cyaw, ck, pe, pth_e):
108108
v = state.v
109109
th_e = pi_2_pi(state.yaw - cyaw[ind])
110110

111-
A = np.matrix(np.zeros((4, 4)))
111+
A = np.zeros((4, 4))
112112
A[0, 0] = 1.0
113113
A[0, 1] = dt
114114
A[1, 2] = v
115115
A[2, 2] = 1.0
116116
A[2, 3] = dt
117117
# print(A)
118118

119-
B = np.matrix(np.zeros((4, 1)))
119+
B = np.zeros((4, 1))
120120
B[3, 0] = v / L
121121

122122
K, _, _ = dlqr(A, B, Q, R)
123123

124-
x = np.matrix(np.zeros((4, 1)))
124+
x = np.zeros((4, 1))
125125

126126
x[0, 0] = e
127127
x[1, 0] = (e - pe) / dt
128128
x[2, 0] = th_e
129129
x[3, 0] = (th_e - pth_e) / dt
130130

131131
ff = math.atan2(L * k, 1)
132-
fb = pi_2_pi((-K * x)[0, 0])
132+
fb = pi_2_pi((-K @ x)[0, 0])
133133

134134
delta = ff + fb
135135

0 commit comments

Comments
 (0)