Separate forbidden ground from body collision and retain capture phase
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
"""Render jitter must not silently lower the requested capture rate."""
|
||||
import importlib
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def cadence(monkeypatch):
|
||||
monkeypatch.syspath_prepend(str(Path(__file__).parents[1] / "simulation/ai-polygon"))
|
||||
return importlib.import_module("scheduling_policy").CaptureCadence
|
||||
|
||||
|
||||
def test_ten_hz_capture_survives_sixteen_hz_render_quantization(cadence):
|
||||
clock = cadence(10, 0.)
|
||||
admitted = [i/16 for i in range(1, 161) if clock.due(i/16)]
|
||||
assert len(admitted) == 100
|
||||
assert all(0 <= actual - (i+1)/10 < 1/16 + 1e-9
|
||||
for i, actual in enumerate(admitted))
|
||||
assert set(round(b-a, 8) for a, b in zip(admitted, admitted[1:], strict=False)) == {.0625, .125}
|
||||
|
||||
|
||||
def test_overload_and_pause_discard_missed_slots_without_a_burst(cadence):
|
||||
clock = cadence(10, 100.)
|
||||
assert not clock.due(100.05)
|
||||
assert clock.due(102.035)
|
||||
assert not clock.due(102.035)
|
||||
assert not clock.due(102.05)
|
||||
assert clock.due(102.1)
|
||||
assert not clock.due(102.1)
|
||||
# A long operator pause creates no queued frames or catch-up workload.
|
||||
assert clock.due(500.07)
|
||||
assert not clock.due(500.08)
|
||||
assert clock.due(500.11)
|
||||
|
||||
|
||||
def test_invalid_clocks_and_rates_are_rejected(cadence):
|
||||
for rate in (0, -1, float("nan"), float("inf"), True):
|
||||
with pytest.raises(ValueError):
|
||||
cadence(rate, 0.)
|
||||
with pytest.raises(ValueError):
|
||||
cadence(10, float("nan"))
|
||||
with pytest.raises(ValueError):
|
||||
cadence(10, 0.).due(float("nan"))
|
||||
@@ -97,3 +97,103 @@ def test_refined_detection_subset_is_shared_with_control_without_removing_raw_ra
|
||||
gate.observe(dict(geometry_age_seconds=0.,range_sequence=[1,2],
|
||||
points=np.vstack((gate.geometry[1],[[.525,0.,.5]]))))
|
||||
assert gate.tick(tick)['reason']=='obstacle'
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def tracked_admission(admission):
|
||||
gate, now, command, tick = admission
|
||||
footprint = importlib.import_module('navigation.footprint')
|
||||
geometry = dict(length_m=1.2, width_m=.6, collision_length_m=1.8,
|
||||
max_step_m=.1, max_slope_degrees=25., ground_contact=dict(
|
||||
schema_version='missioncore.ground-contact/v1', model='two-track-bottom-bands',
|
||||
bands=[dict(side='left', lower_xy_m=[-.4,.2], upper_xy_m=[.3,.3]),
|
||||
dict(side='right', lower_xy_m=[-.4,-.3], upper_xy_m=[.3,-.2])]))
|
||||
monitor = footprint.Footprint(geometry)
|
||||
gate.monitor = gate.support.monitor = monitor
|
||||
gate.ground_monitor = monitor.ground_envelope()
|
||||
gate.support.observed_pivots = gate.support.observed_approaches = True
|
||||
return gate, now, command, tick
|
||||
|
||||
|
||||
@pytest.mark.parametrize('command', [(0.,.15),(0.,-.15),(-.1,0.)])
|
||||
def test_forbidden_floor_under_overhang_does_not_block_supported_native_escape(
|
||||
tracked_admission, command):
|
||||
gate, _, proposal, tick = tracked_admission
|
||||
record = gate.plans['sample-1']
|
||||
physical = np.r_[record['terrain'], [[.75,0.,0.,0.]]]
|
||||
terrain = physical.copy()
|
||||
terrain[-1,3] = 1.
|
||||
request = {**record['value'], 'allow_reverse':command[0]<0, 'continuous':True}
|
||||
proposal[:] = command
|
||||
gate.accept(request,record['result'],terrain)
|
||||
assert gate.tick(tick)['reason'] == 'obstacle' # Reproduces the previous conflation.
|
||||
gate.accept(request,record['result'],terrain,collision_terrain=physical)
|
||||
result = gate.tick(tick)
|
||||
assert result['reason']=='none', result
|
||||
assert (result['speed_mps'],result['yaw_rate_rps']) == command
|
||||
assert result['command_source']=='nav2'
|
||||
|
||||
|
||||
@pytest.mark.parametrize('source', [
|
||||
'retained-solid','fresh-solid','track-exclusion','unknown-support'])
|
||||
def test_separated_floor_never_waives_solid_collision_or_ground_safety(tracked_admission,source):
|
||||
gate, _, command, tick = tracked_admission
|
||||
record = gate.plans['sample-1']
|
||||
physical = np.r_[record['terrain'], [[.75,0.,0.,0.]]]
|
||||
terrain = physical.copy()
|
||||
terrain[-1,3] = 1.
|
||||
command[:] = [0.,.15]
|
||||
if source=='retained-solid':
|
||||
physical[-1] = terrain[-1] = [.75,0.,.5,1.]
|
||||
elif source=='fresh-solid':
|
||||
gate.observe(dict(geometry_age_seconds=0.,range_sequence=[1,2],
|
||||
points=np.r_[gate.geometry[1], [[.75,0.,.5]]]))
|
||||
elif source=='track-exclusion':
|
||||
physical[-1,:2] = terrain[-1,:2] = [.2,.25]
|
||||
else:
|
||||
physical = physical[physical[:,0]>.9]
|
||||
terrain = terrain[terrain[:,0]>.9]
|
||||
gate.observe(dict(geometry_age_seconds=0.,range_sequence=[1,2],
|
||||
points=physical[:,:3]))
|
||||
gate.accept(record['value'],record['result'],terrain,collision_terrain=physical)
|
||||
result = gate.tick(tick)
|
||||
assert result['speed_mps']==result['yaw_rate_rps']==0.,result
|
||||
if source.endswith('solid'):
|
||||
assert result['reason']=='obstacle'
|
||||
if source=='track-exclusion':
|
||||
assert result['reason']=='forbidden-ground-sweep'
|
||||
|
||||
|
||||
def test_new_floor_exclusion_reduces_forward_command(tracked_admission):
|
||||
gate, _, command, tick = tracked_admission
|
||||
record = gate.plans['sample-1']
|
||||
physical = np.r_[record['terrain'], [[.6,0.,0.,0.]]]
|
||||
terrain = physical.copy()
|
||||
terrain[-1,3] = 1.
|
||||
command[:] = [.1,0.]
|
||||
gate.accept(record['value'],record['result'],terrain,collision_terrain=physical)
|
||||
result = gate.tick(tick)
|
||||
assert 0 <= result['speed_mps'] < .1 and result['yaw_rate_rps']==0.,result
|
||||
|
||||
|
||||
def test_legacy_contact_geometry_retains_full_body_surface_veto(admission):
|
||||
gate, _, command, tick = admission
|
||||
assert gate.ground_monitor is gate.monitor
|
||||
record = gate.plans['sample-1']
|
||||
physical = np.r_[record['terrain'], [[.4,0.,0.,0.]]]
|
||||
terrain = physical.copy()
|
||||
terrain[-1,3] = 1.
|
||||
command[:] = [0.,.15]
|
||||
gate.accept(record['value'],record['result'],terrain,collision_terrain=physical)
|
||||
assert gate.tick(tick)['reason']=='forbidden-ground-sweep'
|
||||
|
||||
|
||||
def test_surface_separation_rejects_misaligned_or_lowered_observations(admission):
|
||||
gate, _, _, _ = admission
|
||||
record = gate.plans['sample-1']
|
||||
terrain = record['terrain']
|
||||
for field in (0,3):
|
||||
altered=terrain.copy()
|
||||
altered[0,field]+=1
|
||||
with pytest.raises(ValueError,match='share the measured terrain'):
|
||||
gate.accept(record['value'],record['result'],terrain,collision_terrain=altered)
|
||||
|
||||
Reference in New Issue
Block a user