7
7
"""
8
8
9
9
import heapq
10
- import matplotlib .pyplot as plt
11
10
import scipy .spatial
12
11
import numpy as np
13
12
import math
14
-
13
+ import matplotlib . pyplot as plt
15
14
import sys
16
15
sys .path .append ("../ReedsSheppPath/" )
17
16
try :
24
23
25
24
XY_GRID_RESOLUTION = 2.0 # [m]
26
25
YAW_GRID_RESOLUTION = np .deg2rad (15.0 ) # [rad]
27
- GOAL_TYAW_TH = np .deg2rad (5.0 ) # [rad]
28
26
MOTION_RESOLUTION = 0.1 # [m] path interporate resolution
29
27
N_STEER = 20.0 # number of steer command
30
- EXTEND_AREA = 0.0 # [m]
31
28
H_COST = 1.0
32
- MOTION_RESOLUTION = 0.1
33
- SKIP_COLLISION_CHECK = 4
34
29
VR = 1.0 # robot radius
35
30
36
31
SB_COST = 100.0 # switch back penalty cost
37
32
BACK_COST = 5.0 # backward penalty cost
38
33
STEER_CHANGE_COST = 5.0 # steer angle change penalty cost
39
34
STEER_COST = 1.0 # steer angle change penalty cost
40
- # JACKKNIF_COST= 200.0 # Jackknif cost
41
35
H_COST = 5.0 # Heuristic cost
42
36
43
37
show_animation = True
44
38
45
- # _round = round
46
- # def round(x):
47
- # return int(_round(x))
48
-
49
39
50
40
class Node :
51
41
52
- def __init__ (self , xind , yind , yawind , direction , xlist , ylist , yawlist , directions , steer = 0.0 , pind = None , cost = None ):
42
+ def __init__ (self , xind , yind , yawind , direction ,
43
+ xlist , ylist , yawlist , directions ,
44
+ steer = 0.0 , pind = None , cost = None ):
53
45
self .xind = xind
54
46
self .yind = yind
55
47
self .yawind = yawind
@@ -114,10 +106,10 @@ def search_in_distance(self, inp, r):
114
106
class Config :
115
107
116
108
def __init__ (self , ox , oy , xyreso , yawreso ):
117
- min_x_m = min (ox ) # - EXTEND_AREA
118
- min_y_m = min (oy ) # - EXTEND_AREA
119
- max_x_m = max (ox ) # + EXTEND_AREA
120
- max_y_m = max (oy ) # + EXTEND_AREA
109
+ min_x_m = min (ox )
110
+ min_y_m = min (oy )
111
+ max_x_m = max (ox )
112
+ max_y_m = max (oy )
121
113
122
114
ox .append (min_x_m )
123
115
oy .append (min_y_m )
@@ -137,10 +129,6 @@ def __init__(self, ox, oy, xyreso, yawreso):
137
129
self .yaww = round (self .maxyaw - self .minyaw )
138
130
139
131
140
- def show_expansion_tree ():
141
- pass
142
-
143
-
144
132
def calc_motion_inputs ():
145
133
146
134
for steer in np .linspace (- MAX_STEER , MAX_STEER , N_STEER ):
@@ -168,7 +156,6 @@ def calc_next_node(current, steer, direction, config, ox, oy, kdtree):
168
156
ylist .append (y )
169
157
yawlist .append (yaw )
170
158
171
- # plt.plot(xlist, ylist)
172
159
if not check_car_collision (xlist , ylist , yawlist , ox , oy , kdtree ):
173
160
return None
174
161
@@ -252,7 +239,8 @@ def update_node_with_analystic_expantion(current, goal,
252
239
253
240
fsteer = 0.0
254
241
fpath = Node (current .xind , current .yind , current .yawind ,
255
- current .direction , fx , fy , fyaw , fd , cost = fcost , pind = fpind , steer = fsteer )
242
+ current .direction , fx , fy , fyaw , fd ,
243
+ cost = fcost , pind = fpind , steer = fsteer )
256
244
return True , fpath
257
245
258
246
return False , None
@@ -331,7 +319,6 @@ def hybrid_a_star_planning(start, goal, ox, oy, xyreso, yawreso):
331
319
return [], [], []
332
320
333
321
cost , c_id = heapq .heappop (pq )
334
- # if openList.has_key(c_id): # python 2.7
335
322
if c_id in openList :
336
323
current = openList .pop (c_id )
337
324
closedList [c_id ] = current
@@ -351,13 +338,13 @@ def hybrid_a_star_planning(start, goal, ox, oy, xyreso, yawreso):
351
338
352
339
for neighbor in get_neighbors (current , config , ox , oy , obkdtree ):
353
340
neighbor_index = calc_index (neighbor , config )
354
- # if closedList.has_key(neighbor_index):
355
341
if neighbor_index in closedList :
356
342
continue
357
- if not neighbor in openList \
343
+ if neighbor not in openList \
358
344
or openList [neighbor_index ].cost > neighbor .cost :
359
345
heapq .heappush (
360
- pq , (calc_cost (neighbor , h_dp , ngoal , config ), neighbor_index ))
346
+ pq , (calc_cost (neighbor , h_dp , ngoal , config ),
347
+ neighbor_index ))
361
348
openList [neighbor_index ] = neighbor
362
349
363
350
path = get_final_path (closedList , fpath , nstart , config )
@@ -366,9 +353,9 @@ def hybrid_a_star_planning(start, goal, ox, oy, xyreso, yawreso):
366
353
367
354
def calc_cost (n , h_dp , goal , c ):
368
355
ind = (n .yind - c .miny ) * c .xw + (n .xind - c .minx )
369
- if not ind in h_dp :
370
- return ( n .cost + 999999999 ) # collision cost
371
- return ( n .cost + H_COST * h_dp [ind ].cost )
356
+ if ind not in h_dp :
357
+ return n .cost + 999999999 # collision cost
358
+ return n .cost + H_COST * h_dp [ind ].cost
372
359
373
360
374
361
def get_final_path (closed , ngoal , nstart , config ):
@@ -392,7 +379,7 @@ def get_final_path(closed, ngoal, nstart, config):
392
379
ryaw = list (reversed (ryaw ))
393
380
direction = list (reversed (direction ))
394
381
395
- # adjuct first direction
382
+ # adjust first direction
396
383
direction [0 ] = direction [1 ]
397
384
398
385
path = Path (rx , ry , ryaw , direction , finalcost )
@@ -457,12 +444,9 @@ def main():
457
444
path = hybrid_a_star_planning (
458
445
start , goal , ox , oy , XY_GRID_RESOLUTION , YAW_GRID_RESOLUTION )
459
446
460
- # plot_car(*start)
461
- # plot_car(*goal)
462
447
x = path .xlist
463
448
y = path .ylist
464
449
yaw = path .yawlist
465
- # direction = path.directionlist
466
450
467
451
for ix , iy , iyaw in zip (x , y , yaw ):
468
452
plt .cla ()
@@ -473,8 +457,7 @@ def main():
473
457
plot_car (ix , iy , iyaw )
474
458
plt .pause (0.0001 )
475
459
476
- plt .show ()
477
- print (__file__ + " start!!" )
460
+ print (__file__ + " done!!" )
478
461
479
462
480
463
if __name__ == '__main__' :
0 commit comments