Keep advisory route joints directional and preserve observed clearance

This commit is contained in:
DCCONSTRUCTIONS
2026-10-10 00:29:41 +03:00
parent daabdb9450
commit 41fa11e6c8
4 changed files with 62 additions and 9 deletions
@@ -52,6 +52,10 @@ def passage_centres(points, pose, target, geometry, obstacles):
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))
# Beyond the observation horizon, extra empty width has no local
# preference. Route direction can break ties only among equally
# clear interior samples, never overwrite an obstacle score.
centre_clearance = np.minimum(centre_clearance, 3.5)
peak = centre_clearance.max()
maxima = np.flatnonzero(centre_clearance >= peak-.025)
lobes = np.split(maxima, np.flatnonzero(np.diff(maxima)>1)+1)
@@ -59,10 +63,10 @@ def passage_centres(points, pose, target, geometry, obstacles):
# 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:
middle=float(np.clip(along*route[1]/route[0],low+width,high-width))
if peak >= 3.5 and route[0] > .1:
preferred = along*route[1]/route[0]
middle = float(lateral_samples[maxima[np.argmin(
np.abs(lateral_samples[maxima]-preferred))]])
xy=position+axes @ np.array([along,middle])
if np.linalg.norm(xy-position) > 3.5:
continue
@@ -192,11 +192,16 @@ class RoutedMission(WaypointMission):
along, lateral = projection(pose[:2], segment["start_xy"], segment["end_xy"])
self.remaining = max(0.0, self.leg["length_m"] - self.completed_length - along) + lateral * (
.15 if segment.get("guidance_only") else 1.)
# Supply a stable segment endpoint. The visual/local planner already
# chooses observed intermediate goals within its own lookahead. A second
# 0.8m target here sits in the camera blind strip and can make it choose
# unrelated farther pixels instead of remembering a visible corner.
self.route_target = list(segment["end_xy"])
if self.advisory_joint():
# A map joint describes continuation, not a chassis destination.
# Preserve its direction when the measured passage runs beside it:
# a lateral offset must not turn into a 90-degree attraction as the
# rover draws level. Arrival/adjacent-support queries still use the
# actual joint and alone advance the route cursor.
direction = np.asarray(segment["end_xy"]) - segment["start_xy"]
direction /= np.linalg.norm(direction)
self.route_target = (np.asarray(pose[:2]) + 6.*direction).tolist()
def distance_to_target(self, pose, target):
return self.remaining
@@ -360,7 +365,7 @@ class RoutedMission(WaypointMission):
# native planner abort must retire a measured goal near that hint;
# preserving it as task-arrival evidence pins the rover to a blocked
# intermediate point. Explicit goals and return anchors retain it.
super().retire_local_goal(None if advisory_joint else self.route_target, failed=failed)
super().retire_local_goal(None if advisory_joint else self.arrival_target(), failed=failed)
def arrival_candidate(self, pose):
return (
+15
View File
@@ -510,3 +510,18 @@ def test_symmetric_obstacle_does_not_average_two_passages_through_its_centre(sel
goal=selector.choose(points,pose,target,None,(),GEOMETRY,1.1)
assert goal is not None and abs(goal[1])>.35
assert selector.approach_clearance(np.array([goal]),pose,GEOMETRY,1.1)[0]>.2
@pytest.mark.parametrize("angle,shift", [(0,(0,0)), (73,(42,-17)), (-138,(-250,52))])
def test_wide_passage_does_not_erase_obstacle_clearance_for_route_direction(selector,angle,shift):
_,pose,_,_,rotation=road(angle,shift)
xy=np.array([[x,y] for x in np.arange(.4,6.,.07)
for y in np.arange(-4.,4.01,.07)])
points=np.c_[xy@rotation.T+shift,np.zeros(len(xy))]
selector.observe(np.c_[points,np.ones(len(points))],1.,pose)
hazard=(np.array([[2.,-1.3]])@rotation.T+shift).tolist()
selector.observe_navigation(clearance_receipt(pose,hazard),pose,1,'run',1.)
goal=selector.choose(points,pose,np.array(shift)+rotation@[8,-5],None,(),GEOMETRY,1.1)
assert goal is not None
assert selector.approach_clearance(np.array([goal]),pose,GEOMETRY,1.1)[0] > 1.5
assert ((np.array(goal[:2])-shift)@rotation)[1] > 0
+29
View File
@@ -321,3 +321,32 @@ def test_advisory_joint_is_never_an_exact_arrival_destination():
mission.segment_index=len(mission.leg['segments'])-1
mission.route_observation(pose,0.)
assert mission.can_query_arrival(pose)
@pytest.mark.parametrize("offset", [-3.,0.,3.])
def test_advisory_joint_is_a_direction_not_lateral_attraction(offset):
from k1link.simulation.ai_polygon.route_mission import RoutedMission
*_,inputs,_=fixture()
inputs['routing']['blocked_edges']=['0','1','2']
inputs.update(sensors={'schema_version':'missioncore.simulation-sensor-rig/v4'},
behavior={'max_speed_mps':1.})
mission=RoutedMission(inputs)
mission.route_observation([0.,0.,0.,0.,0.,0.,1.],0.)
# The actual open passage can pass a map joint on either side. Neither
# the goal selector nor the stopped view acquisition should face the joint.
for t,y in enumerate([2.,4.,5.,6.],start=10):
pose=[offset,y,0.,0.,0.,0.,1.]
mission.route_observation(pose,float(t*4))
direction=np.array(mission.route_target)-pose[:2]
assert direction[0] == pytest.approx(0.) and direction[1] > 3.5
assert mission.orientation_target()['xy'] == mission.route_target
assert mission.arrival_target() == [0.,5.]
assert mission.segment_index == 0 # direction is not a transition receipt
assert not mission.can_query_arrival(pose)
# A required return anchor and final mission destination retain exact XY.
mission.leg['segments'][0]['return_to_anchor']=True
mission.route_observation(pose,60.)
assert mission.route_target == [0.,5.]
mission.segment_index=len(mission.leg['segments'])-1
mission.route_observation(pose,61.)
assert mission.route_target == mission.leg['goal_xy']