Skip to content

Commit

Permalink
Implement pause and resume for full mission
Browse files Browse the repository at this point in the history
  • Loading branch information
andchiind authored and mrica-equinor committed Jun 17, 2024
1 parent 3aa8df7 commit fd80cec
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 3 deletions.
16 changes: 16 additions & 0 deletions src/isar/state_machine/state_machine.py
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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

Expand Down
5 changes: 4 additions & 1 deletion src/isar/state_machine/states/monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
7 changes: 5 additions & 2 deletions src/isar/state_machine/states/paused.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import logging
import time
from typing import TYPE_CHECKING, Callable
from typing import Callable, TYPE_CHECKING

from transitions import State

Expand All @@ -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)
Expand Down
38 changes: 38 additions & 0 deletions src/robot_interface/robot_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
6 changes: 6 additions & 0 deletions tests/mocks/robot_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit fd80cec

Please sign in to comment.