Look beyond short local goals and stabilize observed surface intent
This commit is contained in:
@@ -325,9 +325,9 @@ def test_clear_retained_intent_does_not_recompute_alternative_approaches(selecto
|
||||
selector.observe_navigation(clearance_receipt(position, [[1.6, 1.5]]), position, 1, 'run', 1.)
|
||||
evaluate = selector.approach_clearance
|
||||
sizes = []
|
||||
def measured(candidates, *args):
|
||||
def measured(candidates, *args, **kwargs):
|
||||
sizes.append(len(candidates))
|
||||
return evaluate(candidates, *args)
|
||||
return evaluate(candidates, *args, **kwargs)
|
||||
monkeypatch.setattr(selector, 'approach_clearance', measured)
|
||||
assert selector.choose(points, position, target, goal, (), GEOMETRY, 1.1) == goal
|
||||
assert sizes == [1]
|
||||
@@ -337,7 +337,7 @@ def test_clear_retained_intent_does_not_recompute_alternative_approaches(selecto
|
||||
assert max(sizes) > 1
|
||||
|
||||
|
||||
def test_clearance_matches_exact_continuous_segments(selector):
|
||||
def test_clearance_is_bounded_below_exact_continuous_segments(selector):
|
||||
rng = np.random.default_rng(122)
|
||||
position = [17., -31., .37, 0., 0., 0., 1.]
|
||||
candidates = np.c_[rng.uniform(-3., 3., (259, 2))+position[:2], np.zeros(259)]
|
||||
@@ -353,4 +353,60 @@ def test_clearance_matches_exact_continuous_segments(selector):
|
||||
b = goal[:2]
|
||||
projection = np.clip((obstacles-a) @ (b-a) / max(np.sum((b-a)**2), 1e-20), 0, 1)
|
||||
expected.append(np.min(np.linalg.norm(obstacles-(a+projection[:, None]*(b-a)), axis=1)))
|
||||
np.testing.assert_allclose(actual, expected, atol=1e-7, rtol=1e-7)
|
||||
assert np.all(actual <= np.asarray(expected)+1e-10)
|
||||
assert np.max(np.asarray(expected)-actual) <= .025+1e-10
|
||||
|
||||
|
||||
@pytest.mark.parametrize('yaw,shift', [(0, (0, 0)), (73, (42, -17)), (-138, (-250, 52))])
|
||||
def test_short_goal_cannot_hide_an_obstacle_beyond_its_endpoint(selector, yaw, shift):
|
||||
points, position, target, _, rotation = road(yaw, shift)
|
||||
selector.observe(np.c_[points, np.ones(len(points))], 1., position)
|
||||
short = np.array([*[1.36, -.06] @ rotation.T + shift, 0.])
|
||||
pole = np.array([[3., -.25]]) @ rotation.T + shift
|
||||
selector.observe_navigation(clearance_receipt(position, pole.tolist()), position, 1, 'run', 1.)
|
||||
# Its endpoint is far from the pole, but its continuing bearing is not.
|
||||
assert selector.approach_clearance(short[None], position, GEOMETRY, 1.1)[0] > 1.5
|
||||
assert selector.approach_clearance(short[None], position, GEOMETRY, 1.1,
|
||||
lookahead_m=3.5)[0] < .3
|
||||
goal = selector.choose(points, position, target, short, (), GEOMETRY, 1.1)
|
||||
assert ((np.array(goal[:2])-shift) @ rotation)[1] > .3
|
||||
assert np.min(np.linalg.norm(points-goal, axis=1)) < 1e-9
|
||||
|
||||
|
||||
def test_repeated_surface_evidence_survives_one_conflicting_frame_not_a_persistent_prohibition(selector):
|
||||
points, position, target, _, _ = road()
|
||||
geometry = {**GEOMETRY, 'length_m': 1.163, 'max_step_m': .1}
|
||||
for stamp in [1., 2., 3.]:
|
||||
selector.observe(np.c_[points, np.ones(len(points))], stamp, position)
|
||||
prior = selector.maneuver(points, position, target, None, (), geometry, 3.)
|
||||
forbidden = np.c_[points, np.zeros(len(points))]
|
||||
selector.observe(forbidden, 4., position)
|
||||
assert selector.maneuver(points, position, target, prior, (), geometry, 4.) == prior
|
||||
# Reusing the same neural frame on many range ticks is one vote only.
|
||||
for _ in range(5):
|
||||
selector.observe(forbidden, 4., position)
|
||||
assert selector.maneuver(points, position, target, prior, (), geometry, 4.5) == prior
|
||||
selector.observe(forbidden, 5., position)
|
||||
selector.observe(forbidden, 6., position)
|
||||
assert selector.maneuver(points, position, target, prior, (), geometry, 6.) is None
|
||||
fresh = type(selector)()
|
||||
fresh.observe(forbidden, 1., position)
|
||||
assert fresh.choose(points, position, target, None, (), geometry, 1.) is None
|
||||
|
||||
|
||||
def test_alternating_cached_views_do_not_multiply_semantic_votes(selector):
|
||||
points, position, target, _, _ = road()
|
||||
positive = np.c_[points, np.ones(len(points))]
|
||||
negative = np.c_[points, np.zeros(len(points))]
|
||||
selector.observe(positive, 1., position, frame_id='a:front', capture_id='a')
|
||||
selector.observe(positive, 2., position, frame_id='b:front', capture_id='b')
|
||||
selector.observe(negative, 3., position, frame_id='c:front', capture_id='c')
|
||||
selector.observe(negative, 3., position, frame_id='c:side', capture_id='c')
|
||||
assert selector.choose(points, position, target, None, (), GEOMETRY, 3.) is not None
|
||||
before = dict(selector.surface.cells)
|
||||
for _ in range(5):
|
||||
selector.observe(positive, 2., position, frame_id='b:front', capture_id='b')
|
||||
selector.observe(negative, 3., position, frame_id='c:front', capture_id='c')
|
||||
assert dict(selector.surface.cells) == before
|
||||
selector.observe(negative, 4., position, frame_id='d:front', capture_id='d')
|
||||
assert selector.choose(points, position, target, None, (), GEOMETRY, 4.) is None
|
||||
|
||||
Reference in New Issue
Block a user