From 3735f21fc202638c51e9787ad1ba9283e4209308 Mon Sep 17 00:00:00 2001 From: DCCONSTRUCTIONS Date: Sat, 10 Oct 2026 05:02:18 +0300 Subject: [PATCH] Prevent accumulated range sampling drift in observed passages --- .../ai-polygon/navigation/observed_goals.py | 17 ++++++++++- tests/test_ai_polygon_observed_goals.py | 30 +++++++++++++++++++ 2 files changed, 46 insertions(+), 1 deletion(-) diff --git a/simulation/ai-polygon/navigation/observed_goals.py b/simulation/ai-polygon/navigation/observed_goals.py index 6abbde4a..003190e5 100644 --- a/simulation/ai-polygon/navigation/observed_goals.py +++ b/simulation/ai-polygon/navigation/observed_goals.py @@ -28,6 +28,7 @@ class ObservedGoals: self.evidence = None self.clearance_observation = None self.clearance_index = None + self.continuation_anchor = None def observe(self, samples, captured_at, pose, *, frame_id=None, capture_id=None): if frame_id is not None and frame_id in self.seen_semantics: @@ -407,7 +408,17 @@ class ObservedGoals: advance = min(3., remaining)-along if (along > 0 and advance >= float(self.surface.cell_size[0]) and all(math.dist(before[:2], failed[:2]) > 0.6 for failed in excluded)): - query = before[:2]+advance*continuation + # A range sample is a noisy representative of the chosen + # passage, not the origin of its next lateral coordinate. + # Reusing each snapped point accumulates sampling error + # into metres of drift along an otherwise straight aisle. + anchor = before[:2] + saved = self.continuation_anchor + if (saved is not None and np.array_equal(saved[2], before) + and np.allclose(saved[1], continuation, rtol=0, atol=1e-9)): + anchor = saved[0] + query = anchor + (float((pose[:2]-anchor) @ continuation) + + min(3., remaining))*continuation nearby = np.linalg.norm(candidates[:, :2]-query, axis=1) for index in np.argsort(nearby, kind="stable"): if nearby[index] > .15: @@ -420,6 +431,7 @@ class ObservedGoals: continue self.evidence['approach_clearance_m'] = ( float(clearance) if math.isfinite(clearance) else None) + self.continuation_anchor = (anchor.copy(), continuation.copy(), selected.copy()) return selected.tolist() if (0.8 < math.dist(before[:2], pose[:2]) <= 3.5 and math.dist(before[:2], target) < remaining - 0.1 @@ -442,6 +454,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))) + # A blocked/replaced passage releases its old lateral reference. This + # memory never overrides current measured support or obstacle checks. + self.continuation_anchor = None # 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): diff --git a/tests/test_ai_polygon_observed_goals.py b/tests/test_ai_polygon_observed_goals.py index 449b5853..4d641842 100644 --- a/tests/test_ai_polygon_observed_goals.py +++ b/tests/test_ai_polygon_observed_goals.py @@ -654,3 +654,33 @@ def test_through_passage_requires_measured_permission_and_current_clearance(sele moved=[2.7,0.,.37,0.,0.,0.,1.] end=selector.choose(points,moved,[8.,0.],chosen,(),GEOMETRY,1.3,travel_direction=[1.,0.]) assert end is None or end[0]<=points[:,0].max() + + +@pytest.mark.parametrize('angle,side,shift', [(0,1,(0,0)), (73,-1,(42,-17)), (-138,1,(-250,52))]) +def test_range_sampling_error_does_not_accumulate_into_lateral_drift(selector, angle, side, shift): + _, pose, _, _, rotation = road(angle, shift) + # Diagonally phased scan rows: successive nearest samples are offset by + # 11 mm. Recursively extending each snapped point drifts >1 m in 19 m. + xy = np.array([[x, side*(y+.055*x)] for x in np.arange(-1.,25.01,.2) + for y in np.arange(-4.,4.01,.13)]) + points = np.c_[xy@rotation.T+shift, np.zeros(len(xy))] + geometry = {**GEOMETRY, 'length_m':1.36, 'max_step_m':.1} + selector.observe(np.c_[points, np.ones(len(points))], 1., pose) + goal = [*(np.asarray(shift)+rotation@[3.,0.]),0.] + lateral = [] + for along in np.arange(1.,20.01,.2): + position = np.asarray(shift)+rotation@[along,0.] + moved = [*position, *pose[2:]] + goal = selector.choose(points, moved, position+rotation@[6.,0.], goal, + (), geometry, 2., travel_direction=rotation@[1.,0.]) + assert goal is not None + assert selector.evidence['source'] in {'continuing-observed-passage', 'retained-observed-passage'} + assert np.min(np.linalg.norm(points-goal,axis=1)) < 1e-9 + lateral.append(((np.asarray(goal[:2])-shift)@rotation)[1]) + assert max(np.abs(lateral)) < .13 + # A new measured obstacle revokes the axis before a physical encounter. + obstacle = position+rotation@[1.5,0.] + selector.observe_navigation(clearance_receipt(moved,[obstacle]),moved,1,'run',2.) + replacement = selector.choose(points, moved, position+rotation@[6.,0.],goal, + (), geometry,2.1,travel_direction=rotation@[1.,0.]) + assert replacement is None or abs(((np.asarray(replacement[:2])-shift)@rotation)[1])>.3