Preserve admitted command ownership across route path refinements
This commit is contained in:
@@ -31,6 +31,9 @@ def bridge(monkeypatch):
|
||||
navigation.failure = None
|
||||
navigation.active = navigation.activating = True
|
||||
navigation.action_key = navigation.attempted_alignment = None
|
||||
navigation.command_generation = 0
|
||||
navigation.path_context = None
|
||||
navigation.owner_lock = threading.Lock()
|
||||
navigation.inputs = dict(sha256='a'*64, behavior={'max_speed_mps': 1.},
|
||||
mission={'arrival_radius_m': .4})
|
||||
navigation.monitor = Footprint(dict(length_m=1., width_m=.6, max_step_m=.1, max_slope_degrees=25.))
|
||||
@@ -134,3 +137,85 @@ def test_goal_clearance_uses_solids_without_waiving_search_or_surface_costs(brid
|
||||
assert result['clearance_observation']['obstacles_xy'] == ([[.8, .2]] if layer == 'physical' else [])
|
||||
assert seen[0][-1, 3] == 1. # Smac keeps the complete search exclusion.
|
||||
assert observed['terrain'][-1, 3] == (0. if layer == 'search' else 1.)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def moving_bridge(bridge):
|
||||
navigation, observed, value = bridge
|
||||
orientation = dict(key='route-0-1', xy=[20., 0.])
|
||||
value = {**value, 'translation_allowed': True, 'continuous': True,
|
||||
'orientation_target': orientation, 'recovery_orientation': False,
|
||||
'goal': [4., .2, 0.]}
|
||||
navigation.command_generation = 7
|
||||
navigation.action_key = ('path', (3., 0.), 1.)
|
||||
navigation.path_context = navigation.forward_context(value, orientation)
|
||||
navigation.path = None
|
||||
navigation.path_planned_at = float('-inf')
|
||||
navigation.completed_orientation = None
|
||||
navigation.node.terminal = Future()
|
||||
navigation.node.native_command = lambda: (time.monotonic(), .4, .02)
|
||||
navigation.node.observe_pose = lambda *args: None
|
||||
planned = []
|
||||
def plan(pose, goal, yaw):
|
||||
planned.append(list(goal))
|
||||
return SimpleNamespace(poses=[SimpleNamespace(pose=SimpleNamespace(
|
||||
position=SimpleNamespace(x=x, y=y))) for x, y in [(0., 0.), goal[:2]]]), 4
|
||||
navigation.node.plan = plan
|
||||
navigation.control.lock = threading.Lock()
|
||||
navigation.control.path_id = 'old'
|
||||
navigation.control.plans = {'old': dict(result={'controller_generation': 7})}
|
||||
navigation.control.accept = lambda *args, **kwargs: None
|
||||
seen = []
|
||||
navigation.node.follow = lambda path, **kwargs: seen.append(
|
||||
dict(continuing=kwargs['continuing'], command=navigation.native_command()))
|
||||
observed['metrics'] = {}
|
||||
globals_ = navigation._plan.__globals__
|
||||
globals_.update(validate_orientation=lambda x: x, yaw_of=lambda _: 0.,
|
||||
GoalStatus=SimpleNamespace(STATUS_SUCCEEDED=4, STATUS_ABORTED=6))
|
||||
return navigation, value, planned, seen
|
||||
|
||||
|
||||
def test_refined_endpoint_keeps_same_route_command_owner_during_actual_plan(moving_bridge):
|
||||
navigation, value, planned, seen = moving_bridge
|
||||
# A control tick straddles the goal update, while the old observed plan is
|
||||
# still held by its caller. It must retain its original live admission.
|
||||
def tick(_):
|
||||
result = navigation.plan(value)
|
||||
assert result['controller_goal'] == ('path', (4., .2), 1.)
|
||||
assert result['controller_generation'] == 7
|
||||
return dict(speed_mps=.4, yaw_rate_rps=.02, reason='none')
|
||||
navigation.control.tick = tick
|
||||
result = navigation.tick(dict(pose=value['pose'], pose_age_seconds=0., measured_twist=[.4,0.,0.]))
|
||||
assert result == dict(speed_mps=.4, yaw_rate_rps=.02, reason='none')
|
||||
assert planned == [[4., .2, 0.]] # A different goal gets a new native path.
|
||||
assert seen[0]['continuing'] is True and seen[0]['command'] is not None
|
||||
|
||||
|
||||
@pytest.mark.parametrize('change', ['leg', 'direction', 'limit', 'recovery', 'unbound', 'placement', 'discrete'])
|
||||
def test_task_change_revokes_previous_plan_even_when_followpath_is_live(moving_bridge, change):
|
||||
navigation, value, _, seen = moving_bridge
|
||||
if change == 'leg': value['orientation_target'] = dict(key='route-0-2', xy=[20., 0.])
|
||||
elif change == 'direction': value['orientation_target'] = dict(key='route-0-1', xy=[20., 4.])
|
||||
elif change == 'limit': value['max_speed_mps'] = .3
|
||||
elif change == 'recovery': value['recovery_orientation'] = True
|
||||
elif change == 'unbound': value['orientation_target'] = None
|
||||
elif change == 'placement': value['arrival_target'] = [20., 0.]
|
||||
else: value['continuous'] = False
|
||||
result = navigation.plan(value)
|
||||
assert result['controller_generation'] == 8
|
||||
assert seen == [dict(continuing=False, command=None)]
|
||||
assert navigation.native_command() is None # Old capture cannot own the new task.
|
||||
|
||||
|
||||
def test_planner_rejection_revokes_inflight_command_before_native_stop(moving_bridge):
|
||||
navigation, value, _, _ = moving_bridge
|
||||
navigation.node.plan = lambda *args: (None, 6)
|
||||
seen = []
|
||||
navigation.node.stop = lambda: seen.append(navigation.native_command())
|
||||
def tick(_):
|
||||
assert navigation.plan(value)['diagnostic']['failure'] == 'no-path'
|
||||
return dict(speed_mps=.4, yaw_rate_rps=.02, reason='none')
|
||||
navigation.control.tick = tick
|
||||
result = navigation.tick(dict(pose=value['pose'], pose_age_seconds=0., measured_twist=[.4,0.,0.]))
|
||||
assert result == dict(speed_mps=0., yaw_rate_rps=0., reason='changed-path')
|
||||
assert seen == [None]
|
||||
|
||||
Reference in New Issue
Block a user