Keep local navigation on its path across goal refinements
This commit is contained in:
@@ -5,6 +5,8 @@ import math
|
||||
from pathlib import Path
|
||||
from types import SimpleNamespace
|
||||
import time
|
||||
import threading
|
||||
from concurrent.futures import Future
|
||||
|
||||
import numpy as np
|
||||
import pytest
|
||||
@@ -78,3 +80,57 @@ def test_route_support_rejects_remote_or_wrongly_bound_target(bridge):
|
||||
for change in ({'route_transition_target': [4., 0.]}, {'execution_inputs_sha256': 'b'*64}):
|
||||
with pytest.raises(ValueError, match='transition observation'):
|
||||
navigation.plan({**value, **change})
|
||||
|
||||
|
||||
@pytest.mark.parametrize('terminal_status', [None, 4, 6])
|
||||
def test_endpoint_change_keeps_live_path_but_terminal_path_can_align(bridge, terminal_status):
|
||||
navigation, observed, value = bridge
|
||||
future = Future()
|
||||
if terminal_status is not None:
|
||||
future.set_result(SimpleNamespace(status=terminal_status))
|
||||
navigation.owner_lock = threading.Lock()
|
||||
navigation.action_key = ('path', (3., 0.), 1.)
|
||||
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, .05)
|
||||
navigation.node.plan = lambda *args: (SimpleNamespace(poses=[
|
||||
SimpleNamespace(pose=SimpleNamespace(position=SimpleNamespace(x=x, y=y)))
|
||||
for x, y in [(0.,0.), (1.,.3), (2.,2.)]]), 4)
|
||||
calls = []
|
||||
navigation.node.follow = lambda *args, **kwargs: calls.append('follow')
|
||||
navigation.node.spin = lambda *args: calls.append('spin')
|
||||
navigation.control.accept = lambda *args, **kwargs: None
|
||||
observed['metrics'] = {}
|
||||
globals_ = navigation._plan.__globals__
|
||||
globals_['alignment_angle'] = lambda *args, **kwargs: math.pi/4
|
||||
globals_['yaw_of'] = lambda _: 0.
|
||||
globals_['GoalStatus'] = SimpleNamespace(STATUS_SUCCEEDED=4, STATUS_ABORTED=6)
|
||||
result = navigation.plan({**value, 'translation_allowed': True, 'goal': [2.,2.,0.]})
|
||||
if terminal_status is None:
|
||||
assert calls == ['follow']
|
||||
assert result['controller_goal'][0] == 'path'
|
||||
else:
|
||||
assert calls == ['spin']
|
||||
assert result['controller_goal'][0] == 'align'
|
||||
assert result['status'] == 'path'
|
||||
|
||||
|
||||
@pytest.mark.parametrize('layer', ['search', 'surface', 'physical'])
|
||||
def test_goal_clearance_uses_solids_without_waiving_search_or_surface_costs(bridge, layer):
|
||||
navigation, observed, value = bridge
|
||||
point = np.array([[.8, .2, .05, 0.]])
|
||||
for name in ('terrain', 'collision_terrain', 'search_terrain'):
|
||||
observed[name] = np.r_[observed[name], point]
|
||||
observed['search_terrain'][-1, 3] = 1.
|
||||
if layer in {'surface', 'physical'}:
|
||||
observed['terrain'][-1, 3] = 1.
|
||||
if layer == 'physical':
|
||||
observed['collision_terrain'][-1, 3] = 1.
|
||||
seen = []
|
||||
navigation.collision.publish = lambda *args, **kwargs: seen.append(kwargs['search_terrain'].copy()) or True
|
||||
result = navigation.plan(value)
|
||||
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.)
|
||||
|
||||
Reference in New Issue
Block a user