1
1
"""
2
+
2
3
State lattice planner with model predictive trajectory generator
3
4
4
- author: Atsushi Sakai
5
+ author: Atsushi Sakai(Atsushi_twi)
6
+
5
7
"""
6
8
import sys
7
- import os
8
9
9
- sys .path .append (os . path . dirname ( os . path . dirname ( os . path . abspath ( __file__ ))) )
10
+ sys .path .append ("../ModelPredictiveTrajectoryGenerator" )
10
11
11
12
from matplotlib import pyplot as plt
12
13
import numpy as np
13
14
import math
14
15
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
17
22
18
23
19
24
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):
34
39
35
40
36
41
def get_lookup_table ():
37
- data = pd .read_csv ("lookuptable.csv" )
42
+ data = pd .read_csv (table_path )
38
43
39
44
return np .array (data )
40
45
@@ -107,7 +112,8 @@ def calc_biased_polar_states(goal_angle, ns, nxy, nh, d, a_min, a_max, p_min, p_
107
112
cnav_max = max (cnav )
108
113
109
114
# 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 )]
111
117
112
118
csumnav = np .cumsum (cnav )
113
119
di = []
@@ -142,7 +148,8 @@ def calc_lane_states(l_center, l_heading, l_width, v_width, d, nxy):
142
148
143
149
states = []
144
150
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 )
146
153
xf = xc - delta * math .sin (l_heading )
147
154
yf = yc + delta * math .cos (l_heading )
148
155
yawf = l_heading
@@ -183,11 +190,14 @@ def uniform_terminal_state_sampling_test1():
183
190
for table in result :
184
191
xc , yc , yawc = motion_model .generate_trajectory (
185
192
table [3 ], table [4 ], table [5 ], k0 )
186
- plt .plot (xc , yc , "-r" )
187
193
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 ()
191
201
192
202
print ("Done" )
193
203
@@ -207,11 +217,14 @@ def uniform_terminal_state_sampling_test2():
207
217
for table in result :
208
218
xc , yc , yawc = motion_model .generate_trajectory (
209
219
table [3 ], table [4 ], table [5 ], k0 )
210
- plt .plot (xc , yc , "-r" )
211
220
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 ()
215
228
216
229
print ("Done" )
217
230
@@ -227,17 +240,20 @@ def biased_terminal_state_sampling_test1():
227
240
p_max = math .radians (20.0 )
228
241
ns = 100
229
242
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 )
231
245
result = generate_path (states , k0 )
232
246
233
247
for table in result :
234
248
xc , yc , yawc = motion_model .generate_trajectory (
235
249
table [3 ], table [4 ], table [5 ], k0 )
236
- plt .plot (xc , yc , "-r" )
250
+ if show_animation :
251
+ plt .plot (xc , yc , "-r" )
237
252
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 ()
241
257
242
258
243
259
def biased_terminal_state_sampling_test2 ():
@@ -251,17 +267,21 @@ def biased_terminal_state_sampling_test2():
251
267
p_max = math .radians (20.0 )
252
268
ns = 100
253
269
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 )
255
272
result = generate_path (states , k0 )
256
273
257
274
for table in result :
258
275
xc , yc , yawc = motion_model .generate_trajectory (
259
276
table [3 ], table [4 ], table [5 ], k0 )
260
- plt .plot (xc , yc , "-r" )
261
277
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 ()
265
285
266
286
267
287
def lane_state_sampling_test1 ():
@@ -279,18 +299,21 @@ def lane_state_sampling_test1():
279
299
for table in result :
280
300
xc , yc , yawc = motion_model .generate_trajectory (
281
301
table [3 ], table [4 ], table [5 ], k0 )
282
- plt .plot (xc , yc , "-r" )
283
302
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 ()
287
310
288
311
289
312
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 ()
294
317
lane_state_sampling_test1 ()
295
318
296
319
0 commit comments