77""" 
88
99import  heapq 
10- import  matplotlib .pyplot  as  plt 
1110import  scipy .spatial 
1211import  numpy  as  np 
1312import  math 
14- 
13+ import   matplotlib . pyplot   as   plt 
1514import  sys 
1615sys .path .append ("../ReedsSheppPath/" )
1716try :
2423
2524XY_GRID_RESOLUTION  =  2.0   # [m] 
2625YAW_GRID_RESOLUTION  =  np .deg2rad (15.0 )  # [rad] 
27- GOAL_TYAW_TH  =  np .deg2rad (5.0 )  # [rad] 
2826MOTION_RESOLUTION  =  0.1   # [m] path interporate resolution 
2927N_STEER  =  20.0   # number of steer command 
30- EXTEND_AREA  =  0.0   # [m] 
3128H_COST  =  1.0 
32- MOTION_RESOLUTION  =  0.1 
33- SKIP_COLLISION_CHECK  =  4 
3429VR  =  1.0   # robot radius 
3530
3631SB_COST  =  100.0   # switch back penalty cost 
3732BACK_COST  =  5.0   # backward penalty cost 
3833STEER_CHANGE_COST  =  5.0   # steer angle change penalty cost 
3934STEER_COST  =  1.0   # steer angle change penalty cost 
40- # JACKKNIF_COST= 200.0 # Jackknif cost 
4135H_COST  =  5.0   # Heuristic cost 
4236
4337show_animation  =  True 
4438
45- # _round = round 
46- # def round(x): 
47- #     return int(_round(x)) 
48- 
4939
5040class  Node :
5141
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 ):
5345        self .xind  =  xind 
5446        self .yind  =  yind 
5547        self .yawind  =  yawind 
@@ -114,10 +106,10 @@ def search_in_distance(self, inp, r):
114106class  Config :
115107
116108    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 )
121113
122114        ox .append (min_x_m )
123115        oy .append (min_y_m )
@@ -137,10 +129,6 @@ def __init__(self, ox, oy, xyreso, yawreso):
137129        self .yaww  =  round (self .maxyaw  -  self .minyaw )
138130
139131
140- def  show_expansion_tree ():
141-     pass 
142- 
143- 
144132def  calc_motion_inputs ():
145133
146134    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):
168156        ylist .append (y )
169157        yawlist .append (yaw )
170158
171-     # plt.plot(xlist, ylist) 
172159    if  not  check_car_collision (xlist , ylist , yawlist , ox , oy , kdtree ):
173160        return  None 
174161
@@ -252,7 +239,8 @@ def update_node_with_analystic_expantion(current, goal,
252239
253240        fsteer  =  0.0 
254241        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 )
256244        return  True , fpath 
257245
258246    return  False , None 
@@ -331,7 +319,6 @@ def hybrid_a_star_planning(start, goal, ox, oy, xyreso, yawreso):
331319            return  [], [], []
332320
333321        cost , c_id  =  heapq .heappop (pq )
334-         # if openList.has_key(c_id): # python 2.7 
335322        if  c_id  in  openList :
336323            current  =  openList .pop (c_id )
337324            closedList [c_id ] =  current 
@@ -351,13 +338,13 @@ def hybrid_a_star_planning(start, goal, ox, oy, xyreso, yawreso):
351338
352339        for  neighbor  in  get_neighbors (current , config , ox , oy , obkdtree ):
353340            neighbor_index  =  calc_index (neighbor , config )
354-             # if closedList.has_key(neighbor_index): 
355341            if  neighbor_index  in  closedList :
356342                continue 
357-             if  not   neighbor  in  openList  \
343+             if  neighbor   not  in   openList  \
358344                    or  openList [neighbor_index ].cost  >  neighbor .cost :
359345                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 ))
361348                openList [neighbor_index ] =  neighbor 
362349
363350    path  =  get_final_path (closedList , fpath , nstart , config )
@@ -366,9 +353,9 @@ def hybrid_a_star_planning(start, goal, ox, oy, xyreso, yawreso):
366353
367354def  calc_cost (n , h_dp , goal , c ):
368355    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 
372359
373360
374361def  get_final_path (closed , ngoal , nstart , config ):
@@ -392,7 +379,7 @@ def get_final_path(closed, ngoal, nstart, config):
392379    ryaw  =  list (reversed (ryaw ))
393380    direction  =  list (reversed (direction ))
394381
395-     # adjuct  first direction 
382+     # adjust  first direction 
396383    direction [0 ] =  direction [1 ]
397384
398385    path  =  Path (rx , ry , ryaw , direction , finalcost )
@@ -457,12 +444,9 @@ def main():
457444    path  =  hybrid_a_star_planning (
458445        start , goal , ox , oy , XY_GRID_RESOLUTION , YAW_GRID_RESOLUTION )
459446
460-     # plot_car(*start) 
461-     # plot_car(*goal) 
462447    x  =  path .xlist 
463448    y  =  path .ylist 
464449    yaw  =  path .yawlist 
465-     # direction = path.directionlist 
466450
467451    for  ix , iy , iyaw  in  zip (x , y , yaw ):
468452        plt .cla ()
@@ -473,8 +457,7 @@ def main():
473457        plot_car (ix , iy , iyaw )
474458        plt .pause (0.0001 )
475459
476-     plt .show ()
477-     print (__file__  +  " start!!" )
460+     print (__file__  +  " done!!" )
478461
479462
480463if  __name__  ==  '__main__' :
0 commit comments