Preserve installed operator workspace before consolidation
Local preservation snapshot, not a new deployment or simulation acceptance.
This commit is contained in:
@@ -10,6 +10,7 @@ surfaces, excessive roughness and sparse/unknown support retain the CMU cost.
|
||||
import ctypes
|
||||
import hashlib
|
||||
import math
|
||||
import weakref
|
||||
from collections import OrderedDict
|
||||
from pathlib import Path
|
||||
|
||||
@@ -51,15 +52,20 @@ def connected_grade(nearby):
|
||||
reached = expanded
|
||||
|
||||
|
||||
def underbody_support_costs(terrain, pose, contact_height_m=0.37):
|
||||
def underbody_support_costs(terrain, pose, contact_height_m=None, *, geometry):
|
||||
"""Reconcile low returns already inside the current chassis footprint.
|
||||
|
||||
CMU's neighbourhood ground reference can label the supported terrain under
|
||||
the chassis as a body collision. Use measured pose and the declared contact
|
||||
height only inside the body (with a 5 cm inset), never for terrain ahead.
|
||||
height only inside the actual body, never for terrain ahead. A clearance
|
||||
reserve belongs outside the body; insetting the occupied area leaves low
|
||||
ground beneath track edges misclassified as an impossible body collision.
|
||||
Retain drops, high returns and excessive tilt. The 8 cm band has 2 cm reserve
|
||||
below the physically qualified 10 cm step; raw terrain memory is unchanged.
|
||||
"""
|
||||
if contact_height_m is None:
|
||||
contact_height_m = geometry["body_contact_height_m"]
|
||||
extent = np.array([geometry["length_m"], geometry["width_m"]]) / 2
|
||||
result = terrain.copy()
|
||||
x, y, z, w = pose[3:]
|
||||
up = np.array([2 * (x * z + w * y), 2 * (y * z - w * x), 1 - 2 * (x * x + y * y)])
|
||||
@@ -70,13 +76,13 @@ def underbody_support_costs(terrain, pose, contact_height_m=0.37):
|
||||
local = (terrain[:, :2] - pose[:2]) @ axes
|
||||
height = (terrain[:, :3] - pose[:3]) @ up + contact_height_m
|
||||
supported = (
|
||||
(np.abs(local) < 0.45).all(axis=1) & (np.abs(height) <= 0.08) & (terrain[:, 3] > 0.1)
|
||||
(np.abs(local) < extent).all(axis=1) & (np.abs(height) <= 0.08) & (terrain[:, 3] > 0.1)
|
||||
)
|
||||
result[supported, 3] = np.abs(height[supported])
|
||||
return result, int(supported.sum())
|
||||
|
||||
|
||||
def _neighborhoods(terrain, radius=0.4):
|
||||
def _reference_neighborhoods(terrain, radius=0.4):
|
||||
"""Exact radius neighborhoods without scanning the whole accumulated map.
|
||||
|
||||
Returns in the nine adjacent cells include every possible neighbor. Keep
|
||||
@@ -107,13 +113,68 @@ def _neighborhoods(terrain, radius=0.4):
|
||||
return around
|
||||
|
||||
|
||||
class _NativeNeighborhoods:
|
||||
def __init__(self, terrain):
|
||||
self.terrain = terrain
|
||||
suffix = "f32" if terrain.dtype.itemsize == 4 else "f64"
|
||||
dtype = ctypes.c_float if suffix == "f32" else ctypes.c_double
|
||||
create = getattr(_NATIVE, "terrain_neighbors_create_" + suffix)
|
||||
create.argtypes = [ctypes.POINTER(dtype), ctypes.c_int]
|
||||
create.restype = ctypes.c_void_p
|
||||
self.query = getattr(_NATIVE, "terrain_neighbors_query_" + suffix)
|
||||
self.query.argtypes = [ctypes.c_void_p, ctypes.c_int, ctypes.POINTER(ctypes.c_int)]
|
||||
self.query.restype = ctypes.c_int
|
||||
destroy = getattr(_NATIVE, "terrain_neighbors_destroy_" + suffix)
|
||||
destroy.argtypes = [ctypes.c_void_p]
|
||||
destroy.restype = None
|
||||
xyz = np.ascontiguousarray(terrain[:, :3])
|
||||
self.handle = create(xyz.ctypes.data_as(ctypes.POINTER(dtype)), len(xyz))
|
||||
self.finalizer = weakref.finalize(self, destroy, self.handle)
|
||||
self.indices = np.empty(len(terrain), dtype=np.int32)
|
||||
self.screen = getattr(_NATIVE, "terrain_neighbors_screen_" + suffix, None)
|
||||
if self.screen is not None:
|
||||
self.screen.argtypes = [ctypes.c_void_p, ctypes.POINTER(ctypes.c_int),
|
||||
ctypes.c_int, ctypes.c_int, ctypes.c_double,
|
||||
ctypes.POINTER(ctypes.c_int)]
|
||||
self.screen.restype = ctypes.c_int
|
||||
|
||||
def candidates(self, indices):
|
||||
if self.screen is None:
|
||||
return indices # Previous pinned kernel retains the reference path.
|
||||
indices = np.ascontiguousarray(indices, dtype=np.int32)
|
||||
output = np.empty_like(indices)
|
||||
count = self.screen(self.handle, indices.ctypes.data_as(ctypes.POINTER(ctypes.c_int)),
|
||||
len(indices), 8, 0.8*math.tan(math.radians(25+1e-4))+0.15,
|
||||
output.ctypes.data_as(ctypes.POINTER(ctypes.c_int)))
|
||||
return output[:count]
|
||||
|
||||
def __call__(self, index):
|
||||
count = self.query(
|
||||
self.handle, int(index), self.indices.ctypes.data_as(ctypes.POINTER(ctypes.c_int))
|
||||
)
|
||||
return self.terrain[self.indices[:count], :3] - self.terrain[index, :3]
|
||||
|
||||
|
||||
def _neighborhoods(terrain):
|
||||
if (
|
||||
_NATIVE is not None
|
||||
and hasattr(_NATIVE, "terrain_neighbors_create_f32")
|
||||
and terrain.dtype in (np.dtype("float32"), np.dtype("float64"))
|
||||
):
|
||||
return _NativeNeighborhoods(terrain)
|
||||
return _reference_neighborhoods(terrain)
|
||||
|
||||
|
||||
def supported_slope_costs(terrain, cache=None):
|
||||
result = terrain.copy()
|
||||
if len(terrain) < 8:
|
||||
return result, 0
|
||||
around = _neighborhoods(terrain)
|
||||
corrected = 0
|
||||
for index in np.flatnonzero(terrain[:, 3] > 0.1):
|
||||
indices = np.flatnonzero(terrain[:, 3] > 0.1)
|
||||
if isinstance(around, _NativeNeighborhoods):
|
||||
indices = around.candidates(indices)
|
||||
for index in indices:
|
||||
nearby = around(index)
|
||||
if len(nearby) < 8:
|
||||
continue
|
||||
|
||||
Reference in New Issue
Block a user