perf(simulation): reuse support surface within an observation
This commit is contained in:
@@ -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]
|
||||
|
||||
@@ -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']
|
||||
|
||||
@@ -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"]:
|
||||
|
||||
Reference in New Issue
Block a user