From e3d116d5b066e0d03461888ac970ec43340a359b Mon Sep 17 00:00:00 2001 From: DCCONSTRUCTIONS Date: Sat, 10 Oct 2026 02:12:18 +0300 Subject: [PATCH] Select urban passage intent from measured world geometry --- .../ai-polygon/navigation/observed_goals.py | 51 ++++++++-------- .../navigation/observed_passages.py | 15 ++++- simulation/ai-polygon/navigation_client.py | 7 ++- tests/test_ai_polygon_observed_goals.py | 58 ++++++++++++++++++- 4 files changed, 98 insertions(+), 33 deletions(-) diff --git a/simulation/ai-polygon/navigation/observed_goals.py b/simulation/ai-polygon/navigation/observed_goals.py index 2fcf600e..4b9f8a41 100644 --- a/simulation/ai-polygon/navigation/observed_goals.py +++ b/simulation/ai-polygon/navigation/observed_goals.py @@ -1,4 +1,4 @@ -"""Local intent from current range and causal multi-view surface observations. +"""Local intent from a causal, measured world-space surface. Changing the camera sector must not move a still observed goal to that sector's image centre. This selects measured points, never a route or permission to move; @@ -304,7 +304,7 @@ class ObservedGoals: return dict(goal=candidates[i].tolist(), reverse=False, kind="orient") return inspect_heading() - def choose(self, points, pose, target, prior, excluded, geometry, now, candidate_mask=None): + def choose(self, points, pose, target, prior, excluded, geometry, now, candidate_mask=None, *, travel_direction=None): self.evidence = None if target is None: return None @@ -317,6 +317,21 @@ class ObservedGoals: remaining = float(np.linalg.norm(direction)) if remaining <= 0.4: return None # Exact arrival remains the native whole-body receipt. + allowed = { + key: stamp for key, (permission, stamp) in self.surface.cells.items() + if permission == 1 and self.surface.retained(key, stamp, now) + } + # A current observation must still see some known permitted surface. + # A wholly missing/other-height scene cannot be replaced by old memory. + if not any(tuple(key) in allowed for key in self.surface.cell_keys(points)): + return None + remembered = np.array([point for key, point in self.measured.items() + if key in allowed], dtype=float).reshape(-1, 3) + # Goal selection consumes the observed world, not just the current + # body-facing range crop. Both new and retained intentions may refer to + # actual earlier returns; no timestamp or physical support is created. + # Native planning and live swept-body admission still use current range. + points = np.concatenate((points, remembered)) delta = points[:, :2] - pose[:2] distance = np.linalg.norm(delta, axis=1) progress = np.linalg.norm(points[:, :2] - target, axis=1) @@ -331,10 +346,6 @@ class ObservedGoals: good &= np.linalg.norm(points[:, :2] - np.asarray(failed[:2]), axis=1) > 0.6 if not np.any(good): return None - allowed = { - key: stamp for key, (permission, stamp) in self.surface.cells.items() - if permission == 1 and self.surface.retained(key, stamp, now) - } permitted = points[[tuple(key) in allowed for key in self.surface.cell_keys(points)]] local = np.linalg.norm(permitted[:, :2]-pose[:2], axis=1) permitted = permitted[(local <= 6.) & (np.abs(permitted[:, 2] - @@ -349,7 +360,7 @@ class ObservedGoals: offsets = np.linspace(-geometry["width_m"] / 2, geometry["width_m"] / 2, math.ceil(geometry["width_m"] / 0.1) + 1) - def supported(point, support=permitted, *, source="current-range-and-observed-semantic-memory"): + def supported(point, support=permitted, *, source="measured-surface-memory"): bearing = point[:2]-pose[:2] bearing /= max(np.linalg.norm(bearing), 1e-9) lateral = np.array([-bearing[1], bearing[0]]) @@ -370,20 +381,9 @@ class ObservedGoals: } return True - # A selected passage is a spatial intention, not a fresh sensor return. - # Retain its actually observed surface through a changing range crop. - # Current geometry still owns every native obstacle/support admission; - # this memory never enters that physical terrain or renews a timestamp. - remembered = np.array([point for key, point in self.measured.items() - if key in allowed], dtype=float).reshape(-1, 3) - if len(remembered): - local = np.linalg.norm(remembered[:, :2]-pose[:2], axis=1) - remembered = remembered[(local <= 6.) & (np.abs(remembered[:, 2] - - (pose[2]-geometry['body_contact_height_m'])) <= geometry.get('max_step_m', .1) - + local*math.tan(math.radians(geometry['max_slope_degrees'])))] - if candidate_mask is not None: - remembered = remembered[candidate_mask(remembered)] - passage_points = np.concatenate((permitted, remembered)) + # Positive measured extent has already been bounded by local distance, + # height, permission lifetime and the mission's permitted region. + passage_points = permitted retain = None if prior is not None: before = np.asarray(prior, dtype=float) @@ -410,9 +410,9 @@ class ObservedGoals: observed = self.clearance_observation obstacles = (observed[1] if observed is not None and 0 <= now-observed[0] <= .8 else np.empty((0, 2))) - # Retained measured extent supplies the passage boundaries. New goals - # still require current range support, independently of prior retention. - for passages in passage_centres(passage_points, pose, target, geometry, obstacles): + # New and retained goals share one measured world-space representation. + for passages in passage_centres(passage_points, pose, target, geometry, obstacles, + travel_direction=travel_direction): for passage in passages: distance = np.linalg.norm(candidates[:, :2]-passage['xy'], axis=1) for index in np.argsort(distance, kind="stable"): @@ -425,7 +425,8 @@ class ObservedGoals: self.evidence.update(source="observed-passage-centre", passage_width_m=float(passage['width']), passage_centre_xy=passage['xy'].tolist(), - route_role="rank-distinct-passages-only", + route_role=("continuation-direction-and-branch-selection" if travel_direction is not None + else "rank-distinct-passages-only"), approach_clearance_m=float(clearance) if math.isfinite(clearance) else None) return selected.tolist() return None diff --git a/simulation/ai-polygon/navigation/observed_passages.py b/simulation/ai-polygon/navigation/observed_passages.py index 694c42ce..dd1cd070 100644 --- a/simulation/ai-polygon/navigation/observed_passages.py +++ b/simulation/ai-polygon/navigation/observed_passages.py @@ -10,10 +10,19 @@ import numpy as np from scipy.spatial import cKDTree -def passage_centres(points, pose, target, geometry, obstacles): +def passage_centres(points, pose, target, geometry, obstacles, *, travel_direction=None): position = np.asarray(pose[:2]) - x, y, z, w = pose[3:7] - yaw = math.atan2(2*(w*z+x*y), 1-2*(y*y+z*z)) + # An explicitly selected route continuation stations the observed corridor. + # It is a direction, never the vector toward a remote endpoint. Legacy + # unrouted tasks retain their body-forward observation convention. + if travel_direction is None: + x, y, z, w = pose[3:7] + yaw = math.atan2(2*(w*z+x*y), 1-2*(y*y+z*z)) + else: + direction = np.asarray(travel_direction, dtype=float) + if direction.shape != (2,) or not np.isfinite(direction).all() or np.linalg.norm(direction) <= 1e-9: + raise ValueError("Invalid passage travel direction") + yaw = math.atan2(direction[1], direction[0]) axes = np.array([[math.cos(yaw), -math.sin(yaw)], [math.sin(yaw), math.cos(yaw)]]) local = (points[:, :2]-position) @ axes diff --git a/simulation/ai-polygon/navigation_client.py b/simulation/ai-polygon/navigation_client.py index f6b91c09..6e02dea1 100644 --- a/simulation/ai-polygon/navigation_client.py +++ b/simulation/ai-polygon/navigation_client.py @@ -589,14 +589,15 @@ class ComposedInference: calibration = inputs["source.camera.calibration"] if observed_goals is not None: # Every lens contributes to the same causal surface memory. - # New destinations need current range; an observed passage can - # retain its intent across a changing crop without renewing its - # evidence. Native live body/support admission remains separate. + # Intent uses actually measured world-space surface across + # changing body views. Native live body/support admission stays + # separate and never receives synthetic range from this memory. return observed_goals.choose( inputs["source.lidar"], inputs["source.pose"], target, None if prior_was_approach else prior, excluded, self.geometry, time.monotonic(), self.mission.goals_permitted if isinstance(self.mission, RoutedMission) else None, + travel_direction=(self.mission.orientation_target() or {}).get("direction_xy"), ) if calibration.get("view_role") == "survey": observed = self.task_view_intent.recall(target, time.monotonic()) diff --git a/tests/test_ai_polygon_observed_goals.py b/tests/test_ai_polygon_observed_goals.py index 6f22d822..c016ff07 100644 --- a/tests/test_ai_polygon_observed_goals.py +++ b/tests/test_ai_polygon_observed_goals.py @@ -545,9 +545,63 @@ def test_selected_passage_survives_range_crop_without_creating_new_sensor_suppor assert selector.evidence['oldest_surface_age_seconds']==1. assert dict(selector.surface.cells)==stamps np.testing.assert_array_equal(crop,saved) - # A first destination cannot be manufactured from a narrow current crop. - assert selector.choose(crop,turned,target,None,(),GEOMETRY,2.) is None + # A new intention uses the same observed passage, even after the previous + # goal is reached. This is old measured evidence, not new sensor support. + replacement=selector.choose(crop,turned,target,None,(),GEOMETRY,2., + travel_direction=rotation@[1.,0.]) + assert replacement is not None + assert abs(((np.array(replacement[:2])-shift)@rotation)[1]) < .13 + assert dict(selector.surface.cells)==stamps + np.testing.assert_array_equal(crop,saved) + # Without the earlier full-width observation, the same narrow crop cannot + # invent a traversable destination. + unseen=type(selector)() + unseen.observe(np.c_[crop,np.ones(len(crop))],1.,turned) + assert unseen.choose(crop,turned,target,None,(),GEOMETRY,2.) is None # Current obstacle geometry can still revoke that retained intent. obstacle=(np.asarray(shift)+rotation@[1.6,0.]).tolist() selector.observe_navigation(clearance_receipt(turned,[obstacle]),turned,1,'run',2.) assert selector.choose(crop,turned,target,goal,(),GEOMETRY,2.1)!=goal + + +@pytest.mark.parametrize('angle,shift', [(0,(0,0)),(73,(42,-17)),(-138,(-250,52))]) +def test_local_intent_geometry_does_not_rotate_with_chassis(selector,angle,shift): + _,pose,target,_,rotation=road(angle,shift) + xy=np.array([[x,y] for x in np.arange(-4.,6.01,.08) + for y in np.arange(-1.6,1.61,.08)]) + points=np.c_[xy@rotation.T+shift,np.zeros(len(xy))] + geometry={**GEOMETRY,'length_m':1.3636,'max_step_m':.1} + selector.observe(np.c_[points,np.ones(len(points))],1.,pose) + reference=selector.choose(points,pose,target,None,(),geometry,2., + travel_direction=rotation@[1.,0.]) + assert reference is not None + for offset in [-45,-30,-15,15,30,45]: + heading=math.radians(angle+offset) + turned=[*pose[:3],0,0,math.sin(heading/2),math.cos(heading/2)] + chosen=selector.choose(points,turned,target,None,(),geometry,2., + travel_direction=rotation@[1.,0.]) + np.testing.assert_allclose(chosen,reference,atol=1e-8) + + +def test_memory_goal_selection_does_not_refresh_expired_or_revoked_evidence(selector): + points,pose,target,_,_=road() + selector.observe(np.c_[points,np.ones(len(points))],1.,pose) + crop=points[points[:,1]>.7] + assert selector.choose(crop,pose,target,None,(),GEOMETRY,2.) is not None + original=dict(selector.surface.cells) + # Move the memory's retention centre away, making these old samples expire. + selector.surface.position=np.array([100.,100.]) + assert selector.choose(crop,pose,target,None,(),GEOMETRY,40.) is None + assert dict(selector.surface.cells)==original + selector.observe(np.c_[points,np.zeros(len(points))],41.,pose) + assert selector.choose(crop,pose,target,None,(),GEOMETRY,41.) is None + + +def test_explicit_route_direction_is_separate_from_remote_goal(selector): + points,pose,_,_,_=road() + selector.observe(np.c_[points,np.ones(len(points))],1.,pose) + goals=[selector.choose(points,pose,target,None,(),GEOMETRY,2., + travel_direction=[1.,0.]) + for target in ([8.,-5.],[8.,0.],[8.,5.],[675.,-9.])] + assert goals[0] is not None + assert all(np.array_equal(goal,goals[0]) for goal in goals)