Skip to content

Commit

Permalink
Split task finished function for modularity
Browse files Browse the repository at this point in the history
  • Loading branch information
aeshub committed Feb 27, 2023
1 parent a0fa2de commit 4a93cfd
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 12 deletions.
30 changes: 19 additions & 11 deletions src/isar/models/mission/mission.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,13 @@
from isar.config.settings import settings
from isar.models.mission_metadata.mission_metadata import MissionMetadata
from robot_interface.models.mission import (
STEPS,
InspectionStep,
MotionStep,
STEPS,
Step,
StepStatus,
)
from robot_interface.models.mission.step import DriveToPose

from .status import MissionStatus, TaskStatus


Expand All @@ -36,8 +35,7 @@ def is_finished(self) -> bool:
for step in self.steps:
if step.status is StepStatus.Failed and isinstance(step, MotionStep):
# One motion step has failed meaning the task as a whole should be
# aborted
self.status = TaskStatus.Failed
# considered as failed
return True

elif (step.status is StepStatus.Failed) and isinstance(
Expand All @@ -46,7 +44,6 @@ def is_finished(self) -> bool:
# It should be possible to perform several inspections per task. If
# one out of many inspections fail the task is considered as
# partially successful.
self.status = TaskStatus.PartiallySuccessful
continue

elif step.status is StepStatus.Successful:
Expand All @@ -56,18 +53,29 @@ def is_finished(self) -> bool:
# Not all steps have been completed yet
return False

# Check if the task has been marked as partially successful by having one or
# more inspection steps fail
return True

def update_task_status(self) -> None:
for step in self.steps:
if step.status is StepStatus.Failed and isinstance(step, MotionStep):
self.status = TaskStatus.Failed
return

elif (step.status is StepStatus.Failed) and isinstance(
step, InspectionStep
):
self.status = TaskStatus.PartiallySuccessful
continue

elif step.status is StepStatus.Successful:
continue

if self.status is not TaskStatus.PartiallySuccessful:
# All steps have been completed
self.status = TaskStatus.Successful

# Set the task to failed if all inspection steps failed
elif self._all_inspection_steps_failed():
self.status = TaskStatus.Failed

return True

def reset_task(self):
for step in self.steps:
if isinstance(step, DriveToPose):
Expand Down
3 changes: 2 additions & 1 deletion src/isar/state_machine/state_machine.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ def _stop(self) -> None:

def _initiate_step_failed(self) -> None:
self.current_step.status = StepStatus.Failed
_ = self.current_task.is_finished()
self.current_task.update_task_status()
self.current_mission.status = MissionStatus.Failed
self.publish_step_status()
self.publish_task_status()
Expand Down Expand Up @@ -365,6 +365,7 @@ def begin(self):

def update_current_task(self):
if self.current_task.is_finished():
self.current_task.update_task_status()
self.publish_task_status()
try:
self.current_task = self.task_selector.next_task()
Expand Down

0 comments on commit 4a93cfd

Please sign in to comment.