Skip to content

Commit c05a4fd

Browse files
authored
Fix ModuleNotFoundError when executing test in the tests folder and little improve MPC controller (AtsushiSakai#619)
* Fix ModuleNotFoundError when executing test in the tests folder Signed-off-by: Trung Kien <letrungkien.k53.hut@gmail.com> * Improve model_predictive_speed_and_steer_control - Fix typo - Using @ for matrix multiplication instead of * with have been deprecated in CVXPY1.1 - Fix missing conftest module in test file Signed-off-by: Trung Kien <letrungkien.k53.hut@gmail.com>
1 parent 0dfa274 commit c05a4fd

File tree

6 files changed

+21
-8
lines changed

6 files changed

+21
-8
lines changed

PathPlanning/Eta3SplineTrajectory/eta3_spline_trajectory.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
from matplotlib.collections import LineCollection
1818
import sys
1919
import os
20-
sys.path.append(os.path.relpath("../Eta3SplinePath"))
20+
sys.path.append(os.path.dirname(os.path.abspath(__file__)) +
21+
"/../Eta3SplinePath")
2122

2223
try:
2324
from eta3_spline_path import Eta3Path, Eta3PathSegment

PathTracking/lqr_speed_steer_control/lqr_speed_steer_control.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,14 @@
77
"""
88
import math
99
import sys
10+
import os
1011

1112
import matplotlib.pyplot as plt
1213
import numpy as np
1314
import scipy.linalg as la
1415

15-
sys.path.append("../../PathPlanning/CubicSpline/")
16+
sys.path.append(os.path.dirname(os.path.abspath(__file__)) +
17+
"/../../PathPlanning/CubicSpline/")
1618

1719
try:
1820
import cubic_spline_planner

PathTracking/lqr_steer_control/lqr_steer_control.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@
1010
import math
1111
import numpy as np
1212
import sys
13-
sys.path.append("../../PathPlanning/CubicSpline/")
13+
import os
14+
15+
sys.path.append(os.path.dirname(os.path.abspath(__file__)) +
16+
"/../../PathPlanning/CubicSpline/")
1417

1518
try:
1619
import cubic_spline_planner

PathTracking/model_predictive_speed_and_steer_control/model_predictive_speed_and_steer_control.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@
1010
import math
1111
import numpy as np
1212
import sys
13-
sys.path.append("../../PathPlanning/CubicSpline/")
13+
import os
14+
15+
sys.path.append(os.path.dirname(os.path.abspath(__file__)) +
16+
"/../../PathPlanning/CubicSpline/")
1417

1518
try:
1619
import cubic_spline_planner
@@ -175,9 +178,9 @@ def update_state(state, a, delta):
175178
state.yaw = state.yaw + state.v / WB * math.tan(delta) * DT
176179
state.v = state.v + a * DT
177180

178-
if state. v > MAX_SPEED:
181+
if state.v > MAX_SPEED:
179182
state.v = MAX_SPEED
180-
elif state. v < MIN_SPEED:
183+
elif state.v < MIN_SPEED:
181184
state.v = MIN_SPEED
182185

183186
return state
@@ -272,7 +275,7 @@ def linear_mpc_control(xref, xbar, x0, dref):
272275

273276
A, B, C = get_linear_model_matrix(
274277
xbar[2, t], xbar[3, t], dref[0, t])
275-
constraints += [x[:, t + 1] == A * x[:, t] + B * u[:, t] + C]
278+
constraints += [x[:, t + 1] == A @ x[:, t] + B @ u[:, t] + C]
276279

277280
if t < (T - 1):
278281
cost += cvxpy.quad_form(u[:, t + 1] - u[:, t], Rd)

PathTracking/stanley_controller/stanley_controller.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@
1212
import numpy as np
1313
import matplotlib.pyplot as plt
1414
import sys
15-
sys.path.append("../../PathPlanning/CubicSpline/")
15+
import os
16+
17+
sys.path.append(os.path.dirname(os.path.abspath(__file__)) +
18+
"/../../PathPlanning/CubicSpline/")
1619

1720
try:
1821
import cubic_spline_planner

tests/test_model_predictive_speed_and_steer_control.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import sys
2+
import conftest
23

34
if 'cvxpy' in sys.modules: # pragma: no cover
45

0 commit comments

Comments
 (0)