Skip to content

Commit

Permalink
Use step_status for non stepwise robots
Browse files Browse the repository at this point in the history
  • Loading branch information
andchiind committed Apr 10, 2024
1 parent a9760a2 commit 7f20e97
Showing 1 changed file with 30 additions and 12 deletions.
42 changes: 30 additions & 12 deletions src/isar/state_machine/states/monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

from injector import inject
from transitions import State
from isar.mission_planner.task_selector_interface import TaskSelectorStop

from isar.services.utilities.threaded_request import (
ThreadedRequest,
Expand All @@ -19,7 +20,7 @@
)
from robot_interface.models.inspection.inspection import Inspection
from robot_interface.models.mission.mission import Mission
from robot_interface.models.mission.status import MissionStatus
from robot_interface.models.mission.status import MissionStatus, TaskStatus
from robot_interface.models.mission.step import InspectionStep, Step, StepStatus

if TYPE_CHECKING:
Expand Down Expand Up @@ -56,16 +57,10 @@ def _run(self) -> None:
break

if not self.step_status_thread:
if self.state_machine.stepwise_mission:
self._run_get_status_thread(
status_function=self.state_machine.robot.step_status,
thread_name="State Machine Monitor Get Step Status",
)
else:
self._run_get_status_thread(
status_function=self.state_machine.robot.mission_status,
thread_name="State Machine Monitor Get Mission Status",
)
self._run_get_status_thread(
status_function=self.state_machine.robot.step_status,
thread_name="State Machine Monitor Get Step Status",
)

try:
status: Union[StepStatus, MissionStatus] = (
Expand Down Expand Up @@ -106,7 +101,7 @@ def _run(self) -> None:
f"Retrieving the status failed because: {e.error_description}"
)

if self.state_machine.stepwise_mission and isinstance(status, StepStatus):
if isinstance(status, StepStatus):
self.state_machine.current_step.status = status
elif isinstance(status, MissionStatus):
self.state_machine.current_mission.status = status
Expand All @@ -126,6 +121,29 @@ def _run(self) -> None:
transition = self.state_machine.step_finished # type: ignore
break
else:
if (
isinstance(status, StepStatus)
and self.state_machine.current_task != None
):
if (
status != StepStatus.InProgress
and status != StepStatus.NotStarted
): # If task is done
self.state_machine.current_task.update_task_status()
else: # If not all steps are done
self.state_machine.current_task.status = TaskStatus.InProgress

self.state_machine.publish_task_status(
self.state_machine.current_task
)
if self.state_machine.current_task.status == TaskStatus.Successful:
try:
self.state_machine.current_task = (
self.state_machine.task_selector.next_task()
)
except TaskSelectorStop:
# Indicates that all tasks are finished
self.state_machine.current_task = None
if self._mission_finished(self.state_machine.current_mission):
transition = self.state_machine.full_mission_finished # type: ignore
break
Expand Down

0 comments on commit 7f20e97

Please sign in to comment.