Skip to content

Commit

Permalink
Ensure status checked before starting mission
Browse files Browse the repository at this point in the history
When entering Idle ISAR accept a new mission if
it is started. However, based on the robot status
it might be necessary to transition to a different
state rather than starting the mission.
  • Loading branch information
oysand committed Jan 15, 2025
1 parent b19d9b0 commit ec5a803
Showing 1 changed file with 18 additions and 10 deletions.
28 changes: 18 additions & 10 deletions src/isar/state_machine/states/idle.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ def __init__(self, state_machine: "StateMachine") -> None:
self.logger = logging.getLogger("state_machine")
self.robot_status_thread: Optional[ThreadedRequest] = None
self.last_robot_status_poll_time: float = time.time()
self.status_checked_at_least_once: bool = False

def start(self) -> None:
self.state_machine.update_state()
Expand All @@ -33,8 +34,12 @@ def stop(self) -> None:
if self.robot_status_thread:
self.robot_status_thread.wait_for_thread()
self.robot_status_thread = None
self.status_checked_at_least_once = False

def _is_ready_to_poll_for_status(self) -> bool:
if not self.status_checked_at_least_once:
return True

time_since_last_robot_status_poll = (
time.time() - self.last_robot_status_poll_time
)
Expand All @@ -47,17 +52,19 @@ def _run(self) -> None:
if self.state_machine.should_stop_mission():
transition = self.state_machine.stop # type: ignore
break
start_mission: Optional[StartMissionMessage] = (
self.state_machine.should_start_mission()
)
if start_mission:
self.state_machine.start_mission(
mission=start_mission.mission,
initial_pose=start_mission.initial_pose,

if self.status_checked_at_least_once:
start_mission: Optional[StartMissionMessage] = (
self.state_machine.should_start_mission()
)
transition = self.state_machine.mission_started # type: ignore
break
time.sleep(self.state_machine.sleep_time)
if start_mission:
self.state_machine.start_mission(
mission=start_mission.mission,
initial_pose=start_mission.initial_pose,
)
transition = self.state_machine.mission_started # type: ignore
break
time.sleep(self.state_machine.sleep_time)

if not self._is_ready_to_poll_for_status():
continue
Expand All @@ -72,6 +79,7 @@ def _run(self) -> None:

try:
robot_status: RobotStatus = self.robot_status_thread.get_output()
self.status_checked_at_least_once = True
except ThreadedRequestNotFinishedError:
time.sleep(self.state_machine.sleep_time)
continue
Expand Down

0 comments on commit ec5a803

Please sign in to comment.