Keep passage clearance tied to observed spatial geometry
This commit is contained in:
@@ -7,6 +7,7 @@ converted to positive semantic cells.
|
||||
"""
|
||||
import math
|
||||
import numpy as np
|
||||
from scipy.spatial import cKDTree
|
||||
|
||||
|
||||
def passage_centres(points, pose, target, geometry, obstacles):
|
||||
@@ -17,6 +18,7 @@ def passage_centres(points, pose, target, geometry, obstacles):
|
||||
[math.sin(yaw), math.cos(yaw)]])
|
||||
local = (points[:, :2]-position) @ axes
|
||||
hazards = (obstacles-position) @ axes if len(obstacles) else np.empty((0, 2))
|
||||
tree = cKDTree(hazards) if len(hazards) else None
|
||||
width = geometry['width_m']
|
||||
length = geometry.get('length_m', width)
|
||||
route = (np.asarray(target)-position) @ axes
|
||||
@@ -32,18 +34,31 @@ def passage_centres(points, pose, target, geometry, obstacles):
|
||||
# Larger unsupported intervals remain distinct passages.
|
||||
groups = np.split(lateral, np.flatnonzero(np.diff(lateral) > .3)+1)
|
||||
intervals = [(float(g[0]), float(g[-1])) for g in groups if len(g) >= 3]
|
||||
near = hazards[(hazards[:, 0] >= .4)
|
||||
& (hazards[:, 0] <= along+length)]
|
||||
for boundary in sorted(set(np.round(near[:, 1]/.1).astype(int))):
|
||||
low, high = boundary*.1-.1, boundary*.1+.1
|
||||
intervals = [piece for a,b in intervals for piece in (
|
||||
[(a,b)] if high <= a or low >= b else
|
||||
[(a,min(b,low)),(max(a,high),b)]) if piece[1]>piece[0]]
|
||||
centres=[]
|
||||
for low,high in intervals:
|
||||
if high-low < width:
|
||||
continue
|
||||
middle=(low+high)/2
|
||||
# Rank lateral positions by their worst clearance to the observed
|
||||
# passage limits and to solids along the whole continuing bearing.
|
||||
# Keep each obstacle at its actual longitudinal coordinate: a wall
|
||||
# beside the rover must not become a fictitious barrier ahead.
|
||||
lateral_samples = np.linspace(low+width/2, high-width/2,
|
||||
max(2, math.ceil((high-low-width)/.05)+1))
|
||||
centre_clearance = np.minimum(lateral_samples-low, high-lateral_samples)
|
||||
if tree is not None:
|
||||
delta = np.column_stack((np.full(len(lateral_samples),along), lateral_samples))
|
||||
direction = delta / np.linalg.norm(delta,axis=1)[:,None]
|
||||
radial = np.linspace(length/2, 3.5, 65)
|
||||
queries = direction[:,None,:]*radial[None,:,None]
|
||||
distances = tree.query(queries.reshape(-1,2))[0].reshape(len(delta),-1)
|
||||
centre_clearance = np.minimum(centre_clearance, distances.min(axis=1))
|
||||
peak = centre_clearance.max()
|
||||
maxima = np.flatnonzero(centre_clearance >= peak-.025)
|
||||
lobes = np.split(maxima, np.flatnonzero(np.diff(maxima)>1)+1)
|
||||
# Two equally clear sides of an obstacle are separate choices.
|
||||
# Averaging them would put the goal back through the obstacle.
|
||||
lobe = min(lobes, key=lambda ids: abs(lateral_samples[ids].mean()-(low+high)/2))
|
||||
middle = float(lateral_samples[lobe].mean())
|
||||
# A broad open area has no nearby pair of boundaries to centre
|
||||
# between. The route can choose a direction within its interior.
|
||||
if high-low >= 2*3.5 and route[0] > .1:
|
||||
|
||||
Reference in New Issue
Block a user