From 1f1d4a2807853e8ce3810a848c2cb567158de537 Mon Sep 17 00:00:00 2001 From: DCCONSTRUCTIONS Date: Thu, 8 Oct 2026 15:14:14 +0300 Subject: [PATCH] perf(simulation): reuse support surface within an observation --- simulation/ai-polygon/nav2/terrain_observation.py | 7 ++++--- simulation/ai-polygon/navigation/support_obstacles.py | 10 ++++++---- simulation/ai-polygon/navigation/support_policy.py | 11 ++++++++--- 3 files changed, 18 insertions(+), 10 deletions(-) diff --git a/simulation/ai-polygon/nav2/terrain_observation.py b/simulation/ai-polygon/nav2/terrain_observation.py index b421dfb1..e417f028 100644 --- a/simulation/ai-polygon/nav2/terrain_observation.py +++ b/simulation/ai-polygon/nav2/terrain_observation.py @@ -119,10 +119,11 @@ class TerrainObservation: request['body_contact_height_m'], monitor=self.monitor) physical = points.copy() ground_at = time.monotonic() - self.support_obstacles.revalidate(points, pose, request['body_contact_height_m'], - monitor=self.monitor) + # Both checks use the same immutable terrain and pose in this transaction. + surface = self.support_obstacles.revalidate(points, pose, request['body_contact_height_m'], + monitor=self.monitor) self.support_obstacles.observe_ahead(points, pose, request['body_contact_height_m'], - monitor=self.monitor, speed_mps=float(request['max_speed_mps'])) + monitor=self.monitor, speed_mps=float(request['max_speed_mps']), surface=surface) support_at = time.monotonic() candidates = self.detections.observed(request) ground = current[ground[:,3] == 1] diff --git a/simulation/ai-polygon/navigation/support_obstacles.py b/simulation/ai-polygon/navigation/support_obstacles.py index 59f71d93..41e768fb 100644 --- a/simulation/ai-polygon/navigation/support_obstacles.py +++ b/simulation/ai-polygon/navigation/support_obstacles.py @@ -90,8 +90,9 @@ class SupportObstacles: self.keys.pop(key, None) del self.patches[key] offset += length + return surface - def observe_ahead(self, terrain, pose, contact_height_m, *, monitor, speed_mps): + def observe_ahead(self, terrain, pose, contact_height_m, *, monitor, speed_mps, surface=None): """Expose measured bad ground to search before a command reaches it. The reactive sweep remains authoritative. This bounded contact-width @@ -122,9 +123,10 @@ class SupportObstacles: axis=0, return_index=True) selected = candidates[indices] selected = selected[np.argsort(np.linalg.norm(local[selected],axis=1))][:512] - surface = SupportSurface(terrain, pose, contact_height_m, - monitor.max_step, monitor.max_slope, - anchor_radius_m=math.hypot(monitor.half_length, monitor.half_width)) + if surface is None: + surface = SupportSurface(terrain, pose, contact_height_m, + monitor.max_step, monitor.max_slope, + anchor_radius_m=math.hypot(monitor.half_length, monitor.half_width)) offsets = terrain[selected,:2]-pose[:2] states, _ = monitor.classify_contacts(surface, offsets) unsafe = offsets[states == 'observed-unsafe'] diff --git a/simulation/ai-polygon/navigation/support_policy.py b/simulation/ai-polygon/navigation/support_policy.py index 3298cae9..eee485b6 100644 --- a/simulation/ai-polygon/navigation/support_policy.py +++ b/simulation/ai-polygon/navigation/support_policy.py @@ -63,6 +63,12 @@ class SupportPolicy: anchor_radius_m=math.hypot(m.half_length, m.half_width), continuity_terrain=continuity_terrain, ) + return self._context(speed, yaw_rate, pose, surface) + + def _context(self, speed, yaw_rate, pose, surface): + # The live sweep and entering-track probes use the identical captured + # ground, pose and continuity. Share only within this control tick. + m = self.monitor qx, qy, qz, qw = pose[3:] yaw = math.atan2(2 * (qw * qz + qx * qy), 1 - 2 * (qy * qy + qz * qz)) axes = np.array([[math.cos(yaw), -math.sin(yaw)], [math.sin(yaw), math.cos(yaw)]]) @@ -70,7 +76,7 @@ class SupportPolicy: # sweep instead of inventing contact bands or upgrading pinned inputs. if m.contacts is None: fresh = m.assess_command_support( - speed, yaw_rate, [], pose, contact_height_m, surface=surface + speed, yaw_rate, [], pose, surface.contact_height, surface=surface ) return dict(available=fresh["admitted"], reason="legacy-fresh-sweep", patches=[]) patches = [] @@ -250,8 +256,7 @@ class SupportPolicy: "patches": [], } else: - context = self.context(speed, yaw_rate, current_points, pose, contact_height_m, - continuity_terrain=terrain) + context = self._context(speed, yaw_rate, pose, fresh_surface) if any(p["observed_unsafe"] for p in context["patches"]): scale, reason = 0.0, "observed-unsafe-support" elif not context["available"]: