Keep clearance refresh bounded and preserve rear recovery observation
This commit is contained in:
@@ -72,12 +72,16 @@ class ObservedGoals:
|
||||
if not len(obstacles):
|
||||
return distances
|
||||
offsets = obstacles-xy
|
||||
squared = np.sum(offsets*offsets, axis=1)
|
||||
for first in range(0, len(candidates), 128):
|
||||
last = min(first+128, len(candidates))
|
||||
along = np.clip(direction[first:last] @ offsets.T,
|
||||
start[first:last, None], length[first:last, None])
|
||||
difference = (offsets[None]-along[:, :, None]*direction[first:last, None])
|
||||
distances[first:last] = np.sqrt(np.min(np.sum(difference*difference, axis=2), axis=1))
|
||||
# Exact point-to-segment distance without an N*M*2 temporary or
|
||||
# a threaded BLAS call for a two-coordinate product.
|
||||
projection = (direction[first:last, 0, None]*offsets[None, :, 0]
|
||||
+ direction[first:last, 1, None]*offsets[None, :, 1])
|
||||
along = np.clip(projection, start[first:last, None], length[first:last, None])
|
||||
square_distance = squared[None] + along*(along-2*projection)
|
||||
distances[first:last] = np.sqrt(np.maximum(0., np.min(square_distance, axis=1)))
|
||||
return distances
|
||||
|
||||
def clearance_cost(self, candidates, pose, geometry, now):
|
||||
@@ -314,6 +318,15 @@ class ObservedGoals:
|
||||
and (candidate_mask is None or candidate_mask(before[None])[0])
|
||||
and supported(before)):
|
||||
retain = before
|
||||
retained_clearance = (self.approach_clearance(retain[None], pose, geometry, now)[0]
|
||||
if retain is not None else None)
|
||||
if retain is not None and retained_clearance >= geometry['width_m']:
|
||||
# The selection rule below cannot replace this still supported
|
||||
# intention. Avoid recomputing all alternative approaches each
|
||||
# sensor tick: doing so used most of the original plan lease.
|
||||
self.evidence['approach_clearance_m'] = (
|
||||
float(retained_clearance) if math.isfinite(retained_clearance) else None)
|
||||
return retain.tolist()
|
||||
# Score the task direction at the existing 3.5 m observation horizon.
|
||||
# Distance to a remote endpoint mostly rewards longitudinal advance:
|
||||
# slightly farther side returns can beat a clear straight destination
|
||||
@@ -334,8 +347,6 @@ class ObservedGoals:
|
||||
+ self.boundary_cost(candidates, geometry, now))
|
||||
clearance_cost, clearances = self.clearance_cost(candidates, pose, geometry, now)
|
||||
score += clearance_cost
|
||||
retained_clearance = (self.approach_clearance(retain[None], pose, geometry, now)[0]
|
||||
if retain is not None else None)
|
||||
for index in np.argsort(score, kind="stable"):
|
||||
if supported(candidates[index]):
|
||||
selected = candidates[index]
|
||||
|
||||
Reference in New Issue
Block a user