Restore observed recovery through native Nav2
This commit is contained in:
@@ -0,0 +1,99 @@
|
||||
"""Nav2 commands keep geometric vetoes without former proposal fallbacks."""
|
||||
import importlib
|
||||
from pathlib import Path
|
||||
|
||||
import numpy as np
|
||||
import pytest
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def admission(monkeypatch):
|
||||
monkeypatch.syspath_prepend(str(Path(__file__).parents[1]/'simulation/ai-polygon'))
|
||||
control = importlib.import_module('navigation.continuous_control')
|
||||
footprint = importlib.import_module('navigation.footprint')
|
||||
policy = importlib.import_module('navigation.support_policy')
|
||||
geometry = dict(length_m=1., width_m=.6, max_step_m=.1, max_slope_degrees=25.)
|
||||
monitor = footprint.Footprint(geometry)
|
||||
now, command = [10.], [.08, 0.]
|
||||
gate = control.ContinuousControl(monitor, policy.SupportPolicy(monitor),
|
||||
lambda _: None, lambda *_: None, lambda: (now[0], *command), clock=lambda: now[0],
|
||||
native_only=True, body_top_m=1.)
|
||||
points = np.array([[x,y,0.] for x in np.arange(-2,2.01,.075)
|
||||
for y in np.arange(-2,2.01,.075)])
|
||||
terrain = np.column_stack((points, np.zeros(len(points))))
|
||||
pose = [0.,0.,.37,0.,0.,0.,1.]
|
||||
request = dict(geometry_age_seconds=0., points=points, pose=pose, observation_id='sample-1',
|
||||
body_contact_height_m=.37, max_speed_mps=.1)
|
||||
result = dict(status='path', speed_mps=.1, yaw_rate_rps=.04, path=[[0.,0.,0.],[1.,0.,0.]],
|
||||
diagnostic={'terminal_approach':True})
|
||||
gate.observe(request); gate.accept(request, result, terrain)
|
||||
tick = dict(pose=pose, pose_age_seconds=0., perception_age_seconds=0., enabled=True,
|
||||
observation_id='sample-1', speed_mps=0.)
|
||||
return gate, now, command, tick
|
||||
|
||||
|
||||
def test_native_zero_cannot_use_previous_terminal_override(admission):
|
||||
gate, _, command, tick = admission
|
||||
assert gate.tick(tick)['speed_mps'] > 0
|
||||
command[:] = [0., 0.]
|
||||
result = gate.tick(tick)
|
||||
assert result['speed_mps'] == result['yaw_rate_rps'] == 0.
|
||||
assert result['command_source'] == 'nav2'
|
||||
|
||||
|
||||
def test_native_command_still_stops_for_new_obstacle(admission):
|
||||
gate, _, _, tick = admission
|
||||
gate.observe(dict(geometry_age_seconds=0., range_sequence=[1,2],
|
||||
points=np.vstack((gate.geometry[1], [[.525,0.,.5]]))))
|
||||
result = gate.tick(tick)
|
||||
assert result['speed_mps'] == result['yaw_rate_rps'] == 0.
|
||||
assert result['reason'] == 'obstacle'
|
||||
|
||||
|
||||
def test_native_command_still_loses_range_lease(admission):
|
||||
gate, now, _, tick = admission
|
||||
now[0] += .801
|
||||
result = gate.tick(tick)
|
||||
assert result['speed_mps'] == result['yaw_rate_rps'] == 0.
|
||||
assert result['reason'] == 'stale-range'
|
||||
|
||||
|
||||
@pytest.mark.parametrize('condition', ['clear','unknown-rear','lost-range','drop','obstacle','no-recovery'])
|
||||
def test_native_backup_requires_retained_support_and_live_hazard_veto(admission,condition):
|
||||
gate, _, command, tick = admission
|
||||
gate.support.observed_approaches=True
|
||||
record=gate.plans['sample-1']
|
||||
floor=record['terrain'].copy()
|
||||
current=floor[floor[:,0]>.75,:3]
|
||||
if condition=='unknown-rear':floor=floor[floor[:,0]>-.2]
|
||||
elif condition=='lost-range':current=np.empty((0,3))
|
||||
elif condition=='drop':
|
||||
rear=record['terrain'][record['terrain'][:,0]<-.45,:3].copy()
|
||||
rear[:,2]=-.4
|
||||
current=np.r_[current,rear]
|
||||
elif condition=='obstacle':current=np.r_[current,[[-.525,0.,.5]]]
|
||||
request={**record['value'],'points':current,'allow_reverse':True,
|
||||
'continuous':condition!='no-recovery'}
|
||||
gate.observe(request)
|
||||
gate.accept(request,record['result'],floor)
|
||||
command[:]=[-.1,0.]
|
||||
result=gate.tick(tick)
|
||||
if condition=='clear':
|
||||
assert result['speed_mps']==-.1 and result['yaw_rate_rps']==0.
|
||||
assert result['support_policy']=='observed-static-ground-retreat'
|
||||
else:
|
||||
assert result['speed_mps']==result['yaw_rate_rps']==0.,result
|
||||
|
||||
|
||||
def test_refined_detection_subset_is_shared_with_control_without_removing_raw_range(admission):
|
||||
gate, _, _, tick = admission
|
||||
record=gate.plans['sample-1']
|
||||
request={**record['value'],'detection_point_indices':[0,1]}
|
||||
gate.accept(request,record['result'],record['terrain'],detections=request['points'][[1]])
|
||||
np.testing.assert_array_equal(gate.plans['sample-1']['detections'],request['points'][[1]])
|
||||
assert len(gate.geometry[1])==len(request['points'])
|
||||
with pytest.raises(ValueError,match='original associated range'):
|
||||
gate.accept(request,record['result'],record['terrain'],detections=[[99,99,99]])
|
||||
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'
|
||||
Reference in New Issue
Block a user