Version urban lidar horizon and retain measured crossing exits
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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"]
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user