From 3657998f9d6cda199a33e4b3af19122670a26f21 Mon Sep 17 00:00:00 2001 From: DCCONSTRUCTIONS Date: Sat, 10 Oct 2026 05:38:35 +0300 Subject: [PATCH] Measure advisory route progress beyond approximate joints --- .../simulation/ai_polygon/route_mission.py | 14 ++++++++ tests/test_prepared_urban_route.py | 34 +++++++++++++++++++ 2 files changed, 48 insertions(+) diff --git a/src/k1link/simulation/ai_polygon/route_mission.py b/src/k1link/simulation/ai_polygon/route_mission.py index 30f2c757..67e0b87c 100644 --- a/src/k1link/simulation/ai_polygon/route_mission.py +++ b/src/k1link/simulation/ai_polygon/route_mission.py @@ -204,6 +204,20 @@ class RoutedMission(WaypointMission): self.route_target = (np.asarray(pose[:2]) + 6.*direction).tolist() def distance_to_target(self, pose, target): + if self.advisory_joint(): + # A map joint is not a local stopping point. Clamping its along + # coordinate makes genuine travel beyond an offset joint look like + # retreat, provoking recovery while the observed passage is open. + # Measure watchdog progress on the same continuing axis as intent. + # Best-distance tracking still rejects back/forth cycles; this + # neither advances a route joint nor admits terrain or arrival. + segment = self.leg["segments"][self.segment_index] + axis = np.asarray(segment["end_xy"]) - segment["start_xy"] + axis /= np.linalg.norm(axis) + delta = np.asarray(pose[:2]) - segment["start_xy"] + along = float(delta @ axis) + lateral = abs(float(delta[0]*axis[1] - delta[1]*axis[0])) + return self.leg["length_m"] - self.completed_length - along + .15*lateral return self.remaining def orientation_target(self): diff --git a/tests/test_prepared_urban_route.py b/tests/test_prepared_urban_route.py index 69624abc..731d3264 100644 --- a/tests/test_prepared_urban_route.py +++ b/tests/test_prepared_urban_route.py @@ -350,3 +350,37 @@ def test_advisory_joint_is_a_direction_not_lateral_attraction(offset): mission.segment_index=len(mission.leg['segments'])-1 mission.route_observation(pose,61.) assert mission.route_target == mission.leg['goal_xy'] + + +@pytest.mark.parametrize("angle,offset", [(0., 3.), (.7, -3.), (-1.2, 3.)]) +def test_progress_past_advisory_joint_uses_observed_continuation(angle, offset): + from k1link.simulation.ai_polygon.route_mission import RoutedMission + *_, inputs, _ = fixture() + axes = np.array([[math.cos(angle), -math.sin(angle)], + [math.sin(angle), math.cos(angle)]]) + for node in inputs['routing']['map']['nodes']: + node['xy'] = (axes @ node['xy']).tolist() + graph = inputs['routing']['map'] + graph['sha256'] = digest({k: v for k, v in graph.items() if k != 'sha256'}) + inputs['mission']['route_xy'] = [(axes @ [12., 0.]).tolist()] + inputs['routing']['blocked_edges'] = ['0', '1', '2'] + inputs.update(sensors={'schema_version': 'missioncore.simulation-sensor-rig/v4'}, + behavior={'max_speed_mps': 1.}) + mission = RoutedMission(inputs) + def step(x, y, seconds): + xy = axes @ [x, y] + yaw = angle + math.pi/2 + pose = [*xy, 0., 0., 0., math.sin(yaw/2), math.cos(yaw/2)] + # Measured local goals continue along the actual passage beside the + # approximate joint. Changing a goal alone must earn no progress. + return mission.update(pose, seconds, lambda *_: [*(axes @ [x, y+3]), 0.]) + step(0., 0., 0.) + for i, y in enumerate(np.arange(3., 15.5, .5)): + step(offset, y, 5.+i*2) + assert mission.attempts == 0 and mission.fault is None + assert mission.segment_index == 0 and mission.index == 0 + # This is watchdog progress only; no route joint or arrival is admitted. + # Back/forth motion and refreshed goals cannot replenish the watchdog. + for i in range(6): + step(offset, 14.8 if i % 2 == 0 else 15., 55.+i*2) + assert mission.attempts >= 1