Skip to content

Commit eaa9b4d

Browse files
committed
remove np.matrix
1 parent f410844 commit eaa9b4d

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

PathPlanning/LQRPlanner/LQRplanner.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def LQRplanning(sx, sy, gx, gy):
2222

2323
rx, ry = [sx], [sy]
2424

25-
x = np.matrix([sx - gx, sy - gy]).T # State vector
25+
x = np.array([sx - gx, sy - gy]).reshape(2, 1) # State vector
2626

2727
# Linear system model
2828
A, B = get_system_model()
@@ -35,7 +35,7 @@ def LQRplanning(sx, sy, gx, gy):
3535

3636
u = LQR_control(A, B, x)
3737

38-
x = A * x + B * u
38+
x = A @ x + B @ u
3939

4040
rx.append(x[0, 0] + gx)
4141
ry.append(x[1, 0] + gy)
@@ -91,18 +91,18 @@ def dlqr(A, B, Q, R):
9191
X = solve_DARE(A, B, Q, R)
9292

9393
# compute the LQR gain
94-
K = np.matrix(la.inv(B.T * X * B + R) * (B.T * X * A))
94+
K = la.inv(B.T @ X @ B + R) @ (B.T @ X @ A)
9595

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

9898
return K, X, eigVals
9999

100100

101101
def get_system_model():
102102

103-
A = np.matrix([[DT, 1.0],
104-
[0.0, DT]])
105-
B = np.matrix([0.0, 1.0]).T
103+
A = np.array([[DT, 1.0],
104+
[0.0, DT]])
105+
B = np.array([0.0, 1.0]).reshape(2, 1)
106106

107107
return A, B
108108

@@ -111,7 +111,7 @@ def LQR_control(A, B, x):
111111

112112
Kopt, X, ev = dlqr(A, B, np.eye(2), np.eye(1))
113113

114-
u = -Kopt * x
114+
u = -Kopt @ x
115115

116116
return u
117117

0 commit comments

Comments
 (0)