Skip to content

Commit

Permalink
WIP: always assume step_status reported
Browse files Browse the repository at this point in the history
  • Loading branch information
andchiind committed Apr 11, 2024
1 parent c46fe56 commit 91d105e
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 90 deletions.
54 changes: 15 additions & 39 deletions src/isar/state_machine/state_machine.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
64 changes: 13 additions & 51 deletions src/isar/state_machine/states/monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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] = (
Expand Down Expand Up @@ -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}"
Expand All @@ -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
Expand Down Expand Up @@ -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

0 comments on commit 91d105e

Please sign in to comment.