Keep local navigation on its path across goal refinements
This commit is contained in:
@@ -143,9 +143,12 @@ class Navigation:
|
||||
detected=observed['detected']):
|
||||
return self.reply('stale-range')
|
||||
route = route_observation(terrain, pose, value, self.monitor.max_step)
|
||||
# Return the same observed search obstacles used by Smac, as bounded
|
||||
# intent guidance only. Goal selection must see unlabelled solids too.
|
||||
hazards = observed['search_terrain']
|
||||
# Centre between observed solids, including unlabelled ones. Search
|
||||
# hints for rejected contact patches are not objects: assigning their
|
||||
# nearest return an obstacle radius moves the local endpoint across a
|
||||
# clear passage as patch queries change. Smac still receives the full
|
||||
# search layer; semantic/contact gates still admit every actual sweep.
|
||||
hazards = observed['collision_terrain']
|
||||
hazards = hazards[hazards[:, 3] > self.monitor.max_step + 1e-4, :2]
|
||||
if len(hazards):
|
||||
_, indices = np.unique(np.floor(hazards / .05), axis=0, return_index=True)
|
||||
@@ -188,8 +191,16 @@ class Navigation:
|
||||
aligning = (not reverse and value['translation_allowed']
|
||||
and self.action_key == alignment_key and self.node.terminal is not None
|
||||
and not self.node.terminal.done())
|
||||
# A changing local endpoint is still a FollowPath task. Let Smac/DWB
|
||||
# choose its curve; facing the endpoint directly is not a prerequisite
|
||||
# for following that curve. Preempting a live path with Spin on every
|
||||
# >30 degree bearing change creates stop/turn/advance oscillations.
|
||||
# A completed/aborted path and explicit mission recovery may still
|
||||
# select a fully observed in-place turn before starting translation.
|
||||
following = (self.action_key is not None and self.action_key[0] == 'path'
|
||||
and self.node.terminal is not None and not self.node.terminal.done())
|
||||
turn = None
|
||||
if (not reverse and value['translation_allowed'] and not aligning
|
||||
if (not reverse and value['translation_allowed'] and not aligning and not following
|
||||
and alignment_key != self.attempted_alignment):
|
||||
turn = alignment_angle(pose, goal, terrain, observed['detected'], self.monitor,
|
||||
value['body_contact_height_m'],
|
||||
|
||||
@@ -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