11import os
22import argparse
33import time
4- import math
5- import matplotlib .pyplot as plt
6- import numpy as np
74import matplotlib
8- # from collision import build_collision_lookup
9- # from kinodynamic_rrt_star import OptimizedKinodynamicRRT
10- # from map_utils import load_pgm_to_occupancy_grid
11- # from visualization import visualize_path, animate_path
5+
126from .collision import build_collision_lookup
13- from .map_utils import world_to_grid , grid_to_world
7+ from .map_utils import load_pgm_to_occupancy_grid
148from .visualization import visualize_path , animate_path
159from .kinodynamic_rrt_star import OptimizedKinodynamicRRT
16- def optimized_kinodynamic_rrt_planning ( start_world , goal_world , occupancy_grid , metadata = None ,
17- safety_margin = 10 , vehicle_width = 5 , step_size = 1.0 ,
18- turning_radius = 3 .0 , max_iterations = 100000 , bidirectional = True ):
10+
11+ def optimized_kinodynamic_rrt_planning ( start_world , goal_world , occupancy_grid , safety_margin = 10 ,
12+ vehicle_width = 20 , vehicle_length = 45 .0 , step_size = 1.0 , max_iterations = 100000 ):
1913 """
20- parser.add_argument("--test", action="store_true", help="run unit tests and exit")
21- parser.add_argument("--vis", default=True, action="store_true", help="show visualizations for tests or planning result")
22- parser.add_argument("--animate", "-a", action="store_true", help="animate planned path")
23- parser.add_argument("--max-iter", type=int, default=20000, help="maximum RRT iterations")
24- parser.add_argument("--pad", type=int, default=100, help="crop padding (cells)")
25- parser.add_argument("--safety", type=int, default=2, help="safety margin (cells)")
26- parser.add_argument("--map-pgm", type=str, default="occupancy_grid_after_>0.pgm", help="path to PGM map file")
27- parser.add_argument("--map-yaml", type=str, default="rrt_occupancy_map.yaml", help="path to YAML metadata file")
28- parser.add_argument("--step-size", type=float, default=1.0, help="step size for path sampling")
29- parser.add_argument("--turning-radius", type=float, default=1.0, help="minimum turning radius")
30- parser.add_argument("--vehicle-width", type=float, default=1.5, help="vehicle width in meters")
31- parser.add_argument("--bidirectional", type=bool, default=False, help="Use bidirectional RRT*")
32- Optimized Kinodynamic RRT planning from start to goal
33-
3414 Args:
3515 start_world: (x, y, theta) start position in world coordinates
3616 goal_world: (x, y, theta) goal position in world coordinates
3717 occupancy_grid: Binary occupancy grid (1=obstacle, 0=free)
38- metadata: Map metadata
3918 safety_margin: Safety margin in grid cells
4019 vehicle_width: Vehicle width in meters
4120 step_size: Step size for path sampling
@@ -77,18 +56,21 @@ def optimized_kinodynamic_rrt_planning(start_world, goal_world, occupancy_grid,
7756 # Initialize planner with optimized parameters
7857 planner = OptimizedKinodynamicRRT (
7958 occupancy_grid = occupancy_grid ,
80- collision_lookup = collision_lookup ,
81- start_pose = start_grid ,
82- goal_pose = goal_grid ,
83- max_iter = max_iterations ,
59+ collision_lookup_table = collision_lookup ,
60+ start_pose_tuple = start_grid ,
61+ goal_pose_tuple = goal_grid ,
62+ max_iterations = max_iterations ,
63+ local_sampling_step_size = step_size ,
64+ vehicle_width = vehicle_width ,
65+ vehicle_length = vehicle_length
8466 # bidirectional=bidirectional
8567 )
8668
8769 ## Testing Summoning RRT implementation
8870 # planner = BiRRT(start_grid, goal_grid, 1-occupancy_grid, [0,4384,0,4667])
8971 # grid_path = planner.search()
9072 t_rrt = time .time ()
91- grid_path = planner .plan (visualize_final = True )
73+ grid_path = planner .plan (visualize_planning_output = True )
9274 # anim = planner.animate_sampling()
9375 t_rrt_final = time .time () - t_rrt
9476 print (f"RRT planning completed in { t_rrt_final :.2f} s" )
@@ -103,51 +85,31 @@ def optimized_kinodynamic_rrt_planning(start_world, goal_world, occupancy_grid,
10385
10486 return grid_path
10587
88+ # Used for local testing
10689def main ():
10790 """Main function for running the planner."""
10891 parser = argparse .ArgumentParser (description = "Optimized Kinodynamic RRT planner" )
109- parser .add_argument ("--test" , action = "store_true" , help = "run unit tests and exit" )
11092 parser .add_argument ("--vis" , default = True , action = "store_true" , help = "show visualizations for tests or planning result" )
11193 parser .add_argument ("--animate" , "-a" , action = "store_true" , help = "animate planned path" )
112- parser .add_argument ("--max-iter" , type = int , default = 20000 , help = "maximum RRT iterations" )
94+ parser .add_argument ("--max-iter" , type = int , default = 10000 , help = "maximum RRT iterations" )
11395 parser .add_argument ("--pad" , type = int , default = 100 , help = "crop padding (cells)" )
11496 parser .add_argument ("--safety" , type = int , default = 2 , help = "safety margin (cells)" )
11597 parser .add_argument ("--map-pgm" , type = str , default = "occupancy_grid_after_>0.pgm" , help = "path to PGM map file" )
116- parser .add_argument ("--map-yaml" , type = str , default = "rrt_occupancy_map.yaml" , help = "path to YAML metadata file" )
117- parser .add_argument ("--step-size" , type = float , default = 1.0 , help = "step size for path sampling" )
118- parser .add_argument ("--turning-radius" , type = float , default = 1.0 , help = "minimum turning radius" )
119- parser .add_argument ("--vehicle-width" , type = float , default = 1.5 , help = "vehicle width in meters" )
120- parser .add_argument ("--bidirectional" , type = bool , default = False , help = "Use bidirectional RRT*" )
121-
122- # parser = argparse.ArgumentParser(description="Optimized Kinodynamic RRT planner")
123- # parser.add_argument("--test", action="store_true", help="run unit tests and exit")
124- # parser.add_argument("--vis", action="store_true", help="show visualizations for tests or planning result")
125- # parser.add_argument("--animate", "-a", action="store_true", help="animate planned path")
126- # parser.add_argument("--max-iter", type=int, default=10000, help="maximum RRT iterations")
127- # parser.add_argument("--pad", type=int, default=100, help="crop padding (cells)")
128- # parser.add_argument("--safety", type=int, default=2, help="safety margin (cells)")
129- # parser.add_argument("--map-pgm", type=str, default="rrt_occupancy_map.pgm", help="path to PGM map file")
130- # parser.add_argument("--map-yaml", type=str, default="rrt_occupancy_map.yaml", help="path to YAML metadata file")
131- # parser.add_argument("--step-size", type=float, default=5.0, help="step size for path sampling")
132- # parser.add_argument("--turning-radius", type=float, default=100.0, help="minimum turning radius")
133- # parser.add_argument("--vehicle-width", type=float, default=12.0, help="vehicle width in meters")
134- # parser.add_argument("--bidirectional", type=bool, default=False, help="Use bidirectional RRT*")
98+ parser .add_argument ("--step-size" , type = float , default = 100.0 , help = "step size for path sampling" )
99+ parser .add_argument ("--vehicle-width" , type = float , default = 20 , help = "vehicle width in meters" )
100+ parser .add_argument ("--vehicle-length" , type = float , default = 45 , help = "vehicle length in meters" )
135101
136102 if "--vis" not in os .sys .argv and "--animate" not in os .sys .argv and "-a" not in os .sys .argv :
137103 matplotlib .use ("Agg" )
138104
139105 args = parser .parse_args ()
140106
141- if args .test :
142- run_tests (show = args .vis )
143- return
144-
145- if not (os .path .exists (args .map_pgm ) and os .path .exists (args .map_yaml )):
146- print (f"Map files not found: { args .map_pgm } and/or { args .map_yaml } " )
147- print ("Use --test for CI runs or provide map files with --map-pgm and --map-yaml" )
107+ if not (os .path .exists (args .map_pgm )):
108+ print (f"Map files not found: { args .map_pgm } " )
109+ print ("Use --test for CI runs or provide map files with --map-pgm" )
148110 return
149111
150- occupancy_grid , meta = load_pgm_to_occupancy_grid (args .map_pgm , args . map_yaml )
112+ occupancy_grid = load_pgm_to_occupancy_grid (args .map_pgm )
151113
152114 # start_w = (-200.0, -137.0, 0 * math.pi / 2)
153115 # goal_w = (-100.0, -137.0, 3*math.pi/2)
@@ -160,24 +122,22 @@ def main():
160122 # goal_w = (15.0, 11.0, 2*math.pi/2)
161123 # goal_w = (.0, 5.0, 1*math.pi/2)
162124
163- visualize_path (occupancy_grid , [], meta , start_w , goal_w )
125+ visualize_path (occupancy_grid , [], start_w , goal_w )
164126
165127 path = optimized_kinodynamic_rrt_planning (
166- start_w , goal_w , occupancy_grid , meta ,
128+ start_w , goal_w , occupancy_grid ,
167129 safety_margin = args .safety ,
168130 vehicle_width = args .vehicle_width ,
169131 step_size = args .step_size ,
170- turning_radius = args .turning_radius ,
171132 max_iterations = args .max_iter ,
172- bidirectional = args .bidirectional
173133 )
174134
175135 if path :
176136 print (f"Planned path with { len (path )} poses" )
177137 if args .vis :
178- visualize_path (occupancy_grid , path , meta , start_w , goal_w )
138+ visualize_path (occupancy_grid , path , start_w , goal_w )
179139 if args .animate :
180- animate_path (occupancy_grid , path , meta , pad_cells = args .pad )
140+ animate_path (occupancy_grid , path , pad_cells = args .pad )
181141 else :
182142 print ("Failed to find path" )
183143
0 commit comments