Batch exact ground support queries in the control loop

This commit is contained in:
DCCONSTRUCTIONS
2026-10-10 04:57:32 +03:00
parent d8c79a1134
commit 5a68240511
2 changed files with 85 additions and 18 deletions
+44
View File
@@ -115,3 +115,47 @@ def test_support_guard_reduces_same_arc_or_stops_before_unknown(monitor):
assert (v, w, scale) == (0, 0, 0) and not support["admitted"]
blocked = np.vstack((ground(), [[0, 0, 0.3, 0.3]]))
assert monitor.regulate_supported_command(0.2, 0, blocked, POSE, 0.37)[:3] == (0, 0, 0)
@pytest.mark.parametrize("translation", [(0., 0.), (-125., 48.), (1e9, -1e9)])
def test_ground_columns_keep_relief_and_only_remove_measured_wall_layer(monitor, translation):
from navigation.support_surface import SupportSurface
# Separate columns, including negative coordinates, must not alias. Raised
# returns only suppress higher low-cost samples in their own XY column.
points = np.array([
[-.10, -.10, 0., 0.], [-.10, -.10, .04, 0.],
[-.10, -.10, .09, 0.], [-.10, -.10, .8, 1.],
[-.10, .10, .09, 0.], [.10, -.10, .09, 0.],
[.10, .10, -.4, 0.], [.10, .10, -.32, 0.],
[.10, .10, -.1, 1.],
])
points[:, :2] += translation
assert np.array_equal(SupportSurface.ground_layer(points, .1), points[[0, 1, 4, 5, 6], :3])
def test_contact_batch_does_not_mix_neighbouring_relief_or_missing_support(monitor):
from collections import Counter
from navigation.support_surface import SupportSurface
terrain = ground()
terrain[:, 2] = .065 * np.sin(terrain[:, 0] * 25) * np.cos(terrain[:, 1] * 20)
terrain[terrain[:, 0] > .9, 2] -= .4
terrain = terrain[~((terrain[:, 0] < -.9) & (terrain[:, 1] > .4))]
samples = np.array([[x, y] for x in np.arange(-1.4, 1.41, .14)
for y in np.arange(-1.4, 1.41, .14)])
def surface():
return SupportSurface(terrain, POSE, .37, .1, math.tan(math.radians(25)))
batched, individual = surface(), surface()
states, reasons = batched.classify_contacts(samples, .22)
expected_states, expected_reasons = [], Counter()
for sample in samples:
single_states, single_reasons = individual.classify_contacts([sample], .22)
expected_states.extend(single_states)
expected_reasons.update(single_reasons)
assert np.array_equal(states, expected_states)
assert reasons == dict(expected_reasons)
assert "unknown" in states and "observed-unsafe" in states
# Cache hits and repeated query ordering do not share another cell's veto.
order = np.r_[np.arange(len(samples)-1, -1, -1), np.arange(12)]
repeated, counts = batched.classify_contacts(samples[order], .22)
assert np.array_equal(repeated, states[order])
assert sum(counts.values()) == len(order)