Bind Nav2 route transitions to current observed body support
Return a separate positive-surface body receipt before reaching a guide vertex. Keep mission arrival and command admission independent, reject stale transaction reuse, and include the bridge helper in module identity. Validate the actual Nav2 plan entry with observed, unknown and obstructed support.
This commit is contained in:
@@ -102,7 +102,7 @@ def test_unknown_future_track_ground_does_not_select_an_incomplete_turn(motion):
|
||||
assert alignment_angle(pose(),[0.,2.,0.],hole,[],monitor,.37) is None
|
||||
|
||||
|
||||
@pytest.mark.parametrize('helper',['detector_exclusion.py','differential_motion.py'])
|
||||
@pytest.mark.parametrize('helper',['detector_exclusion.py','differential_motion.py','route_support.py'])
|
||||
def test_native_module_identity_includes_behavior_helpers(monkeypatch,helper):
|
||||
from k1link.simulation.ai_polygon.composition import registry
|
||||
|
||||
|
||||
@@ -0,0 +1,80 @@
|
||||
"""Real Nav2 plan entry returns bound current support without declaring arrival."""
|
||||
import ast
|
||||
import copy
|
||||
import math
|
||||
from pathlib import Path
|
||||
from types import SimpleNamespace
|
||||
import time
|
||||
|
||||
import numpy as np
|
||||
import pytest
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def bridge(monkeypatch):
|
||||
root = Path(__file__).parents[1] / 'simulation/ai-polygon'
|
||||
monkeypatch.syspath_prepend(str(root))
|
||||
monkeypatch.syspath_prepend(str(root / 'nav2'))
|
||||
from navigation.footprint import Footprint
|
||||
from navigation.route_observation import route_observation
|
||||
from route_support import route_support
|
||||
# Load the actual adapter class without unavailable ROS imports on the Mac.
|
||||
tree = ast.parse((root / 'nav2/server.py').read_text())
|
||||
cls = next(n for n in tree.body if isinstance(n, ast.ClassDef) and n.name == 'Navigation')
|
||||
scope = dict(np=np, math=math, time=time, route_support=route_support,
|
||||
route_observation=route_observation, validate_orientation=lambda _: None,
|
||||
alignment_angle=lambda *args: None)
|
||||
exec(compile(ast.Module(body=[cls], type_ignores=[]), str(root / 'nav2/server.py'), 'exec'), scope)
|
||||
navigation = scope['Navigation'].__new__(scope['Navigation'])
|
||||
navigation.failure = None
|
||||
navigation.active = navigation.activating = True
|
||||
navigation.action_key = navigation.attempted_alignment = None
|
||||
navigation.inputs = dict(sha256='a'*64, behavior={'max_speed_mps': 1.},
|
||||
mission={'arrival_radius_m': .4})
|
||||
navigation.monitor = Footprint(dict(length_m=1., width_m=.6, max_step_m=.1, max_slope_degrees=25.))
|
||||
navigation.node = SimpleNamespace(pose=(time.monotonic(), None, [0., 0., 0.]), stop=lambda: None)
|
||||
navigation.control = SimpleNamespace(observe=lambda _: None)
|
||||
navigation.collision = SimpleNamespace(publish=lambda *args, **kwargs: True)
|
||||
floor = np.array([[x, y, 0., 0.] for x in np.arange(-2, 2.01, .05)
|
||||
for y in np.arange(-2, 2.01, .05)])
|
||||
observed = dict(terrain=floor, permitted_terrain=floor, search_terrain=floor,
|
||||
detected=np.empty((0, 3)))
|
||||
navigation.terrain = SimpleNamespace(observe=lambda _: observed)
|
||||
value = dict(pose=[0., 0., .37, 0., 0., 0., 1.], goal=[1., 0., 0.],
|
||||
geometry_age_seconds=0., detection_age_seconds=0., max_speed_mps=1.,
|
||||
allow_reverse=False, translation_allowed=False, observation_id='sample-1',
|
||||
route_transition_target=[1., 0.], arrival_target=None,
|
||||
body_contact_height_m=.37, simulation_time_seconds=4.,
|
||||
execution_inputs_sha256='a'*64)
|
||||
return navigation, observed, value
|
||||
|
||||
|
||||
@pytest.mark.parametrize('condition', ['permitted', 'unknown', 'obstacle'])
|
||||
def test_support_is_current_and_positive_but_does_not_grant_a_path_or_arrival(bridge, condition):
|
||||
navigation, observed, value = bridge
|
||||
if condition == 'unknown':
|
||||
observed['permitted_terrain'] = np.empty((0, 4))
|
||||
if condition == 'obstacle':
|
||||
observed['terrain'] = np.vstack((observed['terrain'], [[.3, 0., .4, 1.]]))
|
||||
result = navigation.plan(value)
|
||||
receipt = result['route_support']
|
||||
assert receipt['admitted'] is (condition == 'permitted')
|
||||
assert receipt['positive_surface_required'] is True
|
||||
assert receipt['observation'] == dict(pose=value['pose'], target_xy=[1., 0.],
|
||||
simulation_time_seconds=4., execution_inputs_sha256='a'*64)
|
||||
assert result['status'] == 'blocked' and 'arrival' not in result
|
||||
assert result['speed_mps'] == result['yaw_rate_rps'] == 0.
|
||||
# A stale or unrelated next request must not inherit the previous receipt.
|
||||
stale = copy.deepcopy(value)
|
||||
stale['geometry_age_seconds'] = .9
|
||||
assert 'route_support' not in navigation.plan(stale)
|
||||
unrelated = copy.deepcopy(value)
|
||||
unrelated.pop('route_transition_target')
|
||||
assert 'route_support' not in navigation.plan(unrelated)
|
||||
|
||||
|
||||
def test_route_support_rejects_remote_or_wrongly_bound_target(bridge):
|
||||
navigation, _, value = bridge
|
||||
for change in ({'route_transition_target': [4., 0.]}, {'execution_inputs_sha256': 'b'*64}):
|
||||
with pytest.raises(ValueError, match='transition observation'):
|
||||
navigation.plan({**value, **change})
|
||||
Reference in New Issue
Block a user