Advance passed advisory route joints from observed body progress
This commit is contained in:
@@ -1,6 +1,4 @@
|
||||
"""Current observed body support for an intent transition, never a drive goal."""
|
||||
import math
|
||||
|
||||
import numpy as np
|
||||
|
||||
|
||||
@@ -11,9 +9,11 @@ def route_support(monitor, observed, value, inputs):
|
||||
pose = np.asarray(value["pose"], dtype=float)
|
||||
target = np.asarray(target, dtype=float)
|
||||
if (target.shape != (2,) or not np.isfinite(target).all()
|
||||
or math.dist(pose[:2], target) > 3.5
|
||||
or value["execution_inputs_sha256"] != inputs["sha256"]):
|
||||
raise ValueError("Invalid route transition observation")
|
||||
# The target binds the receipt to an itinerary joint; no terrain near that
|
||||
# target is queried or admitted. Assess only the actual observed body here.
|
||||
# Ordered longitudinal progress belongs to RoutedMission, not this sensor.
|
||||
support = observed["permitted_terrain"]
|
||||
receipt = monitor.assess_pose(observed["terrain"], pose,
|
||||
value["body_contact_height_m"], support_terrain=support)
|
||||
|
||||
@@ -708,9 +708,9 @@ class ComposedInference:
|
||||
and self.mission.can_query_arrival(pose)
|
||||
and np.linalg.norm(np.asarray(pose[:2]) - arrival_target) <= 3.5
|
||||
)
|
||||
route_transition_nearby = bool(not recovering and arrival_target is not None
|
||||
route_transition_query = bool(not recovering and arrival_target is not None
|
||||
and isinstance(self.mission, RoutedMission)
|
||||
and math.dist(pose[:2], arrival_target) <= 3.5)
|
||||
and self.mission.can_query_route_transition(pose))
|
||||
terminal_region = bool(
|
||||
nearby
|
||||
and math.dist(pose[:2], arrival_target)
|
||||
@@ -844,7 +844,7 @@ class ComposedInference:
|
||||
if arrival_candidate or body_goal_query
|
||||
else None,
|
||||
"route_transition_target": arrival_target
|
||||
if route_transition_nearby else None,
|
||||
if route_transition_query else None,
|
||||
"max_speed_mps": min(self.max_speed, 0.1)
|
||||
if intent["state"] == "reversing" or intent.get("corner_approach")
|
||||
else min(self.max_speed, inputs.get("source.crossing-admission", {}).get("speed_limit_mps") or self.max_speed),
|
||||
|
||||
@@ -361,6 +361,25 @@ class RoutedMission(WaypointMission):
|
||||
# may advance that cursor while free-space navigation owns the path.
|
||||
return not self.route_failure and self.remaining is not None and not self.advisory_joint()
|
||||
|
||||
def can_query_route_transition(self, pose):
|
||||
"""Ask about the current body, never require visiting a passed map hint.
|
||||
|
||||
Near a joint we retain the existing approach window. Once longitudinal
|
||||
progress passes an advisory joint, lateral displacement from that hint
|
||||
cannot pin the itinerary to the old edge. Only one adjacent transition
|
||||
may then be confirmed by a fresh positive whole-body observation.
|
||||
"""
|
||||
if not self.advisory_joint():
|
||||
return math.dist(pose[:2], self.arrival_target()) <= 3.5
|
||||
segment = self.leg["segments"][self.segment_index]
|
||||
axis = np.asarray(segment["end_xy"]) - segment["start_xy"]
|
||||
remaining = float(
|
||||
(np.asarray(segment["end_xy"]) - pose[:2]) @ axis / np.linalg.norm(axis)
|
||||
)
|
||||
return remaining <= 0 or (
|
||||
remaining <= 1.5 and math.dist(pose[:2], segment["end_xy"]) <= 3.5
|
||||
)
|
||||
|
||||
def arrival_target(self):
|
||||
segments = self.leg["segments"]
|
||||
return segments[self.segment_index]["end_xy"] if segments else self.leg["goal_xy"]
|
||||
@@ -423,7 +442,7 @@ class RoutedMission(WaypointMission):
|
||||
def confirm_corridor_transition(self, pose, seconds, body):
|
||||
"""Join adjacent corridors without treating a graph vertex as a task goal.
|
||||
|
||||
A current positive whole-body assessment and containment in BOTH
|
||||
A current positive whole-body assessment and permission in BOTH
|
||||
corridors are required. This changes intent only; the adapter fences
|
||||
the old command, and every subsequent turn still needs swept admission.
|
||||
Explicit mission goals and return-to-anchor obligations retain arrival.
|
||||
@@ -465,15 +484,8 @@ class RoutedMission(WaypointMission):
|
||||
):
|
||||
return None
|
||||
adjacent = segments[self.segment_index : self.segment_index + 2]
|
||||
if adjacent[0].get("guidance_only"):
|
||||
along, _ = projection(pose[:2], adjacent[0]["start_xy"], adjacent[0]["end_xy"])
|
||||
length = math.dist(adjacent[0]["start_xy"], adjacent[0]["end_xy"])
|
||||
# Use the same local observation radius as the native support
|
||||
# query. An advisory line's width is not a travel boundary: a
|
||||
# positively observed detour may join the next segment off-centre.
|
||||
# Progress and proximity still prevent remote/skipped joints.
|
||||
if length - along > 1.5 or math.dist(pose[:2], adjacent[0]["end_xy"]) > 3.5:
|
||||
return None
|
||||
if not self.can_query_route_transition(pose):
|
||||
return None
|
||||
directions = [np.asarray(s["end_xy"]) - s["start_xy"] for s in adjacent]
|
||||
# A reversal is a visit and return, not a corner that can be cut.
|
||||
if np.dot(*directions) <= -0.95 * np.linalg.norm(directions[0]) * np.linalg.norm(
|
||||
|
||||
@@ -80,9 +80,22 @@ def test_support_is_current_and_positive_but_does_not_grant_a_path_or_arrival(br
|
||||
assert 'route_support' not in navigation.plan(unrelated)
|
||||
|
||||
|
||||
def test_route_support_rejects_remote_or_wrongly_bound_target(bridge):
|
||||
def test_remote_hint_assesses_current_body_without_granting_remote_terrain(bridge):
|
||||
navigation, _, value = bridge
|
||||
for change in ({'route_transition_target': [4., 0.]}, {'execution_inputs_sha256': 'b'*64}):
|
||||
value['route_transition_target'] = [14., -8.]
|
||||
result = navigation.plan(value)
|
||||
receipt = result['route_support']
|
||||
assert receipt['admitted'] is True
|
||||
assert receipt['observation']['pose'] == value['pose']
|
||||
assert receipt['observation']['target_xy'] == [14., -8.]
|
||||
assert result['status'] == 'blocked' and 'arrival' not in result
|
||||
assert result['speed_mps'] == result['yaw_rate_rps'] == 0.
|
||||
|
||||
|
||||
def test_route_support_rejects_invalid_or_wrongly_bound_target(bridge):
|
||||
navigation, _, value = bridge
|
||||
for change in ({'route_transition_target': [float('nan'), 0.]},
|
||||
{'route_transition_target': [4.]}, {'execution_inputs_sha256': 'b'*64}):
|
||||
with pytest.raises(ValueError, match='transition observation'):
|
||||
navigation.plan({**value, **change})
|
||||
|
||||
|
||||
@@ -226,6 +226,61 @@ def test_observed_detour_can_pass_advisory_joint_without_returning_to_line(condi
|
||||
assert mission.confirm_corridor_transition(pose, 10., body) is None
|
||||
|
||||
|
||||
@pytest.mark.parametrize('angle', [0., .9, -2.1])
|
||||
@pytest.mark.parametrize('offset', [-8., 8.])
|
||||
@pytest.mark.parametrize('condition', ['passed', 'early', 'unknown', 'stale',
|
||||
'forbidden', 'return', 'reverse', 'recovering'])
|
||||
def test_passed_advisory_joint_uses_progress_and_current_body_not_lateral_distance(
|
||||
angle, offset, condition):
|
||||
from k1link.simulation.ai_polygon.route_mission import RoutedMission
|
||||
*_, inputs, _ = fixture()
|
||||
inputs['routing']['blocked_edges'] = ['0', '1', '2']
|
||||
rotation = np.array([[math.cos(angle), -math.sin(angle)],
|
||||
[math.sin(angle), math.cos(angle)]])
|
||||
origin = np.array([37., -23.])
|
||||
def world(xy):
|
||||
return (rotation @ xy + origin).tolist()
|
||||
for node in inputs['routing']['map']['nodes']:
|
||||
node['xy'] = world(node['xy'])
|
||||
graph = inputs['routing']['map']
|
||||
graph['sha256'] = digest({k: v for k, v in graph.items() if k != 'sha256'})
|
||||
inputs.update(sensors={'schema_version': 'missioncore.simulation-sensor-rig/v4'},
|
||||
behavior={'max_speed_mps': 1.})
|
||||
inputs['mission']['route_xy'] = [world([12., 0.])]
|
||||
mission = RoutedMission(inputs)
|
||||
mission.route_observation([*world([0., 0.]), 0., 0., 0., 0., 1.], 0.)
|
||||
pose = [*world([offset, 4.5 if condition == 'early' else 5.5]), 0., 0., 0., 0., 1.]
|
||||
mission.route_observation(pose, 10.)
|
||||
mission.last_time, mission.last_pose = 10., tuple(pose)
|
||||
body = dict(observation=dict(pose=pose, target_xy=mission.arrival_target(),
|
||||
simulation_time_seconds=10., execution_inputs_sha256=inputs['sha256']),
|
||||
admitted=True, collision_free=True, support_known=True,
|
||||
positive_surface_required=True, support_samples=4, supported_samples=4)
|
||||
if condition == 'unknown':
|
||||
body.update(admitted=False, support_known=False, supported_samples=0)
|
||||
if condition == 'stale':
|
||||
body['observation']['simulation_time_seconds'] = 9.
|
||||
if condition == 'forbidden':
|
||||
mission.global_route['no_go'] = [dict(lower_xy=(np.array(pose[:2])-.2).tolist(),
|
||||
upper_xy=(np.array(pose[:2])+.2).tolist())]
|
||||
if condition == 'return':
|
||||
mission.leg['segments'][0]['return_to_anchor'] = True
|
||||
if condition == 'reverse':
|
||||
mission.leg['segments'][1]['end_xy'] = world([0., 0.])
|
||||
if condition == 'recovering':
|
||||
mission.recovery_goal = [*world([offset, 4.]), 0.]
|
||||
assert not mission.can_query_arrival(pose) or condition == 'return'
|
||||
result = mission.confirm_corridor_transition(pose, 10., body)
|
||||
assert (result is not None) is (condition == 'passed')
|
||||
assert mission.segment_index == (1 if condition == 'passed' else 0)
|
||||
assert mission.index == 0
|
||||
if result:
|
||||
assert mission.confirm_corridor_transition(pose, 10., body) is None
|
||||
# The new intent runs along the next edge from the actual position;
|
||||
# it neither turns back to the old hint nor completes the task goal.
|
||||
np.testing.assert_allclose(np.array(mission.route_target)-pose[:2], rotation @ [6., 0.])
|
||||
|
||||
|
||||
@pytest.mark.parametrize('direction', ['forward', 'reverse', 'at-node'])
|
||||
def test_local_blockage_keeps_original_graph_edge_and_nearby_return_node(direction):
|
||||
from k1link.simulation.ai_polygon.route_feedback import blocked_route_piece
|
||||
|
||||
Reference in New Issue
Block a user