Skip to content

Commit 0c97372

Browse files
committed
add state_lattice_planner test
1 parent a77ef77 commit 0c97372

File tree

2 files changed

+75
-34
lines changed

2 files changed

+75
-34
lines changed

PathPlanning/StateLatticePlanner/state_lattice_planner.py

Lines changed: 57 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,24 @@
11
"""
2+
23
State lattice planner with model predictive trajectory generator
34
4-
author: Atsushi Sakai
5+
author: Atsushi Sakai(Atsushi_twi)
6+
57
"""
68
import sys
7-
import os
89

9-
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
10+
sys.path.append("../ModelPredictiveTrajectoryGenerator")
1011

1112
from matplotlib import pyplot as plt
1213
import numpy as np
1314
import math
1415
import pandas as pd
15-
import ModelPredictiveTrajectoryGenerator.model_predictive_trajectory_generator as planner
16-
import ModelPredictiveTrajectoryGenerator.motion_model as motion_model
16+
import model_predictive_trajectory_generator as planner
17+
import motion_model
18+
19+
table_path = "./lookuptable.csv"
20+
21+
show_animation = True
1722

1823

1924
def search_nearest_one_from_lookuptable(tx, ty, tyaw, lookup_table):
@@ -34,7 +39,7 @@ def search_nearest_one_from_lookuptable(tx, ty, tyaw, lookup_table):
3439

3540

3641
def get_lookup_table():
37-
data = pd.read_csv("lookuptable.csv")
42+
data = pd.read_csv(table_path)
3843

3944
return np.array(data)
4045

@@ -107,7 +112,8 @@ def calc_biased_polar_states(goal_angle, ns, nxy, nh, d, a_min, a_max, p_min, p_
107112
cnav_max = max(cnav)
108113

109114
# normalize
110-
cnav = [(cnav_max - cnav[i]) / (cnav_max * ns - cnav_sum) for i in range(ns - 1)]
115+
cnav = [(cnav_max - cnav[i]) / (cnav_max * ns - cnav_sum)
116+
for i in range(ns - 1)]
111117

112118
csumnav = np.cumsum(cnav)
113119
di = []
@@ -142,7 +148,8 @@ def calc_lane_states(l_center, l_heading, l_width, v_width, d, nxy):
142148

143149
states = []
144150
for i in range(nxy):
145-
delta = -0.5 * (l_width - v_width) + (l_width - v_width) * i / (nxy - 1)
151+
delta = -0.5 * (l_width - v_width) + \
152+
(l_width - v_width) * i / (nxy - 1)
146153
xf = xc - delta * math.sin(l_heading)
147154
yf = yc + delta * math.cos(l_heading)
148155
yawf = l_heading
@@ -183,11 +190,14 @@ def uniform_terminal_state_sampling_test1():
183190
for table in result:
184191
xc, yc, yawc = motion_model.generate_trajectory(
185192
table[3], table[4], table[5], k0)
186-
plt.plot(xc, yc, "-r")
187193

188-
plt.grid(True)
189-
plt.axis("equal")
190-
plt.show()
194+
if show_animation:
195+
plt.plot(xc, yc, "-r")
196+
197+
if show_animation:
198+
plt.grid(True)
199+
plt.axis("equal")
200+
plt.show()
191201

192202
print("Done")
193203

@@ -207,11 +217,14 @@ def uniform_terminal_state_sampling_test2():
207217
for table in result:
208218
xc, yc, yawc = motion_model.generate_trajectory(
209219
table[3], table[4], table[5], k0)
210-
plt.plot(xc, yc, "-r")
211220

212-
plt.grid(True)
213-
plt.axis("equal")
214-
plt.show()
221+
if show_animation:
222+
plt.plot(xc, yc, "-r")
223+
224+
if show_animation:
225+
plt.grid(True)
226+
plt.axis("equal")
227+
plt.show()
215228

216229
print("Done")
217230

@@ -227,17 +240,20 @@ def biased_terminal_state_sampling_test1():
227240
p_max = math.radians(20.0)
228241
ns = 100
229242
goal_angle = math.radians(0.0)
230-
states = calc_biased_polar_states(goal_angle, ns, nxy, nh, d, a_min, a_max, p_min, p_max)
243+
states = calc_biased_polar_states(
244+
goal_angle, ns, nxy, nh, d, a_min, a_max, p_min, p_max)
231245
result = generate_path(states, k0)
232246

233247
for table in result:
234248
xc, yc, yawc = motion_model.generate_trajectory(
235249
table[3], table[4], table[5], k0)
236-
plt.plot(xc, yc, "-r")
250+
if show_animation:
251+
plt.plot(xc, yc, "-r")
237252

238-
plt.grid(True)
239-
plt.axis("equal")
240-
plt.show()
253+
if show_animation:
254+
plt.grid(True)
255+
plt.axis("equal")
256+
plt.show()
241257

242258

243259
def biased_terminal_state_sampling_test2():
@@ -251,17 +267,21 @@ def biased_terminal_state_sampling_test2():
251267
p_max = math.radians(20.0)
252268
ns = 100
253269
goal_angle = math.radians(30.0)
254-
states = calc_biased_polar_states(goal_angle, ns, nxy, nh, d, a_min, a_max, p_min, p_max)
270+
states = calc_biased_polar_states(
271+
goal_angle, ns, nxy, nh, d, a_min, a_max, p_min, p_max)
255272
result = generate_path(states, k0)
256273

257274
for table in result:
258275
xc, yc, yawc = motion_model.generate_trajectory(
259276
table[3], table[4], table[5], k0)
260-
plt.plot(xc, yc, "-r")
261277

262-
plt.grid(True)
263-
plt.axis("equal")
264-
plt.show()
278+
if show_animation:
279+
plt.plot(xc, yc, "-r")
280+
281+
if show_animation:
282+
plt.grid(True)
283+
plt.axis("equal")
284+
plt.show()
265285

266286

267287
def lane_state_sampling_test1():
@@ -279,18 +299,21 @@ def lane_state_sampling_test1():
279299
for table in result:
280300
xc, yc, yawc = motion_model.generate_trajectory(
281301
table[3], table[4], table[5], k0)
282-
plt.plot(xc, yc, "-r")
283302

284-
plt.grid(True)
285-
plt.axis("equal")
286-
plt.show()
303+
if show_animation:
304+
plt.plot(xc, yc, "-r")
305+
306+
if show_animation:
307+
plt.grid(True)
308+
plt.axis("equal")
309+
plt.show()
287310

288311

289312
def main():
290-
# uniform_terminal_state_sampling1()
291-
# uniform_terminal_state_sampling2()
292-
# biased_terminal_state_sampling1()
293-
# biased_terminal_state_sampling2()
313+
uniform_terminal_state_sampling_test1()
314+
uniform_terminal_state_sampling_test2()
315+
biased_terminal_state_sampling_test1()
316+
biased_terminal_state_sampling_test2()
294317
lane_state_sampling_test1()
295318

296319

tests/test_state_lattice_planner.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
from unittest import TestCase
2+
3+
import sys
4+
sys.path.append("./PathPlanning/ModelPredictiveTrajectoryGenerator/")
5+
sys.path.append("./PathPlanning/StateLatticePlanner/")
6+
7+
from PathPlanning.StateLatticePlanner import state_lattice_planner as m
8+
9+
m.table_path = "./PathPlanning/StateLatticePlanner/lookuptable.csv"
10+
11+
print(__file__)
12+
13+
14+
class Test(TestCase):
15+
16+
def test1(self):
17+
m.show_animation = False
18+
m.main()

0 commit comments

Comments
 (0)