Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
021b9f427f | ||
|
|
1f1d4a2807 |
@@ -245,6 +245,24 @@ def main():
|
||||
changed=request('/plan',retreat)
|
||||
assert changed['status']=='path' and 'action_result' not in changed,changed
|
||||
report['new_goal_after_completion']=changed
|
||||
# An unobserved destination is rejected by the native planner with
|
||||
# allow_unknown=False. Report that exact action result to selection;
|
||||
# do not mislabel it as a measured obstacle or retain the old command.
|
||||
retreat.update(goal=[6.,0.,0.],observation_id='unobserved-local-goal')
|
||||
rejected=request('/plan',retreat)
|
||||
assert rejected['status']=='blocked' and rejected['diagnostic']['failure']=='no-path',rejected
|
||||
assert rejected['planning_result']==dict(status='aborted',goal_xy=[6.,0.]),rejected
|
||||
assert rejected['route_observation']['observation']==dict(pose=reached,
|
||||
simulation_time_seconds=retreat['simulation_time_seconds'],
|
||||
execution_inputs_sha256=inputs['sha256']),rejected
|
||||
with condition:state.update(enabled=True,observation_id=retreat['observation_id'])
|
||||
time.sleep(.1)
|
||||
assert responses[-1]['speed_mps']==responses[-1]['yaw_rate_rps']==0.,responses[-1]
|
||||
report['aborted_local_plan']=dict(plan=rejected,command=responses[-1])
|
||||
retreat.update(goal=[1.8,.2,0.],observation_id='replacement-observed-goal')
|
||||
replacement=request('/plan',retreat)
|
||||
assert replacement['status']=='path' and 'planning_result' not in replacement,replacement
|
||||
report['replacement_local_plan']=replacement
|
||||
with condition:
|
||||
state.update(pose=[0.,0.,.37,0.,0.,0.,1.],enabled=False)
|
||||
retreat['pose']=[0.,0.,.37,0.,0.,0.,1.]
|
||||
|
||||
@@ -72,7 +72,7 @@ def main():
|
||||
bridge.activate()
|
||||
history=[]
|
||||
for goal in ([5.,0.], [3.,1.]):
|
||||
planned=bridge.plan(pose,goal,math.atan2(goal[1],goal[0]))
|
||||
planned,status=bridge.plan(pose,goal,math.atan2(goal[1],goal[0]))
|
||||
assert planned is not None and len(planned.poses)>1
|
||||
proposed=bridge.follow(planned)
|
||||
assert proposed is not None
|
||||
|
||||
@@ -144,7 +144,8 @@ class RosNavigation(Node):
|
||||
# Do not leave work from a timed-out HTTP transaction as authority.
|
||||
self.await_result(handle.cancel_goal_async(), .2)
|
||||
raise
|
||||
return result.result.path if result.status == GoalStatus.STATUS_SUCCEEDED else None
|
||||
return (result.result.path if result.status == GoalStatus.STATUS_SUCCEEDED else None,
|
||||
result.status)
|
||||
|
||||
def accept(self, client, request, timeout, feedback_callback=None):
|
||||
if self.failed:
|
||||
|
||||
@@ -204,10 +204,14 @@ class Navigation:
|
||||
# capture leases and command gates still refresh above/every tick.
|
||||
if (not continuing or self.path is None or self.node.native_command() is None
|
||||
or entered-self.path_planned_at >= 1.0):
|
||||
path = self.node.plan(pose, goal, math.atan2(goal[1]-pose[1],goal[0]-pose[0]))
|
||||
path, status = self.node.plan(pose, goal, math.atan2(goal[1]-pose[1],goal[0]-pose[0]))
|
||||
if path is None or len(path.poses) < 2:
|
||||
self.node.stop()
|
||||
return self.reply('no-path', status='blocked', route_observation=route)
|
||||
# Humble has no typed planner error code. Preserve its
|
||||
# terminal abort without inventing an obstacle diagnosis.
|
||||
feedback = (dict(planning_result=dict(status='aborted', goal_xy=goal[:2].tolist()))
|
||||
if status == GoalStatus.STATUS_ABORTED else {})
|
||||
return self.reply('no-path', status='blocked', route_observation=route, **feedback)
|
||||
if not continuing:
|
||||
with self.owner_lock:
|
||||
self.action_key = None
|
||||
|
||||
@@ -119,10 +119,11 @@ class TerrainObservation:
|
||||
request['body_contact_height_m'], monitor=self.monitor)
|
||||
physical = points.copy()
|
||||
ground_at = time.monotonic()
|
||||
self.support_obstacles.revalidate(points, pose, request['body_contact_height_m'],
|
||||
monitor=self.monitor)
|
||||
# Both checks use the same immutable terrain and pose in this transaction.
|
||||
surface = self.support_obstacles.revalidate(points, pose, request['body_contact_height_m'],
|
||||
monitor=self.monitor)
|
||||
self.support_obstacles.observe_ahead(points, pose, request['body_contact_height_m'],
|
||||
monitor=self.monitor, speed_mps=float(request['max_speed_mps']))
|
||||
monitor=self.monitor, speed_mps=float(request['max_speed_mps']), surface=surface)
|
||||
support_at = time.monotonic()
|
||||
candidates = self.detections.observed(request)
|
||||
ground = current[ground[:,3] == 1]
|
||||
|
||||
@@ -90,8 +90,9 @@ class SupportObstacles:
|
||||
self.keys.pop(key, None)
|
||||
del self.patches[key]
|
||||
offset += length
|
||||
return surface
|
||||
|
||||
def observe_ahead(self, terrain, pose, contact_height_m, *, monitor, speed_mps):
|
||||
def observe_ahead(self, terrain, pose, contact_height_m, *, monitor, speed_mps, surface=None):
|
||||
"""Expose measured bad ground to search before a command reaches it.
|
||||
|
||||
The reactive sweep remains authoritative. This bounded contact-width
|
||||
@@ -122,9 +123,10 @@ class SupportObstacles:
|
||||
axis=0, return_index=True)
|
||||
selected = candidates[indices]
|
||||
selected = selected[np.argsort(np.linalg.norm(local[selected],axis=1))][:512]
|
||||
surface = SupportSurface(terrain, pose, contact_height_m,
|
||||
monitor.max_step, monitor.max_slope,
|
||||
anchor_radius_m=math.hypot(monitor.half_length, monitor.half_width))
|
||||
if surface is None:
|
||||
surface = SupportSurface(terrain, pose, contact_height_m,
|
||||
monitor.max_step, monitor.max_slope,
|
||||
anchor_radius_m=math.hypot(monitor.half_length, monitor.half_width))
|
||||
offsets = terrain[selected,:2]-pose[:2]
|
||||
states, _ = monitor.classify_contacts(surface, offsets)
|
||||
unsafe = offsets[states == 'observed-unsafe']
|
||||
|
||||
@@ -63,6 +63,12 @@ class SupportPolicy:
|
||||
anchor_radius_m=math.hypot(m.half_length, m.half_width),
|
||||
continuity_terrain=continuity_terrain,
|
||||
)
|
||||
return self._context(speed, yaw_rate, pose, surface)
|
||||
|
||||
def _context(self, speed, yaw_rate, pose, surface):
|
||||
# The live sweep and entering-track probes use the identical captured
|
||||
# ground, pose and continuity. Share only within this control tick.
|
||||
m = self.monitor
|
||||
qx, qy, qz, qw = pose[3:]
|
||||
yaw = math.atan2(2 * (qw * qz + qx * qy), 1 - 2 * (qy * qy + qz * qz))
|
||||
axes = np.array([[math.cos(yaw), -math.sin(yaw)], [math.sin(yaw), math.cos(yaw)]])
|
||||
@@ -70,7 +76,7 @@ class SupportPolicy:
|
||||
# sweep instead of inventing contact bands or upgrading pinned inputs.
|
||||
if m.contacts is None:
|
||||
fresh = m.assess_command_support(
|
||||
speed, yaw_rate, [], pose, contact_height_m, surface=surface
|
||||
speed, yaw_rate, [], pose, surface.contact_height, surface=surface
|
||||
)
|
||||
return dict(available=fresh["admitted"], reason="legacy-fresh-sweep", patches=[])
|
||||
patches = []
|
||||
@@ -250,8 +256,7 @@ class SupportPolicy:
|
||||
"patches": [],
|
||||
}
|
||||
else:
|
||||
context = self.context(speed, yaw_rate, current_points, pose, contact_height_m,
|
||||
continuity_terrain=terrain)
|
||||
context = self._context(speed, yaw_rate, pose, fresh_surface)
|
||||
if any(p["observed_unsafe"] for p in context["patches"]):
|
||||
scale, reason = 0.0, "observed-unsafe-support"
|
||||
elif not context["available"]:
|
||||
|
||||
@@ -837,6 +837,8 @@ class ComposedInference:
|
||||
"allow_reverse": intent["state"] == "reversing",
|
||||
},
|
||||
)
|
||||
self.mission.reject_local_plan(
|
||||
result, pose, inputs["source.simulation-time"], self.inputs["sha256"])
|
||||
self.mission.recovery.observe_navigation(
|
||||
result, pose, inputs["source.simulation-time"],
|
||||
recovery_option, self.inputs["sha256"],
|
||||
|
||||
@@ -114,6 +114,25 @@ class WaypointMission:
|
||||
self.failed_goals.append(self.goal)
|
||||
self.goal = None
|
||||
|
||||
def reject_local_plan(self, result, pose, seconds, execution_inputs_sha256):
|
||||
"""Retire an intermediate intent after its bound native planner abort.
|
||||
|
||||
This is not an obstacle label or motion permission. The next observed
|
||||
candidate must obtain its own native path and current command admission.
|
||||
Preserve task arrival evidence and the existing progress/retry budget.
|
||||
"""
|
||||
if (self.fault or self.recovery.active or self.goal is None
|
||||
or self.last_time != seconds or self.last_pose != tuple(pose)):
|
||||
return
|
||||
expected = dict(pose=list(pose), simulation_time_seconds=seconds,
|
||||
execution_inputs_sha256=execution_inputs_sha256)
|
||||
if (result.get("route_observation", {}).get("observation") == expected
|
||||
and result.get("status") == "blocked"
|
||||
and result.get("speed_mps") == result.get("yaw_rate_rps") == 0.
|
||||
and result.get("planning_result") == dict(
|
||||
status="aborted", goal_xy=list(self.goal[:2]))):
|
||||
self.retire_local_goal(self.arrival_target(), failed=True)
|
||||
|
||||
def arrival_candidate(self, pose):
|
||||
return bool(
|
||||
self.route
|
||||
|
||||
@@ -101,7 +101,7 @@ def test_wrong_direction_never_replenishes_route_attempts():
|
||||
assert intent["state"] == "stuck"
|
||||
|
||||
|
||||
def test_signed_motion_contract_accepts_reverse_but_stays_bounded():
|
||||
def test_signed_motion_contract_accepts_reverse_but_requires_finite_speed():
|
||||
from pydantic import ValidationError
|
||||
|
||||
from k1link.simulation.ai_polygon.contracts import Decision
|
||||
@@ -112,8 +112,11 @@ def test_signed_motion_contract_accepts_reverse_but_stays_bounded():
|
||||
).speed_mps
|
||||
< 0
|
||||
)
|
||||
with pytest.raises(ValidationError):
|
||||
Decision(speed_mps=-1.1, yaw_rate_rps=0, reason="road", road_fraction=1, obstacle_count=0)
|
||||
# The configured robot/run owns the speed ceiling; this transport contract
|
||||
# has no fixed one-metre-per-second limit. Non-finite commands remain invalid.
|
||||
for speed in (float("inf"), float("-inf"), float("nan")):
|
||||
with pytest.raises(ValidationError):
|
||||
Decision(speed_mps=speed, yaw_rate_rps=0, reason="road", road_fraction=1, obstacle_count=0)
|
||||
|
||||
|
||||
def test_slow_regulated_progress_is_not_mistaken_for_stall():
|
||||
@@ -242,3 +245,55 @@ def test_heading_credit_keeps_existing_retry_count_and_expires():
|
||||
for seconds in range(9, 80):
|
||||
mission.update(yaw_pose(min((seconds - 8) * 0.08, 3.14)), seconds, choose)
|
||||
assert mission.fault == "stuck" and mission.attempts == 4
|
||||
|
||||
|
||||
def aborted_plan(goal, p, seconds):
|
||||
return dict(status="blocked", speed_mps=0., yaw_rate_rps=0.,
|
||||
planning_result=dict(status="aborted", goal_xy=list(goal[:2])),
|
||||
route_observation=dict(observation=dict(pose=p, simulation_time_seconds=seconds,
|
||||
execution_inputs_sha256="run")))
|
||||
|
||||
|
||||
def test_native_abort_selects_another_observed_intent_without_resetting_progress():
|
||||
mission = WaypointMission([[8, 0]])
|
||||
first, _ = mission.update(pose(), 0, goal)
|
||||
mission.reject_local_plan(aborted_plan(first, pose(), 0), pose(), 0, "run")
|
||||
assert mission.goal is None and mission.failed_goals == [first]
|
||||
assert mission.anchor_time == 0 and mission.attempts == 0
|
||||
second, _ = mission.update(pose(), .1, goal)
|
||||
assert second != first and mission.route == [[8, 0]]
|
||||
# Repeated planner rejection and goal changes cannot create progress.
|
||||
for t in range(1, 34):
|
||||
current, _ = mission.update(pose(), t, goal)
|
||||
if current is not None:
|
||||
mission.reject_local_plan(aborted_plan(current, pose(), t), pose(), t, "run")
|
||||
assert mission.fault == "stuck"
|
||||
|
||||
|
||||
@pytest.mark.parametrize("invalid", ["old-goal", "old-pose", "old-time", "old-run",
|
||||
"missing-result", "canceled", "moving", "waiting", "old-caller", "recovery"])
|
||||
def test_only_current_native_abort_can_retire_local_intent(invalid):
|
||||
mission = WaypointMission([[8, 0]])
|
||||
first, _ = mission.update(pose(), 1, goal)
|
||||
result = aborted_plan(first, pose(), 1)
|
||||
observation = result["route_observation"]["observation"]
|
||||
if invalid == "old-goal": result["planning_result"]["goal_xy"] = [3, 0]
|
||||
elif invalid == "old-pose": observation["pose"] = pose(.1)
|
||||
elif invalid == "old-time": observation["simulation_time_seconds"] = 0
|
||||
elif invalid == "old-run": observation["execution_inputs_sha256"] = "other"
|
||||
elif invalid == "missing-result": result.pop("planning_result")
|
||||
elif invalid == "canceled": result["planning_result"]["status"] = "canceled"
|
||||
elif invalid == "moving": result["speed_mps"] = .1
|
||||
elif invalid == "waiting": result["status"] = "waiting-for-plan"
|
||||
elif invalid == "recovery": mission.recovery.begin(pose(), 1, [])
|
||||
mission.reject_local_plan(result, pose(), 0 if invalid == "old-caller" else 1, "run")
|
||||
assert mission.goal == first and mission.failed_goals == []
|
||||
|
||||
|
||||
def test_native_abort_keeps_task_arrival_evidence_and_requires_new_observation():
|
||||
mission = WaypointMission([[2, 0]])
|
||||
first, _ = mission.update(pose(), 0, goal)
|
||||
mission.reject_local_plan(aborted_plan(first, pose(), 0), pose(), 0, "run")
|
||||
assert mission.goal == first and mission.failed_goals == []
|
||||
assert mission.update(pose(), .1, lambda *_: None)[0] is None
|
||||
assert mission.index == 0 and mission.fault is None
|
||||
|
||||
@@ -30,11 +30,11 @@ def test_navigation_delivers_current_option_veto_and_stale_data_does_not_retire_
|
||||
semantic_visible=lambda points,calibration:np.ones(len(points),bool))
|
||||
monkeypatch.setattr(module,'project',lambda points,*args:(points,np.zeros(len(points)),
|
||||
np.zeros(len(points)),np.ones(len(points),bool)))
|
||||
failure=['no-path']
|
||||
failure=['no-path']; planning=[None]
|
||||
def response(path,request):
|
||||
assert path=='/plan'
|
||||
return dict(status='blocked',path=[],speed_mps=0.,yaw_rate_rps=0.,
|
||||
diagnostic=dict(failure=failure[0]),route_observation=dict(observation=dict(
|
||||
planning_result=planning[0],diagnostic=dict(failure=failure[0]),route_observation=dict(observation=dict(
|
||||
pose=list(request['pose']),simulation_time_seconds=request['simulation_time_seconds'],
|
||||
execution_inputs_sha256=request['execution_inputs_sha256'])))
|
||||
model.navigation=SimpleNamespace(request=response)
|
||||
@@ -63,3 +63,15 @@ def test_navigation_delivers_current_option_veto_and_stale_data_does_not_retire_
|
||||
assert model.navigate(inputs)['motion.command']['speed_mps']==0
|
||||
assert not model.mission.recovery.active
|
||||
assert model.mission.recovery.sequence==model.mission.recovery.option==0
|
||||
|
||||
# Normal mission selection also receives a bound planner abort immediately,
|
||||
# without entering the recovery state or changing the task destination.
|
||||
selected, _ = model.mission.update(p, 1., lambda *_: [2.,0.,0.])
|
||||
model.goal=selected
|
||||
planning[0]=dict(status='aborted',goal_xy=selected[:2])
|
||||
inputs['source.simulation-time']=1.
|
||||
model.navigate(inputs)
|
||||
assert model.mission.goal is None
|
||||
assert model.mission.failed_goals == [selected]
|
||||
assert model.mission.anchor_time == 1. and model.mission.attempts == 0
|
||||
assert model.mission.route == [[10,0]] and not model.mission.recovery.active
|
||||
|
||||
Reference in New Issue
Block a user