Compare commits
2
Commits
d8c79a1134
...
3735f21fc2
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3735f21fc2 | ||
|
|
5a68240511 |
@@ -28,6 +28,7 @@ class ObservedGoals:
|
|||||||
self.evidence = None
|
self.evidence = None
|
||||||
self.clearance_observation = None
|
self.clearance_observation = None
|
||||||
self.clearance_index = None
|
self.clearance_index = None
|
||||||
|
self.continuation_anchor = None
|
||||||
|
|
||||||
def observe(self, samples, captured_at, pose, *, frame_id=None, capture_id=None):
|
def observe(self, samples, captured_at, pose, *, frame_id=None, capture_id=None):
|
||||||
if frame_id is not None and frame_id in self.seen_semantics:
|
if frame_id is not None and frame_id in self.seen_semantics:
|
||||||
@@ -407,7 +408,17 @@ class ObservedGoals:
|
|||||||
advance = min(3., remaining)-along
|
advance = min(3., remaining)-along
|
||||||
if (along > 0 and advance >= float(self.surface.cell_size[0])
|
if (along > 0 and advance >= float(self.surface.cell_size[0])
|
||||||
and all(math.dist(before[:2], failed[:2]) > 0.6 for failed in excluded)):
|
and all(math.dist(before[:2], failed[:2]) > 0.6 for failed in excluded)):
|
||||||
query = before[:2]+advance*continuation
|
# A range sample is a noisy representative of the chosen
|
||||||
|
# passage, not the origin of its next lateral coordinate.
|
||||||
|
# Reusing each snapped point accumulates sampling error
|
||||||
|
# into metres of drift along an otherwise straight aisle.
|
||||||
|
anchor = before[:2]
|
||||||
|
saved = self.continuation_anchor
|
||||||
|
if (saved is not None and np.array_equal(saved[2], before)
|
||||||
|
and np.allclose(saved[1], continuation, rtol=0, atol=1e-9)):
|
||||||
|
anchor = saved[0]
|
||||||
|
query = anchor + (float((pose[:2]-anchor) @ continuation)
|
||||||
|
+ min(3., remaining))*continuation
|
||||||
nearby = np.linalg.norm(candidates[:, :2]-query, axis=1)
|
nearby = np.linalg.norm(candidates[:, :2]-query, axis=1)
|
||||||
for index in np.argsort(nearby, kind="stable"):
|
for index in np.argsort(nearby, kind="stable"):
|
||||||
if nearby[index] > .15:
|
if nearby[index] > .15:
|
||||||
@@ -420,6 +431,7 @@ class ObservedGoals:
|
|||||||
continue
|
continue
|
||||||
self.evidence['approach_clearance_m'] = (
|
self.evidence['approach_clearance_m'] = (
|
||||||
float(clearance) if math.isfinite(clearance) else None)
|
float(clearance) if math.isfinite(clearance) else None)
|
||||||
|
self.continuation_anchor = (anchor.copy(), continuation.copy(), selected.copy())
|
||||||
return selected.tolist()
|
return selected.tolist()
|
||||||
if (0.8 < math.dist(before[:2], pose[:2]) <= 3.5
|
if (0.8 < math.dist(before[:2], pose[:2]) <= 3.5
|
||||||
and math.dist(before[:2], target) < remaining - 0.1
|
and math.dist(before[:2], target) < remaining - 0.1
|
||||||
@@ -442,6 +454,9 @@ class ObservedGoals:
|
|||||||
observed = self.clearance_observation
|
observed = self.clearance_observation
|
||||||
obstacles = (observed[1] if observed is not None and 0 <= now-observed[0] <= .8
|
obstacles = (observed[1] if observed is not None and 0 <= now-observed[0] <= .8
|
||||||
else np.empty((0, 2)))
|
else np.empty((0, 2)))
|
||||||
|
# A blocked/replaced passage releases its old lateral reference. This
|
||||||
|
# memory never overrides current measured support or obstacle checks.
|
||||||
|
self.continuation_anchor = None
|
||||||
# New and retained goals share one measured world-space representation.
|
# New and retained goals share one measured world-space representation.
|
||||||
for passages in passage_centres(passage_points, pose, target, geometry, obstacles,
|
for passages in passage_centres(passage_points, pose, target, geometry, obstacles,
|
||||||
travel_direction=travel_direction):
|
travel_direction=travel_direction):
|
||||||
|
|||||||
@@ -38,8 +38,17 @@ class SupportSurface:
|
|||||||
if not ground.any():
|
if not ground.any():
|
||||||
return points[ground]
|
return points[ground]
|
||||||
# Match the observed range voxel resolution; no scene-dependent scale.
|
# Match the observed range voxel resolution; no scene-dependent scale.
|
||||||
_, inverse = np.unique(np.floor(points[:, :2] / .06).astype(int),
|
columns = np.floor(points[:, :2] / .06).astype(np.int64)
|
||||||
axis=0, return_inverse=True)
|
# A bounded sensor cloud can group XY columns with a scalar integer
|
||||||
|
# key. This preserves exact column membership without NumPy's costly
|
||||||
|
# structured-row sort on every control tick. Fall back for wide inputs.
|
||||||
|
extent = [int(columns[:, i].max())-int(columns[:, i].min())+1 for i in (0, 1)]
|
||||||
|
if extent[0] * extent[1] <= np.iinfo(np.int64).max:
|
||||||
|
relative = columns - columns.min(axis=0)
|
||||||
|
keys = relative[:, 0] * extent[1] + relative[:, 1]
|
||||||
|
_, inverse = np.unique(keys, return_inverse=True)
|
||||||
|
else:
|
||||||
|
_, inverse = np.unique(columns, axis=0, return_inverse=True)
|
||||||
lowest = np.full(int(inverse.max()) + 1, np.inf)
|
lowest = np.full(int(inverse.max()) + 1, np.inf)
|
||||||
np.minimum.at(lowest, inverse[ground], points[ground, 2])
|
np.minimum.at(lowest, inverse[ground], points[ground, 2])
|
||||||
obstacle_top = np.full(len(lowest), -np.inf)
|
obstacle_top = np.full(len(lowest), -np.inf)
|
||||||
@@ -94,27 +103,37 @@ class SupportSurface:
|
|||||||
height discontinuity retains the raw veto. Unknown ground is unchanged.
|
height discontinuity retains the raw veto. Unknown ground is unchanged.
|
||||||
"""
|
"""
|
||||||
offsets = np.asarray(offsets, dtype=float).reshape(-1, 2)
|
offsets = np.asarray(offsets, dtype=float).reshape(-1, 2)
|
||||||
states, reasons = self.classify(offsets)
|
states, raw_reasons = self._classify_details(offsets)
|
||||||
states, reasons = states.astype(object), Counter(reasons)
|
states, reasons = states.astype(object), Counter(raw_reasons)
|
||||||
spacing, radius = .05, .15
|
spacing, radius = .05, .15
|
||||||
delta = np.array([[x*spacing, y*spacing] for x in range(-3,4)
|
delta = np.array([[x*spacing, y*spacing] for x in range(-3,4)
|
||||||
for y in range(-3,4) if x*x+y*y<=9])
|
for y in range(-3,4) if x*x+y*y<=9])
|
||||||
critical = math.floor(2*radius*(contact_width_m/3)/spacing**2)
|
critical = math.floor(2*radius*(contact_width_m/3)/spacing**2)
|
||||||
for i in np.flatnonzero(states == 'observed-unsafe'):
|
candidates = np.flatnonzero((states == 'observed-unsafe')
|
||||||
point = offsets[i]
|
& np.isin(raw_reasons, ['slope', 'roughness']))
|
||||||
_, raw = self.classify([point])
|
keys = {i: (tuple(np.round(offsets[i], 12)), float(contact_width_m))
|
||||||
reason = next(iter(raw))
|
for i in candidates}
|
||||||
if reason not in {'slope', 'roughness'}:
|
pending = {}
|
||||||
continue
|
for i, key in keys.items():
|
||||||
key = (tuple(np.round(point,12)), float(contact_width_m))
|
|
||||||
if key not in self.contact_results:
|
if key not in self.contact_results:
|
||||||
_, surrounding = self.classify(point+delta)
|
pending.setdefault(key, offsets[i])
|
||||||
forbidden = set(surrounding)-{'observed-patch','slope','roughness'}
|
items = list(pending.items())
|
||||||
count = surrounding.get('slope',0)+surrounding.get('roughness',0)
|
# Classify each identical 29-point disk in bounded batches. Re-entering
|
||||||
self.contact_results[key] = not forbidden and count<=critical
|
# the native wrapper per cell scanned the full return cloud hundreds
|
||||||
|
# of times; batching changes neither samples nor the relief rule.
|
||||||
|
for start in range(0, len(items), 64):
|
||||||
|
batch = items[start:start+64]
|
||||||
|
queries = np.array([point for _, point in batch])[:, None, :] + delta
|
||||||
|
_, surrounding = self._classify_details(queries.reshape(-1, 2))
|
||||||
|
surrounding = surrounding.reshape(len(batch), len(delta))
|
||||||
|
permitted = np.isin(surrounding, ['observed-patch', 'slope', 'roughness'])
|
||||||
|
counts = np.isin(surrounding, ['slope', 'roughness']).sum(axis=1)
|
||||||
|
for (key, _), allowed in zip(batch, permitted.all(axis=1) & (counts <= critical), strict=True):
|
||||||
|
self.contact_results[key] = bool(allowed)
|
||||||
|
for i, key in keys.items():
|
||||||
if self.contact_results[key]:
|
if self.contact_results[key]:
|
||||||
states[i] = 'observed-supported'
|
states[i] = 'observed-supported'
|
||||||
reasons[reason] -= 1
|
reasons[raw_reasons[i]] -= 1
|
||||||
reasons['observed-local-relief'] += 1
|
reasons['observed-local-relief'] += 1
|
||||||
return states, {key:value for key,value in reasons.items() if value}
|
return states, {key:value for key,value in reasons.items() if value}
|
||||||
|
|
||||||
@@ -158,6 +177,10 @@ class SupportSurface:
|
|||||||
|
|
||||||
def classify(self, offsets):
|
def classify(self, offsets):
|
||||||
"""Return observed-supported, observed-unsafe or unknown per XY sample."""
|
"""Return observed-supported, observed-unsafe or unknown per XY sample."""
|
||||||
|
states, reasons = self._classify_details(offsets)
|
||||||
|
return states, dict(Counter(reasons))
|
||||||
|
|
||||||
|
def _classify_details(self, offsets):
|
||||||
offsets = np.asarray(offsets, dtype=float).reshape(-1, 2)
|
offsets = np.asarray(offsets, dtype=float).reshape(-1, 2)
|
||||||
if not np.isfinite(offsets).all():
|
if not np.isfinite(offsets).all():
|
||||||
raise ValueError("Invalid support samples")
|
raise ValueError("Invalid support samples")
|
||||||
@@ -165,7 +188,7 @@ class SupportSurface:
|
|||||||
states, reasons, raised = self.native.classify(offsets)
|
states, reasons, raised = self.native.classify(offsets)
|
||||||
for point in raised + self.pose[:3]:
|
for point in raised + self.pose[:3]:
|
||||||
self.raised_obstacles[tuple(np.round(point, 6))] = point.tolist()
|
self.raised_obstacles[tuple(np.round(point, 6))] = point.tolist()
|
||||||
return states, dict(Counter(reasons))
|
return states, reasons
|
||||||
keys = [tuple(point) for point in np.round(offsets, 12)]
|
keys = [tuple(point) for point in np.round(offsets, 12)]
|
||||||
pending = {}
|
pending = {}
|
||||||
for point, sample_key in zip(offsets, keys):
|
for point, sample_key in zip(offsets, keys):
|
||||||
@@ -200,7 +223,7 @@ class SupportSurface:
|
|||||||
for item, state, reason in zip(batch, states, reasons))
|
for item, state, reason in zip(batch, states, reasons))
|
||||||
values = [self.results[key] for key in keys]
|
values = [self.results[key] for key in keys]
|
||||||
return (np.array([v[0] for v in values], dtype=str),
|
return (np.array([v[0] for v in values], dtype=str),
|
||||||
dict(Counter(v[1] for v in values)))
|
np.array([v[1] for v in values], dtype=str))
|
||||||
|
|
||||||
def hazard_samples(self, unsafe_offsets):
|
def hazard_samples(self, unsafe_offsets):
|
||||||
"""Bind rejected surface samples to real returns for path-search costs.
|
"""Bind rejected surface samples to real returns for path-search costs.
|
||||||
|
|||||||
@@ -654,3 +654,33 @@ def test_through_passage_requires_measured_permission_and_current_clearance(sele
|
|||||||
moved=[2.7,0.,.37,0.,0.,0.,1.]
|
moved=[2.7,0.,.37,0.,0.,0.,1.]
|
||||||
end=selector.choose(points,moved,[8.,0.],chosen,(),GEOMETRY,1.3,travel_direction=[1.,0.])
|
end=selector.choose(points,moved,[8.,0.],chosen,(),GEOMETRY,1.3,travel_direction=[1.,0.])
|
||||||
assert end is None or end[0]<=points[:,0].max()
|
assert end is None or end[0]<=points[:,0].max()
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize('angle,side,shift', [(0,1,(0,0)), (73,-1,(42,-17)), (-138,1,(-250,52))])
|
||||||
|
def test_range_sampling_error_does_not_accumulate_into_lateral_drift(selector, angle, side, shift):
|
||||||
|
_, pose, _, _, rotation = road(angle, shift)
|
||||||
|
# Diagonally phased scan rows: successive nearest samples are offset by
|
||||||
|
# 11 mm. Recursively extending each snapped point drifts >1 m in 19 m.
|
||||||
|
xy = np.array([[x, side*(y+.055*x)] for x in np.arange(-1.,25.01,.2)
|
||||||
|
for y in np.arange(-4.,4.01,.13)])
|
||||||
|
points = np.c_[xy@rotation.T+shift, np.zeros(len(xy))]
|
||||||
|
geometry = {**GEOMETRY, 'length_m':1.36, 'max_step_m':.1}
|
||||||
|
selector.observe(np.c_[points, np.ones(len(points))], 1., pose)
|
||||||
|
goal = [*(np.asarray(shift)+rotation@[3.,0.]),0.]
|
||||||
|
lateral = []
|
||||||
|
for along in np.arange(1.,20.01,.2):
|
||||||
|
position = np.asarray(shift)+rotation@[along,0.]
|
||||||
|
moved = [*position, *pose[2:]]
|
||||||
|
goal = selector.choose(points, moved, position+rotation@[6.,0.], goal,
|
||||||
|
(), geometry, 2., travel_direction=rotation@[1.,0.])
|
||||||
|
assert goal is not None
|
||||||
|
assert selector.evidence['source'] in {'continuing-observed-passage', 'retained-observed-passage'}
|
||||||
|
assert np.min(np.linalg.norm(points-goal,axis=1)) < 1e-9
|
||||||
|
lateral.append(((np.asarray(goal[:2])-shift)@rotation)[1])
|
||||||
|
assert max(np.abs(lateral)) < .13
|
||||||
|
# A new measured obstacle revokes the axis before a physical encounter.
|
||||||
|
obstacle = position+rotation@[1.5,0.]
|
||||||
|
selector.observe_navigation(clearance_receipt(moved,[obstacle]),moved,1,'run',2.)
|
||||||
|
replacement = selector.choose(points, moved, position+rotation@[6.,0.],goal,
|
||||||
|
(), geometry,2.1,travel_direction=rotation@[1.,0.])
|
||||||
|
assert replacement is None or abs(((np.asarray(replacement[:2])-shift)@rotation)[1])>.3
|
||||||
|
|||||||
@@ -115,3 +115,47 @@ def test_support_guard_reduces_same_arc_or_stops_before_unknown(monitor):
|
|||||||
assert (v, w, scale) == (0, 0, 0) and not support["admitted"]
|
assert (v, w, scale) == (0, 0, 0) and not support["admitted"]
|
||||||
blocked = np.vstack((ground(), [[0, 0, 0.3, 0.3]]))
|
blocked = np.vstack((ground(), [[0, 0, 0.3, 0.3]]))
|
||||||
assert monitor.regulate_supported_command(0.2, 0, blocked, POSE, 0.37)[:3] == (0, 0, 0)
|
assert monitor.regulate_supported_command(0.2, 0, blocked, POSE, 0.37)[:3] == (0, 0, 0)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize("translation", [(0., 0.), (-125., 48.), (1e9, -1e9)])
|
||||||
|
def test_ground_columns_keep_relief_and_only_remove_measured_wall_layer(monitor, translation):
|
||||||
|
from navigation.support_surface import SupportSurface
|
||||||
|
# Separate columns, including negative coordinates, must not alias. Raised
|
||||||
|
# returns only suppress higher low-cost samples in their own XY column.
|
||||||
|
points = np.array([
|
||||||
|
[-.10, -.10, 0., 0.], [-.10, -.10, .04, 0.],
|
||||||
|
[-.10, -.10, .09, 0.], [-.10, -.10, .8, 1.],
|
||||||
|
[-.10, .10, .09, 0.], [.10, -.10, .09, 0.],
|
||||||
|
[.10, .10, -.4, 0.], [.10, .10, -.32, 0.],
|
||||||
|
[.10, .10, -.1, 1.],
|
||||||
|
])
|
||||||
|
points[:, :2] += translation
|
||||||
|
assert np.array_equal(SupportSurface.ground_layer(points, .1), points[[0, 1, 4, 5, 6], :3])
|
||||||
|
|
||||||
|
|
||||||
|
def test_contact_batch_does_not_mix_neighbouring_relief_or_missing_support(monitor):
|
||||||
|
from collections import Counter
|
||||||
|
from navigation.support_surface import SupportSurface
|
||||||
|
terrain = ground()
|
||||||
|
terrain[:, 2] = .065 * np.sin(terrain[:, 0] * 25) * np.cos(terrain[:, 1] * 20)
|
||||||
|
terrain[terrain[:, 0] > .9, 2] -= .4
|
||||||
|
terrain = terrain[~((terrain[:, 0] < -.9) & (terrain[:, 1] > .4))]
|
||||||
|
samples = np.array([[x, y] for x in np.arange(-1.4, 1.41, .14)
|
||||||
|
for y in np.arange(-1.4, 1.41, .14)])
|
||||||
|
def surface():
|
||||||
|
return SupportSurface(terrain, POSE, .37, .1, math.tan(math.radians(25)))
|
||||||
|
batched, individual = surface(), surface()
|
||||||
|
states, reasons = batched.classify_contacts(samples, .22)
|
||||||
|
expected_states, expected_reasons = [], Counter()
|
||||||
|
for sample in samples:
|
||||||
|
single_states, single_reasons = individual.classify_contacts([sample], .22)
|
||||||
|
expected_states.extend(single_states)
|
||||||
|
expected_reasons.update(single_reasons)
|
||||||
|
assert np.array_equal(states, expected_states)
|
||||||
|
assert reasons == dict(expected_reasons)
|
||||||
|
assert "unknown" in states and "observed-unsafe" in states
|
||||||
|
# Cache hits and repeated query ordering do not share another cell's veto.
|
||||||
|
order = np.r_[np.arange(len(samples)-1, -1, -1), np.arange(12)]
|
||||||
|
repeated, counts = batched.classify_contacts(samples[order], .22)
|
||||||
|
assert np.array_equal(repeated, states[order])
|
||||||
|
assert sum(counts.values()) == len(order)
|
||||||
|
|||||||
Reference in New Issue
Block a user