1616import  reeds_shepp_path_planning  as  rs 
1717import  heapq 
1818from  car  import  move , check_car_collision , MAX_STEER , WB , plot_car 
19- from  a_star  import  dp_planning , calc_obstacle_map 
19+ from  a_star  import  dp_planning   # , calc_obstacle_map
2020
2121XY_GRID_RESOLUTION  =  2.0  #[m] 
2222YAW_GRID_RESOLUTION  =  np .deg2rad (15.0 ) #[rad] 
3838
3939show_animation  =  True 
4040
41- _round  =  round 
42- def  round (x ):
43-     return  int (_round (x ))
41+ #  _round = round
42+ #  def round(x):
43+ #      return int(_round(x))
4444
4545class  Node :
4646
@@ -92,9 +92,9 @@ def search(self, inp, k=1):
9292                dist .append (idist )
9393
9494            return  index , dist 
95-         else : 
96-              dist , index  =  self .tree .query (inp , k = k )
97-              return  index , dist 
95+         
96+         dist , index  =  self .tree .query (inp , k = k )
97+         return  index , dist 
9898
9999    def  search_in_distance (self , inp , r ):
100100        """ 
@@ -211,7 +211,7 @@ def analytic_expantion(current, goal, c, ox, oy, kdtree):
211211    paths  =  rs .calc_paths (sx ,sy ,syaw ,gx , gy , gyaw ,
212212                            max_curvature , step_size = MOTION_RESOLUTION )
213213
214-     if  not  len ( paths ) :
214+     if  not  paths :
215215        return  None 
216216
217217    best_path , best  =  None , None 
@@ -223,7 +223,7 @@ def analytic_expantion(current, goal, c, ox, oy, kdtree):
223223                best  =  cost 
224224                best_path  =  path 
225225
226-     return  best_path    # no update 
226+     return  best_path 
227227
228228
229229def  update_node_with_analystic_expantion (current , goal , 
@@ -309,7 +309,6 @@ def hybrid_a_star_planning(start, goal, ox, oy, xyreso, yawreso):
309309                 True , [goal [0 ]], [goal [1 ]], [goal [2 ]], [True ])
310310
311311    openList , closedList  =  {}, {}
312-     h  =  []
313312
314313    _ , _ , h_dp  =  dp_planning (nstart .xlist [- 1 ], nstart .ylist [- 1 ],
315314            ngoal .xlist [- 1 ], ngoal .ylist [- 1 ], ox , oy , xyreso , VR )
@@ -324,9 +323,12 @@ def hybrid_a_star_planning(start, goal, ox, oy, xyreso, yawreso):
324323            return  [], [], []
325324
326325        cost , c_id  =  heapq .heappop (pq )
327-         if  openList .has_key (c_id ):
326+         # if openList.has_key(c_id): # python 2.7 
327+         if  c_id  in  openList :
328328            current  =  openList .pop (c_id )
329329            closedList [c_id ] =  current 
330+         else :
331+             continue 
330332
331333        if  show_animation :  # pragma: no cover 
332334            plt .plot (current .xlist [- 1 ], current .ylist [- 1 ], "xc" )
@@ -341,23 +343,21 @@ def hybrid_a_star_planning(start, goal, ox, oy, xyreso, yawreso):
341343
342344        for  neighbor  in  get_neighbors (current , config , ox , oy , obkdtree ):
343345            neighbor_index  =  calc_index (neighbor , config )
344-             if  closedList .has_key (neighbor_index ):
346+             # if closedList.has_key(neighbor_index): 
347+             if  neighbor_index  in  closedList :
345348                continue 
346-             if  not  openList . has_key ( neighbor_index )  \
347-                 or  openList [neighbor_index ].cost  >  neighbor .cost :  # TODO huristic 
349+             if  not  neighbor   in   openList  \
350+                 or  openList [neighbor_index ].cost  >  neighbor .cost :
348351                heapq .heappush (pq , (calc_cost (neighbor , h_dp , ngoal , config ), neighbor_index ))
349352                openList [neighbor_index ] =  neighbor 
350353
351-         #  print(current) 
352- 
353-     rx , ry , ryaw  =  [], [], []
354354
355355    path  =  get_final_path (closedList , fpath , nstart , config )
356356    return  path 
357357
358358def  calc_cost (n , h_dp , goal , c ):
359359    ind  =  (n .yind  -  c .miny ) *  c .xw  +  (n .xind  -  c .minx )
360-     if  not  h_dp . has_key ( ind ) :
360+     if  not  ind   in   h_dp :
361361        return  (n .cost  +  999999999 ) # collision cost 
362362    return  (n .cost  +  H_COST * h_dp [ind ].cost )
363363
@@ -451,7 +451,7 @@ def main():
451451    x  =  path .xlist 
452452    y  =  path .ylist 
453453    yaw  =  path .yawlist 
454-     direction  =  path .directionlist 
454+     #  direction = path.directionlist
455455
456456    for  ix , iy , iyaw  in  zip (x , y , yaw ):
457457        plt .cla ()
0 commit comments