Skip to content

Commit 25ea050

Browse files
committed
Move presets to constants
1 parent c152ffc commit 25ea050

File tree

2 files changed

+78
-7
lines changed

2 files changed

+78
-7
lines changed

constants.py

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
DEFAULT_CHECK_COLLISIONS: bool = True
1010

1111
# RRT / planning
12-
DEFAULT_NUM_ITER: int = 200
13-
DEFAULT_DISCRETISATION_STEPS: int = 100
12+
DEFAULT_NUM_ITER: int = 500
13+
DEFAULT_DISCRETISATION_STEPS: int = 8
1414
DEFAULT_CHECK_EDGE_STEPS: int = 1000
1515
EDGE_DISTANCE_TOL: float = 1e-3
1616

@@ -21,3 +21,37 @@
2121
DEFAULT_SAMPLER_SHRINK: float = 0.3
2222
# When sampling on the vertical plane, allow a small half-width (meters) perpendicular to the plane
2323
DEFAULT_PLANE_HALF_WIDTH: float = 0.02
24+
25+
# Planner-specific defaults (tunable)
26+
DEFAULT_REPAIR_ATTEMPTS: int = 5
27+
DEFAULT_GOAL_BIAS: float = 0.03
28+
DEFAULT_MAX_IK_ATTEMPTS: int = 3
29+
DEFAULT_MAX_TIME_S: float = 30.0
30+
31+
# Preset bundles for convenience: 'fast', 'default', 'robust'
32+
PRESETS = {
33+
'fast': {
34+
'num_iter': 200,
35+
'discretisation': 8,
36+
'repair_attempts': 3,
37+
'goal_bias': 0.02,
38+
'max_ik_attempts': 3,
39+
'max_time_s': 15.0,
40+
},
41+
'default': {
42+
'num_iter': 500,
43+
'discretisation': 8,
44+
'repair_attempts': 5,
45+
'goal_bias': 0.03,
46+
'max_ik_attempts': 3,
47+
'max_time_s': 30.0,
48+
},
49+
'robust': {
50+
'num_iter': 1000,
51+
'discretisation': 10,
52+
'repair_attempts': 8,
53+
'goal_bias': 0.05,
54+
'max_ik_attempts': 5,
55+
'max_time_s': 60.0,
56+
}
57+
}

path.py

Lines changed: 42 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,19 @@
77
from sampling import random_cube_placement
88
import sampling as sampling_module
99
from 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+
)
1123
from tools import setcubeplacement
1224
import time
1325
import 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

Comments
 (0)