Keep detector planning reserve out of native body collision map

This commit is contained in:
DCCONSTRUCTIONS
2026-10-10 06:13:32 +03:00
parent 3657998f9d
commit 621023380a
3 changed files with 59 additions and 19 deletions
@@ -1,8 +1,9 @@
"""Bounded native BackUp check on archived observations, without an actuator. """Bounded native BackUp check on archived observations, without an actuator.
Captured geometry receives an explicit synthetic ground restriction beneath Fixtures use an explicit synthetic ground restriction or archived detector
future body overhang, with stationary odometry/fresh times. This verifies returns. Recorded pose history restores prior footprint clearing, then odometry
native collision plumbing, never route or physical acceptance. is held stationary with fresh times. This checks collision plumbing without
an actuator; it is not route or physical acceptance.
""" """
import argparse import argparse
import json import json
@@ -19,6 +20,9 @@ from action_msgs.msg import GoalStatus
from configuration import observed_configuration from configuration import observed_configuration
from observed_collision import ObservedCollision from observed_collision import ObservedCollision
from ros_navigation import RosNavigation, yaw_of 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(): def main():
@@ -26,19 +30,31 @@ def main():
for name in ('inputs', 'robot', 'snapshot', 'output'): for name in ('inputs', 'robot', 'snapshot', 'output'):
parser.add_argument('--'+name, type=Path, required=True) parser.add_argument('--'+name, type=Path, required=True)
parser.add_argument('--mixed', action='store_true') parser.add_argument('--mixed', action='store_true')
parser.add_argument('--detector', action='store_true')
args = parser.parse_args() args = parser.parse_args()
args.output.mkdir(exist_ok=False, parents=True) args.output.mkdir(exist_ok=False, parents=True)
inputs = json.loads(args.inputs.read_text()) inputs = json.loads(args.inputs.read_text())
snapshot = json.loads(args.snapshot.read_text()) snapshot = json.loads(args.snapshot.read_text())
request = snapshot['latest_plan']['request'] request = snapshot['latest_plan']['request']
assert request['execution_inputs_sha256'] == inputs['sha256'] 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. request['geometry_age_seconds'] = 0.
physical = np.array(snapshot['geometry']) physical = np.array(snapshot['geometry'])
search = np.array(snapshot['search_terrain']) search = np.array(snapshot['search_terrain'])
pose = np.asarray(request['pose']); yaw = yaw_of(pose) pose = np.asarray(request['pose']); yaw = yaw_of(pose)
axes = np.array([[math.cos(yaw), -math.sin(yaw)], [math.sin(yaw), math.cos(yaw)]]) axes = np.array([[math.cos(yaw), -math.sin(yaw)], [math.sin(yaw), math.cos(yaw)]])
local = (search[:, :2]-pose[:2]) @ axes local = (search[:, :2]-pose[:2]) @ axes
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 # A ground restriction 83 cm behind the origin intersects the mounted
# body's predicted reverse sweep, but not the shorter track sweep. # body's predicted reverse sweep, but not the shorter track sweep.
selected = int(np.argmin(np.linalg.norm(local-[-.83, 0.], axis=1))) selected = int(np.argmin(np.linalg.norm(local-[-.83, 0.], axis=1)))
@@ -54,25 +70,33 @@ def main():
collision = ObservedCollision(node, inputs['robot']['geometry']['max_step_m'], 2) collision = ObservedCollision(node, inputs['robot']['geometry']['max_step_m'], 2)
running = threading.Event(); running.set() running = threading.Event(); running.set()
lock = threading.Lock() 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 = [], [], [], [] errors, commands, processes, logs = [], [], [], []
spinner = threading.Thread(target=rclpy.spin, args=(node,)) spinner = threading.Thread(target=rclpy.spin, args=(node,))
def publish(): def publish():
try: try:
while running.is_set(): while running.is_set():
node.observe_pose(request['pose'], .01, [0., 0., 0.])
with lock: with lock:
terrain = state['physical'] terrain, current_pose = state['physical'], state['pose']
assert collision.publish(request, terrain, 0., search_terrain=search) 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()) commands.append(node.native_command())
time.sleep(.08) time.sleep(.08)
except BaseException as error: except BaseException as error:
errors.append(str(error)) errors.append(str(error))
source = threading.Thread(target=publish) source = threading.Thread(target=publish)
report = dict(passed=False, mixed=args.mixed, authority=None, report = dict(passed=False, mixed=args.mixed, detector=args.detector,
scope='Native collision-domain regression; synthetic ground hint on archived range, stationary odometry, no actuator', 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) synthetic_ground_hint=synthetic_ground_hint)
try: try:
spinner.start(); source.start() spinner.start(); source.start()
@@ -86,6 +110,14 @@ def main():
('behavior' if package == 'nav2_behaviors' else 'controller')+'_cmd_vel'], ('behavior' if package == 'nav2_behaviors' else 'controller')+'_cmd_vel'],
stdout=log, stderr=subprocess.STDOUT)) stdout=log, stderr=subprocess.STDOUT))
node.activate() 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) time.sleep(.8)
node.backup(.8, .1, 0.) node.backup(.8, .1, 0.)
started = time.monotonic() started = time.monotonic()
@@ -94,6 +126,7 @@ def main():
report['held_seconds'] = time.monotonic()-started report['held_seconds'] = time.monotonic()-started
report['terminal_status'] = node.terminal.result().status if node.terminal.done() else None 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) 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: if args.mixed:
assert report['terminal_status'] == GoalStatus.STATUS_ABORTED, report assert report['terminal_status'] == GoalStatus.STATUS_ABORTED, report
else: else:
@@ -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 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 radius sqrt(2)*d disk. This covers the command guard's 35 cm reserve at every
@@ -61,6 +61,13 @@ class ObservedCollision:
hazards = terrain[terrain[:,3]>self.max_step+1e-4,:2] hazards = terrain[terrain[:,3]>self.max_step+1e-4,:2]
search = search_terrain[search_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']) 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)))) self.search.publish(cloud(stamp,'map',np.concatenate((search,reserve))))
return True return True