From 91d105e7fccc0fdbee6df7c474bb861e79708f2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anders=20Chirico=20Indreb=C3=B8?= Date: Thu, 11 Apr 2024 15:31:22 +0200 Subject: [PATCH] WIP: always assume step_status reported --- src/isar/state_machine/state_machine.py | 54 ++++++-------------- src/isar/state_machine/states/monitor.py | 64 +++++------------------- 2 files changed, 28 insertions(+), 90 deletions(-) diff --git a/src/isar/state_machine/state_machine.py b/src/isar/state_machine/state_machine.py index d9c00ba2..2578958e 100644 --- a/src/isar/state_machine/state_machine.py +++ b/src/isar/state_machine/state_machine.py @@ -1,7 +1,6 @@ import json import logging import queue -import time from collections import deque from datetime import datetime from typing import Deque, List, Optional @@ -12,7 +11,7 @@ from transitions.core import State from isar.apis.models.models import ControlMissionResponse -from isar.config.settings import robot_settings, settings +from isar.config.settings import settings from isar.mission_planner.task_selector_interface import ( TaskSelectorInterface, TaskSelectorStop, @@ -224,23 +223,14 @@ def _initialization_failed(self) -> None: self._finalize() def _initiated(self) -> None: - if self.stepwise_mission: - self.current_step.status = StepStatus.InProgress - self.publish_step_status(step=self.current_step) - self.logger.info( - f"Successfully initiated " - f"{type(self.current_step).__name__} " - f"step: {str(self.current_step.id)[:8]}" - ) - else: - if "step_status" in robot_settings.CAPABILITIES: - self.current_step.status = StepStatus.InProgress - self.publish_step_status(step=self.current_step) - self.current_mission.status = MissionStatus.InProgress - self.logger.info( - f"Successfully initiated full mission with ID: " - f"{str(self.current_mission.id)[:8]}" - ) + self.current_step.status = StepStatus.InProgress + self.current_mission.status = MissionStatus.InProgress + self.publish_step_status(step=self.current_step) + self.logger.info( + f"Successfully initiated " + f"{type(self.current_step).__name__} " + f"step: {str(self.current_step.id)[:8]}" + ) def _pause(self) -> None: return @@ -352,26 +342,12 @@ def _stop(self) -> None: self.stopped = True def _initiate_failed(self) -> None: - if self.stepwise_mission: - self.current_step.status = StepStatus.Failed - self.current_task.update_task_status() - self.current_mission.status = MissionStatus.Failed - self.publish_step_status(step=self.current_step) - self.publish_task_status(task=self.current_task) - self._finalize() - - else: - self.current_task = None - step_status: StepStatus = StepStatus.Cancelled - task_status: TaskStatus = TaskStatus.Cancelled - - for task in self.current_mission.tasks: - task.status = task_status - for step in task.steps: - step.status = step_status - self.publish_step_status(step=step) - self.publish_task_status(task=task) - self._finalize() + self.current_step.status = StepStatus.Failed + self.current_task.update_task_status() + self.current_mission.status = MissionStatus.Failed + self.publish_step_status(step=self.current_step) + self.publish_task_status(task=self.current_task) + self._finalize() def _initiate_infeasible(self) -> None: if self.stepwise_mission: diff --git a/src/isar/state_machine/states/monitor.py b/src/isar/state_machine/states/monitor.py index fbf3d31a..19d12a96 100644 --- a/src/isar/state_machine/states/monitor.py +++ b/src/isar/state_machine/states/monitor.py @@ -6,7 +6,6 @@ from injector import inject from transitions import State -from isar.config.settings import robot_settings, settings from isar.mission_planner.task_selector_interface import TaskSelectorStop from isar.services.utilities.threaded_request import ( ThreadedRequest, @@ -58,19 +57,10 @@ def _run(self) -> None: break if not self.step_status_thread: - if ( - self.state_machine.stepwise_mission - or "step_status" in robot_settings.CAPABILITIES - ): - 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] = ( @@ -102,13 +92,7 @@ def _run(self) -> None: except RobotException as e: self._set_error_message(e) - if ( - self.state_machine.stepwise_mission - or "step_status" in robot_settings.CAPABILITIES - ): - status = StepStatus.Failed - else: - status = MissionStatus.Failed + status = StepStatus.Failed self.logger.error( f"Retrieving the status failed because: {e.error_description}" @@ -134,10 +118,7 @@ def _run(self) -> None: transition = self.state_machine.step_finished # type: ignore break else: - if ( - isinstance(status, StepStatus) - and "step_status" in robot_settings.CAPABILITIES - ): + if isinstance(status, StepStatus): if ( status != StepStatus.InProgress and status != StepStatus.NotStarted @@ -227,34 +208,15 @@ def _mission_finished(mission: Mission) -> bool: return False def _should_upload_inspections(self) -> bool: - if ( - self.state_machine.stepwise_mission - or "step_status" in robot_settings.CAPABILITIES - ): - step: Step = self.state_machine.current_step - return ( - self._step_finished(step) - and step.status == StepStatus.Successful - and isinstance(step, InspectionStep) - ) - else: - mission_status: MissionStatus = self.state_machine.current_mission.status - if ( - mission_status == MissionStatus.Successful - or mission_status == MissionStatus.PartiallySuccessful - ): - return True - return False + step: Step = self.state_machine.current_step + return ( + self._step_finished(step) + and step.status == StepStatus.Successful + and isinstance(step, InspectionStep) + ) def _set_error_message(self, e: RobotException) -> None: error_message: ErrorMessage = ErrorMessage( error_reason=e.error_reason, error_description=e.error_description ) - if ( - self.state_machine.stepwise_mission - or "step_status" in robot_settings.CAPABILITIES - ): - self.state_machine.current_step.error_message = error_message - else: - if self.state_machine.current_mission: - self.state_machine.current_mission.error_message = error_message + self.state_machine.current_step.error_message = error_message