From 621023380a8117b2881f53d6b133dc29336e681e Mon Sep 17 00:00:00 2001 From: DCCONSTRUCTIONS Date: Sat, 10 Oct 2026 06:13:32 +0300 Subject: [PATCH] Keep detector planning reserve out of native body collision map --- .../nav2/check_collision_domains.py | 67 ++++++++++++++----- .../ai-polygon/nav2/detector_exclusion.py | 2 +- .../ai-polygon/nav2/observed_collision.py | 9 ++- 3 files changed, 59 insertions(+), 19 deletions(-) diff --git a/simulation/ai-polygon/nav2/check_collision_domains.py b/simulation/ai-polygon/nav2/check_collision_domains.py index 8fe7ad04..82645aeb 100644 --- a/simulation/ai-polygon/nav2/check_collision_domains.py +++ b/simulation/ai-polygon/nav2/check_collision_domains.py @@ -1,8 +1,9 @@ """Bounded native BackUp check on archived observations, without an actuator. -Captured geometry receives an explicit synthetic ground restriction beneath -future body overhang, with stationary odometry/fresh times. This verifies -native collision plumbing, never route or physical acceptance. +Fixtures use an explicit synthetic ground restriction or archived detector +returns. Recorded pose history restores prior footprint clearing, then odometry +is held stationary with fresh times. This checks collision plumbing without +an actuator; it is not route or physical acceptance. """ import argparse import json @@ -19,6 +20,9 @@ from action_msgs.msg import GoalStatus from configuration import observed_configuration from observed_collision import ObservedCollision from ros_navigation import RosNavigation, yaw_of +from navigation.detection_obstacles import DetectionObstacles +from navigation.footprint import Footprint +from rig_collision import collision_geometry def main(): @@ -26,26 +30,38 @@ def main(): for name in ('inputs', 'robot', 'snapshot', 'output'): parser.add_argument('--'+name, type=Path, required=True) parser.add_argument('--mixed', action='store_true') + parser.add_argument('--detector', action='store_true') args = parser.parse_args() args.output.mkdir(exist_ok=False, parents=True) inputs = json.loads(args.inputs.read_text()) snapshot = json.loads(args.snapshot.read_text()) request = snapshot['latest_plan']['request'] assert request['execution_inputs_sha256'] == inputs['sha256'] - assert not snapshot['current_detected'], 'This recorded fixture has no detections' + detected = np.asarray(snapshot['current_detected'], dtype=float).reshape(-1,3) + assert args.detector or not len(detected), 'Select --detector for detector fixtures' request['geometry_age_seconds'] = 0. physical = np.array(snapshot['geometry']) search = np.array(snapshot['search_terrain']) pose = np.asarray(request['pose']); yaw = yaw_of(pose) axes = np.array([[math.cos(yaw), -math.sin(yaw)], [math.sin(yaw), math.cos(yaw)]]) local = (search[:, :2]-pose[:2]) @ axes - # A ground restriction 83 cm behind the origin intersects the mounted - # body's predicted reverse sweep, but not the shorter track sweep. - selected = int(np.argmin(np.linalg.norm(local-[-.83, 0.], axis=1))) - assert -.9 < local[selected, 0] < -.78 and abs(local[selected, 1]) < .07 - assert search[selected, 3] <= inputs['robot']['geometry']['max_step_m'] - search[selected, 3] = 1. - synthetic_ground_hint = search[selected].tolist() + guard_receipt = None + synthetic_ground_hint = None + if args.detector: + geometry = collision_geometry(inputs['robot']['geometry'], inputs['sensors']['mounts']) + guard = DetectionObstacles(Footprint(geometry)) + guard_receipt = dict(reverse=guard.regulate(-.1,0.,detected,pose), + approach=guard.regulate(.1,0.,detected,pose)) + assert guard_receipt['reverse']==(-.1,0.,1.), guard_receipt + assert guard_receipt['approach']==(0.,0.,0.), guard_receipt + else: + # A ground restriction 83 cm behind the origin intersects the mounted + # body's predicted reverse sweep, but not the shorter track sweep. + selected = int(np.argmin(np.linalg.norm(local-[-.83, 0.], axis=1))) + assert -.9 < local[selected, 0] < -.78 and abs(local[selected, 1]) < .07 + assert search[selected, 3] <= inputs['robot']['geometry']['max_step_m'] + search[selected, 3] = 1. + synthetic_ground_hint = search[selected].tolist() config = observed_configuration(inputs, json.loads(args.robot.read_text()), 2) parameters = args.output/'parameters.yaml' parameters.write_text(yaml.safe_dump(config, sort_keys=False)) @@ -54,25 +70,33 @@ def main(): collision = ObservedCollision(node, inputs['robot']['geometry']['max_step_m'], 2) running = threading.Event(); running.set() lock = threading.Lock() - state = dict(physical=search if args.mixed else physical) + if args.detector and args.mixed: + reserve = collision.detector_exclusion.points(detected, request['pose']) + old_costs = np.column_stack((reserve,np.zeros(len(reserve)),np.ones(len(reserve)))) + initial = np.vstack((physical,old_costs)) + else: + initial = search if args.mixed else physical + history = snapshot.get('pose_history', []) + state = dict(physical=initial, pose=history[0] if history else request['pose']) errors, commands, processes, logs = [], [], [], [] spinner = threading.Thread(target=rclpy.spin, args=(node,)) def publish(): try: while running.is_set(): - node.observe_pose(request['pose'], .01, [0., 0., 0.]) with lock: - terrain = state['physical'] - assert collision.publish(request, terrain, 0., search_terrain=search) + terrain, current_pose = state['physical'], state['pose'] + node.observe_pose(current_pose, .01, [0., 0., 0.]) + assert collision.publish(request, terrain, 0., search_terrain=search, detected=detected) commands.append(node.native_command()) time.sleep(.08) except BaseException as error: errors.append(str(error)) source = threading.Thread(target=publish) - report = dict(passed=False, mixed=args.mixed, authority=None, - scope='Native collision-domain regression; synthetic ground hint on archived range, stationary odometry, no actuator', + report = dict(passed=False, mixed=args.mixed, detector=args.detector, + exact_guard=guard_receipt, fixture_scope=snapshot.get('scope'), authority=None, + scope='Native collision-domain regression on an archived fixture; stationary action odometry, no actuator', synthetic_ground_hint=synthetic_ground_hint) try: spinner.start(); source.start() @@ -86,6 +110,14 @@ def main(): ('behavior' if package == 'nav2_behaviors' else 'controller')+'_cmd_vel'], stdout=log, stderr=subprocess.STDOUT)) node.activate() + # Rebuild only the body's actually recorded clearing history. An + # isolated last scan otherwise invents unknown holes behind the rover. + for prior_pose in history: + with lock: + state['pose'] = prior_pose + time.sleep(.24) + with lock: + state['pose'] = request['pose'] time.sleep(.8) node.backup(.8, .1, 0.) started = time.monotonic() @@ -94,6 +126,7 @@ def main(): report['held_seconds'] = time.monotonic()-started report['terminal_status'] = node.terminal.result().status if node.terminal.done() else None report['reverse_samples'] = sum(c is not None and c[1] < 0 for c in commands) + (args.output/'costmaps.json').write_text(json.dumps(node.diagnostic())) if args.mixed: assert report['terminal_status'] == GoalStatus.STATUS_ABORTED, report else: diff --git a/simulation/ai-polygon/nav2/detector_exclusion.py b/simulation/ai-polygon/nav2/detector_exclusion.py index e85fbc0b..dc77d601 100644 --- a/simulation/ai-polygon/nav2/detector_exclusion.py +++ b/simulation/ai-polygon/nav2/detector_exclusion.py @@ -1,4 +1,4 @@ -"""Rasterise detector reserve as collision costs, never as sensor measurements. +"""Rasterise detector reserve as search costs, never as sensor measurements. A rectangle enlarged on both axes by d lies inside its Minkowski sum with a radius sqrt(2)*d disk. This covers the command guard's 35 cm reserve at every diff --git a/simulation/ai-polygon/nav2/observed_collision.py b/simulation/ai-polygon/nav2/observed_collision.py index 5bfb27de..20c5cb5a 100644 --- a/simulation/ai-polygon/nav2/observed_collision.py +++ b/simulation/ai-polygon/nav2/observed_collision.py @@ -61,6 +61,13 @@ class ObservedCollision: hazards = terrain[terrain[:,3]>self.max_step+1e-4,:2] search = search_terrain[search_terrain[:,3]>self.max_step+1e-4,:2] reserve = self.detector_exclusion.points(detected, request['pose']) - self.hazards.publish(cloud(stamp,'map',np.concatenate((hazards,reserve)))) + # Reserve is a search constraint, not an observed solid object. It may + # already enclose the body when a new detection arrives. Making it + # lethal locally prevents native BackUp from leaving that reserve. + # Keep original returns in the body map; the independent exact sweep + # guard still enforces the reserve and forbids closer motion when the + # rover is already inside it. + detected_xy = np.asarray(detected, dtype=float).reshape(-1,3)[:,:2] + self.hazards.publish(cloud(stamp,'map',np.concatenate((hazards,detected_xy)))) self.search.publish(cloud(stamp,'map',np.concatenate((search,reserve)))) return True