Version urban lidar horizon and retain measured crossing exits

This commit is contained in:
DCCONSTRUCTIONS
2026-10-10 03:50:39 +03:00
parent 857bd1fc7b
commit 18e6a0e971
8 changed files with 95 additions and 15 deletions
@@ -24,11 +24,13 @@ class ContinuousComposition(ComposedInference):
self.recovery_view_request = None
self.recovery_detection_view = None
self.last_supplement = -math.inf
self.crossing = MarkedCrossing(self.geometry)
self.crossing = MarkedCrossing(self.geometry, observation_range_m=max(
12., self.inputs["sensors"]["mounts"]["k1"]["range_m"][1]))
def reset(self):
super().reset()
self.crossing = MarkedCrossing(self.geometry)
self.crossing = MarkedCrossing(self.geometry, observation_range_m=max(
12., self.inputs["sensors"]["mounts"]["k1"]["range_m"][1]))
self.recovery_view_request = None
self.recovery_detection_view = None
+3 -2
View File
@@ -279,7 +279,7 @@ def mounted_range_returns(query, origin, directions, key, spec, forward, *,
itself is scalar, avoiding thousands of tiny NumPy allocations per frame.
"""
count = len(directions)
maximum = np.full(count, 8.0) if key == "k1" else np.minimum(8.0, 6.0 / forward)
maximum = np.full(count, spec["range_m"][1]) if key == "k1" else np.minimum(8.0, 6.0 / forward)
# PhysX consumes Float3 internally. Native callers avoid repeated pybind
# sequence conversion; portable checks can use the identical tuple contract.
mount = query_vector(origin)
@@ -304,7 +304,8 @@ def mounted_range_returns(query, origin, directions, key, spec, forward, *,
distances = np.linalg.norm(positions - origin, axis=1)
depth = np.full(count, np.nan, np.float32)
if key == "k1":
valid = np.isfinite(distances) & (distances >= spec["range_m"][0])
valid = (np.isfinite(distances) & (distances >= spec["range_m"][0])
& (distances <= spec["range_m"][1]))
positions[no_hit] = origin + directions[no_hit] * maximum[no_hit, None]
clear = valid | no_hit
else:
+8 -5
View File
@@ -20,7 +20,10 @@ class MarkedCrossing:
grid_m = .2
ground_tolerance_m = .1
def __init__(self, geometry):
def __init__(self, geometry, *, observation_range_m=12.):
if not math.isfinite(observation_range_m) or not 12 <= observation_range_m <= 40:
raise ValueError("Invalid crossing observation range")
self.observation_range_m = observation_range_m
self.geometry = geometry
self.previous = self.stopped_since = self.active = None
self.measured = OrderedDict()
@@ -32,7 +35,7 @@ class MarkedCrossing:
This bounded static-scene semantic evidence supplies no ground/support
certificate. Current range and objects still veto every commanded sweep.
"""
near = np.linalg.norm(points[:, :2]-pose[:2], axis=1) < 12
near = np.linalg.norm(points[:, :2]-pose[:2], axis=1) < self.observation_range_m
for point, label in zip(points[near & ground], sampled[near & ground]):
key = tuple(np.floor(point / [.2, .2, .06]).astype(int))
if label in (1, 3):
@@ -41,7 +44,7 @@ class MarkedCrossing:
elif label in (4, 5):
self.measured.pop(key, None)
for key, (point, _) in list(self.measured.items()):
if np.linalg.norm(point[:2]-pose[:2]) >= 12:
if np.linalg.norm(point[:2]-pose[:2]) >= self.observation_range_m:
del self.measured[key]
while len(self.measured) > 6000:
self.measured.popitem(last=False)
@@ -173,7 +176,7 @@ class MarkedCrossing:
# Completion and abandonment revoke this manoeuvre. It cannot
# expand indefinitely by following unrelated new yellow pixels.
if (relative[0] > a['exit_forward']+self.geometry['length_m']/2
or np.linalg.norm(relative) > 16):
or np.linalg.norm(relative) > max(16., self.observation_range_m+self.geometry["length_m"])):
self.active = None
self.stopped_since = None
self.measured.clear()
@@ -189,7 +192,7 @@ class MarkedCrossing:
distance = np.linalg.norm(relative, axis=1)
height = (remembered-pose[:3]) @ up + self.geometry['body_contact_height_m']
on_ground = np.abs(height) <= .1+distance*math.tan(math.radians(self.geometry['max_slope_degrees']))
paint = (classes == 3) & on_ground & (relative[:, 0] > 0) & (distance < 12)
paint = (classes == 3) & on_ground & (relative[:, 0] > 0) & (distance < self.observation_range_m)
state.update(self._admit(remembered, relative, classes, on_ground,
paint, pose, axes, now))
else:
@@ -300,7 +300,7 @@ def mounted_sensor_rig(robot, camera_height, *, legacy=False, continuous=False):
camera_forward_m=0.665,
camera_pitch_degrees=-30.0,
focal_length_mm=13.0,
mounts=rover_mounts(camera_height),
mounts=rover_mounts(camera_height, urban_range=continuous),
)
if continuous:
if legacy:
@@ -8,11 +8,12 @@ import copy
import math
SCHEMA = "missioncore.rover-sensor-mounts/v1"
URBAN_SCHEMA = "missioncore.rover-sensor-mounts/v2"
def rover_mounts(height=0.8):
def rover_mounts(height=0.8, *, urban_range=False):
return {
"schema_version": SCHEMA,
"schema_version": URBAN_SCHEMA if urban_range else SCHEMA,
"frame": "body-x-forward-y-left-z-up-from-ground-contact",
"calibration_status": "engineering-approximation-not-device-calibration",
"insta360": {
@@ -47,10 +48,14 @@ def rover_mounts(height=0.8):
"tilt_forward_degrees": 15.0,
"body_size_m": [0.11, 0.11, 0.20],
"elevation_degrees": [-7.0, 52.0],
"range_m": [0.3, 8.0],
# K1 publishes 40m @10% reflectivity. This ideal first-hit
# surrogate uses a bounded 20m urban horizon, not a guarantee of
# real-device range/reflectivity or its native sampling pattern.
"range_m": [0.3, 20.0 if urban_range else 8.0],
"scope": (
"MID360-published-FOV; mount-assumed; "
"bounded-uniform-sampling-not-vendor-scan-pattern; 8m-lab-horizon"
"bounded-uniform-sampling-not-vendor-scan-pattern; "
+ ("20m-urban-horizon" if urban_range else "8m-lab-horizon")
),
},
}
@@ -63,7 +68,10 @@ def validate_mounts(value):
height = value["insta360"]["body_center_m"][2]
if type(height) not in (int, float) or not math.isfinite(height) or not 0.78 <= height <= 2:
raise ValueError("Invalid sensor mounting height")
if value != rover_mounts(height):
schema = value.get("schema_version")
if schema not in (SCHEMA, URBAN_SCHEMA):
raise ValueError("Unsupported sensor mount version")
if value != rover_mounts(height, urban_range=schema == URBAN_SCHEMA):
raise ValueError("Unsupported or changed sensor mount calibration")
except (KeyError, TypeError, IndexError) as exc:
raise ValueError("Invalid sensor mounts") from exc
+21
View File
@@ -256,3 +256,24 @@ def test_coordinator_inputs_do_not_import_numpy_pydantic_or_core():
env={**os.environ, "PYTHONPATH": str(ROOT / "src")},
check=True,
)
def test_extended_lidar_horizon_is_versioned_and_old_mounts_stay_immutable():
from k1link.simulation.ai_polygon.sensor_mounts import rover_mounts, validate_mounts
from k1link.simulation.ai_polygon.run_inputs import mounted_sensor_rig, validate_sensor_rig
legacy = rover_mounts(.8)
current = mounted_sensor_rig(select_robot("dcd006-v020"), .8, continuous=True)
assert legacy["schema_version"] == "missioncore.rover-sensor-mounts/v1"
assert legacy["k1"]["range_m"] == [.3, 8.]
assert current["mounts"]["schema_version"] == "missioncore.rover-sensor-mounts/v2"
assert current["mounts"]["k1"]["range_m"] == [.3, 20.]
assert validate_mounts(legacy) == legacy
validate_sensor_rig(current)
# Archived v4 camera captures keep their original, explicit v1 range.
old_rig = copy.deepcopy(current); old_rig["mounts"] = legacy
validate_sensor_rig(old_rig)
assert digest(old_rig) != digest(current)
for spec in (legacy, current["mounts"]):
altered = copy.deepcopy(spec); altered["k1"]["range_m"][1] += 1.
with pytest.raises(ValueError, match="changed sensor mount"):
validate_mounts(altered)
+23
View File
@@ -170,3 +170,26 @@ def test_retained_crossing_does_not_admit_new_ground_above_or_outside_it(module)
g = gate(module); assert enter(g, scene())[1]['admitted']
points = np.array([[3, 0, 0], [3, 0, .4], [3, 2, 0], [3, 0, -1.]])
assert g.ground_mask(points).tolist() == [True, False, False, False]
def test_wide_crossing_requires_measured_exit_within_declared_horizon(module):
x, y = np.meshgrid(np.arange(.4, 18., .2), np.arange(-1., 1.01, .2), indexing="ij")
points = np.column_stack((x.ravel(), y.ravel(), np.zeros(x.size)))
pixels = np.unravel_index(np.arange(len(points)), (512, 512))
labels = np.zeros((512, 512), np.uint8)
paint = (points[:,0] >= 1.) & (points[:,0] < 15.5) & (np.mod(points[:,0]+.01, 1.) < .45)
sidewalk = (points[:,0] < 1.) | (points[:,0] >= 16.)
labels[pixels[0][paint], pixels[1][paint]] = 3
labels[pixels[0][sidewalk], pixels[1][sidewalk]] = 1
data = labels, points, pixels, np.array([0.,0.,.37,0.,0.,0.,1.])
geometry = gate(module).geometry
assert not enter(module.MarkedCrossing(geometry), data)[1]["admitted"]
current = module.MarkedCrossing(geometry, observation_range_m=20.)
assert enter(current, data)[1]["admitted"]
# Enlarging the observation domain cannot manufacture an unobserved exit.
near = np.linalg.norm(points[:,:2], axis=1) <= 8.
cropped = labels, points[near], tuple(p[near] for p in pixels), data[-1]
assert not enter(module.MarkedCrossing(geometry, observation_range_m=20.), cropped)[1]["admitted"]
current = module.MarkedCrossing(geometry, observation_range_m=20.)
labels[pixels[0][points[:,0]>=16.], pixels[1][points[:,0]>=16.]] = 0
assert not enter(current, data)[1]["admitted"]
+22
View File
@@ -83,3 +83,25 @@ settings.persistent = false
assert Path(prepare_experience(sdk, out)).read_bytes() == first
python.write_text(python.read_text().replace("6.1.0", "6.2.0"))
with pytest.raises(RuntimeError, match="Unsupported"): prepare_experience(sdk, out)
@pytest.mark.parametrize("maximum", [8., 20.])
def test_lidar_observation_horizon_comes_from_versioned_sensor_spec(maximum):
class Query:
def __init__(self): self.limits = []
def raycast_closest(self, origin, direction, distance, bothSides):
self.limits.append(distance)
if len(self.limits) == 1 and distance >= 14.:
return dict(hit=True, position=[14., 0., 0.], collision="/World/Exit")
return dict(hit=False)
q = Query(); ranges = []
observed, ends, _, paths = mounted_range_returns(q, np.zeros(3),
np.array([[1.,0.,0.],[0.,1.,0.]]), "k1", dict(range_m=[.3,maximum]), np.ones(2),
organized_ranges=ranges)
assert q.limits == [maximum, maximum]
assert len(observed) == int(maximum >= 14.)
assert paths == (["/World/Exit"] if maximum >= 14. else [])
np.testing.assert_array_equal(ranges[0], [14. if maximum >= 14. else maximum, maximum])
assert ends[-1].tolist() == [0., maximum, 0.]
# A missing return only contributes a clearing ray, never supporting ground.
assert not any(np.array_equal(p, ends[-1]) for p in observed)