Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mil_missions: Wait until all missions come alive before attempting to run a requested mission #1250

Merged
merged 1 commit into from
Aug 25, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions mil_common/mil_missions/nodes/mission_server
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import traceback
import types

import axros
import rospy
import uvloop
from axros import NodeHandle, Service, action, util
from mil_missions.msg import DoMissionAction, DoMissionFeedback, DoMissionResult
Expand Down Expand Up @@ -188,13 +189,23 @@ class MissionRunner:
print(message)
self.server.publish_feedback(feedback)

def do_new_mission(self):
async def do_new_mission(self):
"""
Accept a new goal and start running it
"""
if not self.server.is_new_goal_available():
return
goal = self.server.accept_new_goal()
start = self.nh.get_time()
wait = rospy.Duration(5)
while not self.missions and (self.nh.get_time() - start) < wait:
await self.nh.sleep(0.1)
if not self.missions:
print(f"TASK RUNNER: no missions have been loaded after {wait.secs} secs")
self.server.set_aborted(
result=DoMissionResult(success=False, result="no missions loaded"),
)
return
if not self.has_mission(goal.mission):
print(f"TASK RUNNER: unrecognized mission '{goal.mission}'")
self.server.set_aborted(
Expand Down Expand Up @@ -237,7 +248,7 @@ class MissionRunner:
):
self.mission_future.cancel()
# Try to accept a new mission
self.do_new_mission()
self.new_mission_task = asyncio.create_task(self.do_new_mission())

def mission_finished_cb(self, task: asyncio.Task):
"""
Expand Down
Loading