diff --git a/src/isar/state_machine/state_machine.py b/src/isar/state_machine/state_machine.py index 5fe323f7..7ba068e9 100644 --- a/src/isar/state_machine/state_machine.py +++ b/src/isar/state_machine/state_machine.py @@ -122,6 +122,12 @@ def __init__( "dest": self.monitor_state, "before": self._initiated, }, + { + "trigger": "pause_full_mission", + "source": [self.initiate_state, self.monitor_state], + "dest": self.paused_state, + "before": self._mission_paused, + }, { "trigger": "pause", "source": [self.initiate_state, self.monitor_state], @@ -166,6 +172,12 @@ def __init__( "dest": self.initiate_state, "before": self._resume, }, + { + "trigger": "resume_full_mission", + "source": self.paused_state, + "dest": self.monitor_state, + "before": self._resume, + }, { "trigger": "step_finished", "source": self.monitor_state, @@ -282,6 +294,8 @@ def _resume(self) -> None: self.current_task.reset_task() self.update_current_step() + self.robot.resume() + def _mission_finished(self) -> None: fail_statuses: List[TaskStatus] = [ TaskStatus.Cancelled, @@ -348,6 +362,8 @@ def _mission_paused(self) -> None: self.publish_task_status(task=self.current_task) self.publish_step_status(step=self.current_step) + self.robot.pause() + def _stop(self) -> None: self.stopped = True diff --git a/src/isar/state_machine/states/monitor.py b/src/isar/state_machine/states/monitor.py index 5e23dc73..acc5eb60 100644 --- a/src/isar/state_machine/states/monitor.py +++ b/src/isar/state_machine/states/monitor.py @@ -59,7 +59,10 @@ def _run(self) -> None: break if self.state_machine.should_pause_mission(): - transition = self.state_machine.pause # type: ignore + if self.state_machine.stepwise_mission: + transition = self.state_machine.pause # type: ignore + else: + transition = self.state_machine.pause_full_mission # type: ignore break if not self.step_status_thread: diff --git a/src/isar/state_machine/states/paused.py b/src/isar/state_machine/states/paused.py index 636d7fad..f887e0b6 100644 --- a/src/isar/state_machine/states/paused.py +++ b/src/isar/state_machine/states/paused.py @@ -1,6 +1,6 @@ import logging import time -from typing import TYPE_CHECKING, Callable +from typing import Callable, TYPE_CHECKING from transitions import State @@ -26,7 +26,10 @@ def _run(self) -> None: break if self.state_machine.should_resume_mission(): - transition = self.state_machine.resume # type: ignore + if self.state_machine.stepwise_mission: + transition = self.state_machine.resume # type: ignore + else: + transition = self.state_machine.resume_full_mission # type: ignore break time.sleep(self.state_machine.sleep_time) diff --git a/src/robot_interface/robot_interface.py b/src/robot_interface/robot_interface.py index 55663606..2d00d641 100644 --- a/src/robot_interface/robot_interface.py +++ b/src/robot_interface/robot_interface.py @@ -142,6 +142,44 @@ def stop(self) -> None: """ raise NotImplementedError + @abstractmethod + def pause(self) -> None: + """Pauses the execution of the current step and stops the movement of the robot. + + Returns + ------- + None + + Raises + ------ + RobotActionException + If the robot fails to perform the requested action to pause mission execution + the action to pause will be attempted again until a certain number of retries + RobotException + Will catch other RobotExceptions and retry to pause the mission + + """ + raise NotImplementedError + + @abstractmethod + def resume(self) -> None: + """Resumes the execution of the current step and continues the rest of the mission. + + Returns + ------- + None + + Raises + ------ + RobotActionException + If the robot fails to perform the requested action to resume mission execution + the action to resume will be attempted again until a certain number of retries + RobotException + Will catch other RobotExceptions and retry to resume the mission + + """ + raise NotImplementedError + @abstractmethod def get_inspections(self, step: InspectionStep) -> Sequence[Inspection]: """Return the inspections connected to the given step. diff --git a/tests/mocks/robot_interface.py b/tests/mocks/robot_interface.py index 4be71215..c99e5be9 100644 --- a/tests/mocks/robot_interface.py +++ b/tests/mocks/robot_interface.py @@ -51,6 +51,12 @@ def step_status(self) -> StepStatus: def stop(self) -> None: return + def pause(self) -> None: + return + + def resume(self) -> None: + return + def get_inspections(self, step: InspectionStep) -> Sequence[Inspection]: image: Image = Image(mock_image_metadata()) image.data = b"Some binary image data"