Bound corridor ranking work and retire aborted local actions
This commit is contained in:
@@ -81,18 +81,30 @@ class ObservedGoals:
|
||||
delta = candidates[:, :2]-xy
|
||||
length = np.linalg.norm(delta, axis=1)
|
||||
direction = delta / np.maximum(length[:, None], 1e-9)
|
||||
inverse = angular_error = None
|
||||
if lookahead_m is not None:
|
||||
# Compare bearings over one common horizon. A short destination
|
||||
# before an obstacle must not hide that obstacle from intent cost.
|
||||
# This extends a scoring query, never the measured drive goal.
|
||||
length = np.full(len(candidates), lookahead_m)
|
||||
# Dense range samples often describe almost the same bearing.
|
||||
# Share radial queries in quarter-degree bins; subtract the exact
|
||||
# maximum displacement caused by that rotation from each result.
|
||||
# This is still a lower bound, with <= 4.1 cm total error at 3.5 m.
|
||||
bearing = np.arctan2(direction[:, 1], direction[:, 0])
|
||||
bins = np.rint(bearing/math.radians(.25)).astype(int)
|
||||
unique, inverse = np.unique(bins, return_inverse=True)
|
||||
quantized = unique*math.radians(.25)
|
||||
angular_error = 2*lookahead_m*np.abs(np.sin((bearing-quantized[inverse])/2))
|
||||
direction = np.column_stack((np.cos(quantized), np.sin(quantized)))
|
||||
length = np.full(len(unique), lookahead_m)
|
||||
distances = np.full(len(unique), np.inf)
|
||||
start = np.minimum(length, geometry.get("length_m", geometry["width_m"])/2)
|
||||
# Nearest-obstacle distance is 1-Lipschitz. Sampling at <= 5 cm and
|
||||
# subtracting half the actual spacing gives a conservative continuous
|
||||
# segment lower bound (error <= 2.5 cm), without an N*M hazard matrix.
|
||||
# This is a soft ranking cost only, never a swept-body safety receipt.
|
||||
for first in range(0, len(candidates), 128):
|
||||
last = min(first+128, len(candidates))
|
||||
for first in range(0, len(length), 128):
|
||||
last = min(first+128, len(length))
|
||||
steps = np.maximum(1, np.ceil((length[first:last]-start[first:last])/.05).astype(int))
|
||||
spacing = (length[first:last]-start[first:last])/steps
|
||||
along = (start[first:last, None]
|
||||
@@ -101,6 +113,8 @@ class ObservedGoals:
|
||||
queries = xy + along[:, :, None]*direction[first:last, None]
|
||||
nearest = tree.query(queries.reshape(-1, 2), workers=1)[0].reshape(along.shape)
|
||||
distances[first:last] = np.maximum(0., nearest.min(axis=1)-spacing/2)
|
||||
if inverse is not None:
|
||||
return np.maximum(0., distances[inverse]-angular_error)
|
||||
return distances
|
||||
|
||||
def clearance_cost(self, candidates, pose, geometry, now, *, lookahead_m=None):
|
||||
@@ -128,13 +142,34 @@ class ObservedGoals:
|
||||
barriers = barriers[np.all((barriers[:,:2]>=low)&(barriers[:,:2]<=high),axis=1)]
|
||||
if not len(barriers):
|
||||
return cost
|
||||
for start in range(0,len(candidates),128):
|
||||
batch = candidates[start:start+128]
|
||||
distance = np.linalg.norm(batch[:,None,:2]-barriers[None,:,:2],axis=2)
|
||||
dz = barriers[None,:,2]-batch[:,None,2]
|
||||
relevant = (dz>=-geometry.get('max_step_m', .1)) & (dz<=geometry.get('height_m',width))
|
||||
nearest = np.min(np.where(relevant,distance,np.inf),axis=1)
|
||||
cost[start:start+len(batch)] = 2*width*np.exp(-nearest/width)
|
||||
# Query nearest XY neighbours until one also lies in the candidate's
|
||||
# exact height interval. Usually the first return qualifies. Unlike a
|
||||
# dense candidate-by-barrier matrix this does no work for distant
|
||||
# obstacles once a nearer relevant boundary has been found.
|
||||
tree = cKDTree(barriers[:, :2])
|
||||
heights = np.sort(barriers[:, 2])
|
||||
lower = candidates[:, 2]-geometry.get('max_step_m', .1)
|
||||
upper = candidates[:, 2]+geometry.get('height_m', width)
|
||||
has_relevant = (np.searchsorted(heights, np.nextafter(upper, np.inf), side='right')
|
||||
> np.searchsorted(heights, np.nextafter(lower, -np.inf), side='left'))
|
||||
for start in range(0, len(candidates), 128):
|
||||
pending = np.arange(start, min(start+128, len(candidates)))
|
||||
pending = pending[has_relevant[pending]]
|
||||
count = 1
|
||||
while len(pending):
|
||||
distance, indices = tree.query(candidates[pending, :2], k=count, workers=1)
|
||||
distance = np.asarray(distance).reshape(len(pending), count)
|
||||
indices = np.asarray(indices).reshape(len(pending), count)
|
||||
dz = barriers[indices, 2]-candidates[pending, None, 2]
|
||||
relevant = ((dz >= -geometry.get('max_step_m', .1))
|
||||
& (dz <= geometry.get('height_m', width)))
|
||||
nearest = np.min(np.where(relevant, distance, np.inf), axis=1)
|
||||
found = np.isfinite(nearest)
|
||||
cost[pending[found]] = 2*width*np.exp(-nearest[found]/width)
|
||||
pending = pending[~found]
|
||||
if count == len(barriers):
|
||||
break
|
||||
count = min(2*count, len(barriers))
|
||||
return cost
|
||||
|
||||
def maneuver(self, points, pose, target, prior, excluded, geometry, now, candidate_mask=None):
|
||||
|
||||
Reference in New Issue
Block a user