fix(simulation): consume Nav2 local action completion

This commit is contained in:
DCCONSTRUCTIONS
2026-10-08 14:00:54 +03:00
parent 6a89f809a4
commit bc915c01e1
5 changed files with 149 additions and 3 deletions
@@ -213,6 +213,41 @@ def main():
# Warm the costmaps through normal planning before invoking a behavior;
# lifecycle activation alone does not publish their first observation.
assert result['controller_goal'][0]=='path',result
# Synthetic measured odometry enters Nav2's unchanged 40 cm region,
# while remaining outside the legacy mission recovery's 30 cm region.
# A capture refresh must return completion, not restart FollowPath.
reached=[.65,0.,.37,0.,0.,0.,1.]
with condition:
state.update(pose=reached,enabled=True)
retreat.update(pose=reached,observation_id='local-action-complete')
time.sleep(.15)
deadline=time.monotonic()+3
completion_plans=[]
while True:
result=request('/plan',retreat)
completion_plans.append(result)
if result.get('action_result') is not None:
break
assert time.monotonic()<deadline,completion_plans
time.sleep(.1)
expected=dict(status='succeeded',kind='path',goal_xy=[1.,0.])
assert result['action_result']==expected,result
assert result['speed_mps']==result['yaw_rate_rps']==0.,result
assert result['route_observation']['observation']['pose']==reached,result
for index in range(3):
retreat['observation_id']='completed-refresh-'+str(index)
repeated=request('/plan',retreat)
assert repeated.get('action_result')==expected,repeated
assert repeated['speed_mps']==repeated['yaw_rate_rps']==0.,repeated
report['local_action_completion']=completion_plans
# A different goal must start its own action, not inherit that result.
retreat.update(goal=[1.8,0.,0.],observation_id='after-completion-new-goal')
changed=request('/plan',retreat)
assert changed['status']=='path' and 'action_result' not in changed,changed
report['new_goal_after_completion']=changed
with condition:
state.update(pose=[0.,0.,.37,0.,0.,0.,1.],enabled=False)
retreat['pose']=[0.,0.,.37,0.,0.,0.,1.]
retreat.update(goal=[-1.,0.,0.],allow_reverse=True,observation_id='retreat-full-ground')
result=request('/plan',retreat)
assert result['status']=='path' and result['controller_goal'][0]=='backup',result
+21
View File
@@ -83,6 +83,18 @@ class Navigation:
return dict(speed_mps=0., yaw_rate_rps=0., status=status, path=[],
diagnostic=dict(failure=reason), **extra)
def completed_action(self, key, route):
terminal = self.node.terminal
if (key == self.action_key and key[0] in {'path', 'backup'}
and terminal is not None and terminal.done()
and terminal.result().status == GoalStatus.STATUS_SUCCEEDED):
# Preserve the native terminal result before a sensor refresh can
# submit the same FollowPath again. This is local-action completion,
# not whole-body arrival admission and never a motion proposal.
return self.reply('native-action-complete', route_observation=route,
action_result=dict(status='succeeded', kind=key[0], goal_xy=list(key[1])))
return None
def plan(self, value):
entered = time.monotonic()
if self.failure:
@@ -170,6 +182,9 @@ class Navigation:
self.node.stop()
return self.reply('reverse-goal-is-not-behind', status='blocked')
key = ('backup', tuple(goal[:2]), limit)
completed = self.completed_action(key, route)
if completed is not None:
return completed
if key != self.action_key:
with self.owner_lock:
self.action_key = None
@@ -180,6 +195,9 @@ class Navigation:
# a path update; the existing capture leases and raw range gates
# still validate every command against the caller's observation.
key = ('path', tuple(goal[:2]), limit)
completed = self.completed_action(key, route)
if completed is not None:
return completed
continuing = key == self.action_key
# Match the pinned Nav2 BT's 1 Hz ComputePathToPose cadence.
# The path is an intent, not a sensor sample: terrain, costmaps,
@@ -202,6 +220,9 @@ class Navigation:
for p in path.poses]
with self.owner_lock:
self.action_key = key
completed = self.completed_action(key, route)
if completed is not None:
return completed
native = self.node.native_command()
if native is None:
terminal = self.node.terminal.result() if self.node.terminal and self.node.terminal.done() else None