77from sampling import random_cube_placement
88import sampling as sampling_module
99from rrt import Vertex , RRT , construct_rrt
10- from constants import DEFAULT_NUM_ITER , DEFAULT_DISCRETISATION_STEPS , DEFAULT_VIZ_DELAY , DEFAULT_SAMPLER_SHRINK , DEFAULT_PLANE_HALF_WIDTH , DEFAULT_TABLE_Z_RANGE
10+ from constants import (
11+ DEFAULT_NUM_ITER ,
12+ DEFAULT_DISCRETISATION_STEPS ,
13+ DEFAULT_VIZ_DELAY ,
14+ DEFAULT_SAMPLER_SHRINK ,
15+ DEFAULT_PLANE_HALF_WIDTH ,
16+ DEFAULT_TABLE_Z_RANGE ,
17+ PRESETS ,
18+ DEFAULT_REPAIR_ATTEMPTS ,
19+ DEFAULT_GOAL_BIAS ,
20+ DEFAULT_MAX_IK_ATTEMPTS ,
21+ DEFAULT_MAX_TIME_S ,
22+ )
1123from tools import setcubeplacement
1224import time
1325import logging
@@ -36,6 +48,7 @@ def computepath(qinit,
3648 num_iter : int = DEFAULT_NUM_ITER ,
3749 discretisation_steps : int = DEFAULT_DISCRETISATION_STEPS ,
3850 max_ik_attempts : int = None ,
51+ max_time_s : float = DEFAULT_MAX_TIME_S ,
3952 post_path_wait : float = 5.0 ,
4053 random_sampler = None ,
4154 repair_sampler = None ,
@@ -131,7 +144,7 @@ def plane_sampler():
131144 max_delta_q = MAX_DELTA_Q ,
132145 cubeplacementqgoal = cubeplacementqgoal ,
133146 q_goal = qgoal ,
134- max_time_s = None ,
147+ max_time_s = max_time_s ,
135148 progress_log_every = 50 ,
136149 repair_sampler = repair_sampler ,
137150 repair_max_attempts = repair_max_attempts ,
@@ -204,6 +217,7 @@ def displaypath(robot, cube, path, cube_placements, dt, viz):
204217 parser .add_argument ('--smart-global' , action = 'store_true' , help = 'Use the smart sampler as the global sampler instead of repair-only' )
205218 parser .add_argument ('--goal-bias' , type = float , default = 0.02 , help = 'Probability to sample the goal directly on each iteration (0.0-1.0)' )
206219 parser .add_argument ('--playback' , action = 'store_true' , help = 'Show the final path even if planning ran with --no-viz' )
220+ parser .add_argument ('--preset' , choices = ['fast' , 'default' , 'robust' ], default = None , help = 'Use a preset bundle of planner defaults' )
207221 args = parser .parse_args ()
208222
209223 logging .basicConfig (level = logging .INFO )
@@ -221,6 +235,24 @@ def displaypath(robot, cube, path, cube_placements, dt, viz):
221235 raise SystemExit (1 )
222236
223237 viz_obj = None if args .no_viz else viz
238+ # Resolve preset values (CLI args override preset). We detect explicit
239+ # CLI overrides by checking sys.argv for the flag name.
240+ import sys
241+ preset_values = PRESETS .get (args .preset ) if args .preset is not None else {}
242+ def use_or_preset (flag_name , current_value ):
243+ # Return CLI-provided value if flag present, otherwise preset or current_value
244+ if f'--{ flag_name } ' in sys .argv :
245+ return current_value
246+ if preset_values and flag_name in preset_values :
247+ return preset_values [flag_name ]
248+ return current_value
249+
250+ resolved_num_iter = use_or_preset ('num-iter' , args .num_iter )
251+ resolved_discretisation = use_or_preset ('discretisation' , args .discretisation )
252+ resolved_repair_attempts = use_or_preset ('repair-attempts' , args .repair_attempts )
253+ resolved_goal_bias = use_or_preset ('goal-bias' , args .goal_bias )
254+ resolved_max_ik_attempts = use_or_preset ('max-ik-attempts' , args .max_ik_attempts if args .max_ik_attempts is not None else DEFAULT_MAX_IK_ATTEMPTS )
255+ resolved_max_time = use_or_preset ('max-time' , args .max_time if args .max_time is not None else DEFAULT_MAX_TIME_S )
224256 # choose sampler: either let computepath build the plane sampler, or build a smart sampler here
225257 RANDOM_SAMPLER = None
226258 REPAIR_SAMPLER = None
@@ -303,13 +335,18 @@ def plane_sampler():
303335 robot = robot ,
304336 cube = cube ,
305337 computeqgrasppose = computeqgrasppose ,
306- num_iter = args . num_iter ,
307- discretisation_steps = args . discretisation ,
338+ num_iter = resolved_num_iter ,
339+ discretisation_steps = resolved_discretisation ,
308340 random_sampler = RANDOM_SAMPLER ,
309341 repair_sampler = REPAIR_SAMPLER ,
342+ repair_max_attempts = resolved_repair_attempts ,
343+ goal_bias = resolved_goal_bias ,
310344 viz = viz_obj ,
311345 viz_delay = args .viz_delay ,
312- max_ik_attempts = args .max_ik_attempts ,
346+ max_ik_attempts = resolved_max_ik_attempts ,
347+ # forward wall-time
348+ # Note: computepath forwards this into construct_rrt/RRT.run
349+ max_time_s = resolved_max_time ,
313350 )
314351
315352 # optionally playback the final path. If --playback is set we show the
0 commit comments