1212import math
1313import matplotlib .pyplot as plt
1414import sys
15- sys .path .append ("../ReedsSheppPath/" )
15+ import os
16+
17+ sys .path .append (os .path .dirname (os .path .abspath (__file__ ))
18+ + "/../ReedsSheppPath" )
1619try :
1720 from a_star_heuristic import dp_planning # , calc_obstacle_map
1821 import reeds_shepp_path_planning as rs
1922 from car import move , check_car_collision , MAX_STEER , WB , plot_car
20- except :
23+ except Exception :
2124 raise
2225
2326
2427XY_GRID_RESOLUTION = 2.0 # [m]
2528YAW_GRID_RESOLUTION = np .deg2rad (15.0 ) # [rad]
2629MOTION_RESOLUTION = 0.1 # [m] path interporate resolution
27- N_STEER = 20.0 # number of steer command
30+ N_STEER = 20 # number of steer command
2831H_COST = 1.0
2932VR = 1.0 # robot radius
3033
@@ -131,7 +134,8 @@ def __init__(self, ox, oy, xyreso, yawreso):
131134
132135def calc_motion_inputs ():
133136
134- for steer in np .concatenate ((np .linspace (- MAX_STEER , MAX_STEER , N_STEER ),[0.0 ])):
137+ for steer in np .concatenate ((np .linspace (- MAX_STEER , MAX_STEER ,
138+ N_STEER ), [0.0 ])):
135139 for d in [1 , - 1 ]:
136140 yield [steer , d ]
137141
@@ -225,7 +229,8 @@ def update_node_with_analystic_expantion(current, goal,
225229 apath = analytic_expantion (current , goal , c , ox , oy , kdtree )
226230
227231 if apath :
228- plt .plot (apath .x , apath .y )
232+ if show_animation :
233+ plt .plot (apath .x , apath .y )
229234 fx = apath .x [1 :]
230235 fy = apath .y [1 :]
231236 fyaw = apath .yaw [1 :]
@@ -337,6 +342,7 @@ def hybrid_a_star_planning(start, goal, ox, oy, xyreso, yawreso):
337342 current , ngoal , config , ox , oy , obkdtree )
338343
339344 if isupdated :
345+ print ("path found" )
340346 break
341347
342348 for neighbor in get_neighbors (current , config , ox , oy , obkdtree ):
@@ -437,12 +443,16 @@ def main():
437443 start = [10.0 , 10.0 , np .deg2rad (90.0 )]
438444 goal = [50.0 , 50.0 , np .deg2rad (- 90.0 )]
439445
440- plt .plot (ox , oy , ".k" )
441- rs .plot_arrow (start [0 ], start [1 ], start [2 ], fc = 'g' )
442- rs .plot_arrow (goal [0 ], goal [1 ], goal [2 ])
446+ print ("start : " , start )
447+ print ("goal : " , goal )
448+
449+ if show_animation :
450+ plt .plot (ox , oy , ".k" )
451+ rs .plot_arrow (start [0 ], start [1 ], start [2 ], fc = 'g' )
452+ rs .plot_arrow (goal [0 ], goal [1 ], goal [2 ])
443453
444- plt .grid (True )
445- plt .axis ("equal" )
454+ plt .grid (True )
455+ plt .axis ("equal" )
446456
447457 path = hybrid_a_star_planning (
448458 start , goal , ox , oy , XY_GRID_RESOLUTION , YAW_GRID_RESOLUTION )
@@ -451,14 +461,15 @@ def main():
451461 y = path .ylist
452462 yaw = path .yawlist
453463
454- for ix , iy , iyaw in zip (x , y , yaw ):
455- plt .cla ()
456- plt .plot (ox , oy , ".k" )
457- plt .plot (x , y , "-r" , label = "Hybrid A* path" )
458- plt .grid (True )
459- plt .axis ("equal" )
460- plot_car (ix , iy , iyaw )
461- plt .pause (0.0001 )
464+ if show_animation :
465+ for ix , iy , iyaw in zip (x , y , yaw ):
466+ plt .cla ()
467+ plt .plot (ox , oy , ".k" )
468+ plt .plot (x , y , "-r" , label = "Hybrid A* path" )
469+ plt .grid (True )
470+ plt .axis ("equal" )
471+ plot_car (ix , iy , iyaw )
472+ plt .pause (0.0001 )
462473
463474 print (__file__ + " done!!" )
464475
0 commit comments