Guide local goals around observed obstacles and finish native recovery
This commit is contained in:
@@ -265,3 +265,54 @@ def test_uneven_range_horizon_does_not_pull_straight_intent_sideways(selector,ya
|
||||
assert np.min(np.linalg.norm(points-goal,axis=1))<1e-9
|
||||
# A local reference grants no synthetic ground or permission.
|
||||
assert selector.choose(np.empty((0,3)),pose,target,goal,(),GEOMETRY,1) is None
|
||||
|
||||
|
||||
def clearance_receipt(position, obstacles, seconds=1):
|
||||
return dict(clearance_observation=dict(obstacles_xy=obstacles,
|
||||
observation=dict(pose=position, simulation_time_seconds=seconds,
|
||||
execution_inputs_sha256='run')))
|
||||
|
||||
|
||||
@pytest.mark.parametrize('yaw,shift', [(0, (0, 0)), (73, (42, -17)), (-138, (-250, 52))])
|
||||
def test_unlabelled_pole_changes_approach_before_body_gets_close(selector, yaw, shift):
|
||||
points, position, target, _, rotation = road(yaw, shift)
|
||||
geometry = {**GEOMETRY, 'length_m': 1.163, 'max_step_m': .1}
|
||||
selector.observe(np.c_[points, np.ones(len(points))], 1., position)
|
||||
old_goal = selector.choose(points, position, target, None, (), geometry, 1.)
|
||||
# No semantic object name is required: native physical geometry supplies it.
|
||||
pole = np.array([[1.9, -.25]]) @ rotation.T + shift
|
||||
selector.observe_navigation(clearance_receipt(position, pole.tolist()),
|
||||
position, 1, 'run', 1.)
|
||||
goal = selector.choose(points, position, target, old_goal, (), geometry, 1.1)
|
||||
lateral = ((np.array(goal[:2])-shift) @ rotation)[1]
|
||||
assert lateral > .3
|
||||
assert selector.approach_clearance(np.array([goal]), position, geometry, 1.1)[0] > (
|
||||
selector.approach_clearance(np.array([old_goal]), position, geometry, 1.1)[0]+.1)
|
||||
assert np.min(np.linalg.norm(points-goal, axis=1)) < 1e-9
|
||||
# Ranking is not new ground permission and expired geometry is not refreshed.
|
||||
assert selector.choose(points, position, target, None, (), geometry, 1.1,
|
||||
lambda p: np.zeros(len(p), bool)) is None
|
||||
assert np.isinf(selector.approach_clearance(np.array([goal]),position,geometry,1.81)[0])
|
||||
|
||||
|
||||
def test_obstacle_beyond_goal_has_less_effect_than_one_on_approach(selector):
|
||||
points, position, target, _, _ = road()
|
||||
selector.observe(np.c_[points,np.ones(len(points))],1.,position)
|
||||
candidates=np.array([[3.,0.,0.],[3.,.6,0.]])
|
||||
selector.observe_navigation(clearance_receipt(position, [[1.6,0.]]),position,1,'run',1.)
|
||||
scores, clearances=selector.clearance_cost(candidates,position,GEOMETRY,1.1)
|
||||
assert clearances[0] == 0. and scores[0] > scores[1]
|
||||
# Looking only at the final point misses this mid-approach obstruction.
|
||||
assert np.linalg.norm(candidates[0,:2]-[1.6,0.]) > 1.
|
||||
|
||||
|
||||
@pytest.mark.parametrize('mismatch', ['run','pose','time'])
|
||||
def test_clearance_receipt_is_bound_and_does_not_invent_semantics(selector,mismatch):
|
||||
_,position,_,_,_=road()
|
||||
receipt=clearance_receipt(position,[[1.5,0.]])
|
||||
run,seconds='run',1
|
||||
if mismatch=='run':run='different'
|
||||
elif mismatch=='time':seconds=2
|
||||
elif mismatch=='pose':position=[1.,*position[1:]]
|
||||
selector.observe_navigation(receipt,position,seconds,run,1.)
|
||||
assert selector.clearance_observation is None and not selector.surface.cells
|
||||
|
||||
@@ -58,3 +58,17 @@ def test_mission_translation_rotation_and_endpoint_do_not_change_navigation_conf
|
||||
changed["mission"]["route_xy"] = [[-500., 700.], [-503., 702.]]
|
||||
changed["sha256"] = digest({k: v for k, v in changed.items() if k != "sha256"})
|
||||
assert configure(changed, robot) == original
|
||||
|
||||
|
||||
def test_clearance_potential_spans_the_local_intent_horizon(configured):
|
||||
configure, inputs, robot = configured
|
||||
config = configure(inputs, robot)
|
||||
for name in ('global_costmap', 'local_costmap'):
|
||||
grid = config[name][name]['ros__parameters']
|
||||
layer = grid['inflation_layer']
|
||||
assert layer['inflation_radius'] >= 3.5
|
||||
# The native exponential must still distinguish the middle of a
|
||||
# passage from its edge well outside the hard collision reserve.
|
||||
cost = lambda d: 252*math.exp(-layer['cost_scaling_factor']*d)
|
||||
assert cost(1.) > cost(2.) > cost(3.) > 1.
|
||||
assert grid['footprint_padding'] == .05 and grid['track_unknown_space']
|
||||
|
||||
@@ -118,3 +118,23 @@ def test_native_module_identity_includes_behavior_helpers(monkeypatch,helper):
|
||||
after=identities()
|
||||
assert before['simulation-nav2-navigation']!=after['simulation-nav2-navigation']
|
||||
assert before['simulation-waypoint-mission']==after['simulation-waypoint-mission']
|
||||
|
||||
|
||||
@pytest.mark.parametrize('kind', ['overhang-ground','physical-object','track-ground'])
|
||||
def test_spin_selection_keeps_body_and_track_surface_domains_separate(motion,kind):
|
||||
from differential_motion import alignment_angle
|
||||
from navigation.footprint import 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(geometry)
|
||||
floor=np.array([[i*.05,j*.05,0.,0.] for i in range(-30,31) for j in range(-30,31)])
|
||||
point=np.array([[0.,-.45 if kind=='track-ground' else -.82,0.,1.]])
|
||||
terrain=np.r_[floor,point]
|
||||
collision=terrain.copy()
|
||||
if kind!='physical-object':collision[-1,3]=0.
|
||||
angle=alignment_angle(pose(),[0.,2.,0.],terrain,[],monitor,.37,
|
||||
collision_terrain=collision)
|
||||
assert (angle is not None) == (kind=='overhang-ground')
|
||||
|
||||
@@ -295,3 +295,73 @@ def test_only_bound_native_abort_retires_the_local_option(reverse, mismatch):
|
||||
if mismatch is None:
|
||||
assert r.tick(position, now+.1, choose)[0] is None
|
||||
assert r.excluded == [selected['goal']]
|
||||
|
||||
|
||||
@pytest.mark.parametrize("reverse", [False, True])
|
||||
def test_native_action_finishes_its_own_distance_before_returning_to_route(reverse):
|
||||
r = ObservedRecovery()
|
||||
r.begin(pose(), 0, [])
|
||||
sign = -1 if reverse else 1
|
||||
selected = dict(goal=[sign*.7, 0., 0.], reverse=reverse)
|
||||
choose = lambda *_: selected
|
||||
now = survey(r, pose(), choose)
|
||||
receipt = completed_path(pose(), now, selected['goal'])
|
||||
receipt.update(status='path', speed_mps=sign*.1,
|
||||
controller_goal=['backup' if reverse else 'path', selected['goal'][:2], .1])
|
||||
receipt.pop('action_result')
|
||||
r.observe_navigation(receipt, pose(), now, (r.sequence, r.option), 'run')
|
||||
position = pose(sign*.45)
|
||||
r.observe_view(r.view_request(position, now+1), position, now+1)
|
||||
assert r.tick(position, now+1, choose) == (
|
||||
selected['goal'], 'reversing' if reverse else 'manoeuvring')
|
||||
assert r.active and r.completion is None
|
||||
# A completed native action stops intent even slightly past its goal.
|
||||
position = pose(sign*.71)
|
||||
receipt = completed_path(position, now+2, selected['goal'])
|
||||
receipt['action_result']['kind'] = 'backup' if reverse else 'path'
|
||||
r.observe_navigation(receipt, position, now+2, (r.sequence, r.option), 'run')
|
||||
assert r.tick(position, now+2, choose) == (None, 'replanning')
|
||||
assert not r.active
|
||||
|
||||
|
||||
@pytest.mark.parametrize('mismatch', ['run', 'time', 'pose', 'option', 'goal', 'kind'])
|
||||
def test_unbound_owner_cannot_suppress_legacy_completion(mismatch):
|
||||
r = ObservedRecovery()
|
||||
r.begin(pose(), 0, [])
|
||||
selected = dict(goal=[-.7, 0., 0.], reverse=True)
|
||||
choose = lambda *_: selected
|
||||
now = survey(r, pose(), choose)
|
||||
receipt = completed_path(pose(), now, selected['goal'])
|
||||
receipt.update(status='path', speed_mps=-.1,
|
||||
controller_goal=['backup', [-.7, 0.], .1])
|
||||
receipt.pop('action_result')
|
||||
position, key, run = pose(), (r.sequence, r.option), 'run'
|
||||
if mismatch == 'run': run = 'other'
|
||||
elif mismatch == 'time': now += .1
|
||||
elif mismatch == 'pose': position = pose(.1)
|
||||
elif mismatch == 'option': key = (r.sequence, r.option+1)
|
||||
elif mismatch == 'goal': receipt['controller_goal'][1] = [-1., 0.]
|
||||
elif mismatch == 'kind': receipt['controller_goal'][0] = 'spin'
|
||||
r.observe_navigation(receipt, position, now, key, run)
|
||||
assert r.native_action is None
|
||||
assert r.tick(pose(-.45), now+1, choose) == (None, 'replanning')
|
||||
|
||||
|
||||
def test_native_owner_does_not_bypass_unknown_view_or_progress_budget():
|
||||
r = ObservedRecovery()
|
||||
r.begin(pose(), 0, [])
|
||||
selected = dict(goal=[-.7, 0., 0.], reverse=True)
|
||||
choose = lambda *_: selected
|
||||
now = survey(r, pose(), choose)
|
||||
receipt = completed_path(pose(), now, selected['goal'])
|
||||
receipt.update(status='path', speed_mps=-.1,
|
||||
controller_goal=['backup', [-.7, 0.], .1])
|
||||
receipt.pop('action_result')
|
||||
r.observe_navigation(receipt, pose(), now, (r.sequence, r.option), 'run')
|
||||
# Close enough for the former distance threshold, but no current rear view.
|
||||
assert r.tick(pose(-.45), now+3, choose) == (None, 'surveying')
|
||||
assert r.active
|
||||
assert r.tick(pose(-.45), now+12, choose) == (None, 'surveying')
|
||||
assert r.excluded == [selected['goal']]
|
||||
r.tick(pose(-.45), now+12.1, choose)
|
||||
assert r.native_action is None
|
||||
|
||||
Reference in New Issue
Block a user