Skip to content

Commit

Permalink
Improve code quality
Browse files Browse the repository at this point in the history
  • Loading branch information
mrica-equinor committed Oct 11, 2024
1 parent 847487f commit b9300e8
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 36 deletions.
3 changes: 0 additions & 3 deletions src/isar/state_machine/state_machine.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,9 +288,6 @@ def _resume(self) -> None:
)
self.queues.resume_mission.output.put(resume_mission_response)

# self.current_task.reset_task()
# self.iterate_current_step()

self.robot.resume()

def _mission_finished(self) -> None:
Expand Down
4 changes: 2 additions & 2 deletions src/isar/state_machine/states/initiate.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
ErrorMessage,
RobotException,
RobotInfeasibleMissionException,
RobotInfeasibleStepException,
RobotInfeasibleTaskException,
)

if TYPE_CHECKING:
Expand Down Expand Up @@ -81,7 +81,7 @@ def _run(self) -> None:
except ThreadedRequestNotFinishedError:
time.sleep(self.state_machine.sleep_time)
continue
except RobotInfeasibleStepException as e:
except RobotInfeasibleTaskException as e:
self.state_machine.current_task.error_message = ErrorMessage(
error_reason=e.error_reason, error_description=e.error_description
)
Expand Down
6 changes: 3 additions & 3 deletions src/robot_interface/models/exceptions/robot_exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
class ErrorReason(str, Enum):
RobotCommunicationException: str = "robot_communication_exception"
RobotCommunicationTimeoutException: str = "robot_communication_timeout_exception"
RobotInfeasibleStepException: str = "robot_infeasible_step_exception"
RobotInfeasibleTaskException: str = "robot_infeasible_step_exception"
RobotInfeasibleMissionException: str = "robot_infeasible_mission_exception"
RobotMissionStatusException: str = "robot_mission_status_exception"
RobotStepStatusException: str = "robot_step_status_exception"
Expand Down Expand Up @@ -67,10 +67,10 @@ def __init__(self, error_description: str) -> None:

# An exception which should be thrown by the robot package if it is unable to start the
# current step.
class RobotInfeasibleStepException(RobotException):
class RobotInfeasibleTaskException(RobotException):
def __init__(self, error_description: str) -> None:
super().__init__(
error_reason=ErrorReason.RobotInfeasibleStepException,
error_reason=ErrorReason.RobotInfeasibleTaskException,
error_description=error_description,
)

Expand Down
51 changes: 25 additions & 26 deletions src/robot_interface/robot_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@
from robot_interface.models.initialize import InitializeParams
from robot_interface.models.inspection.inspection import Inspection
from robot_interface.models.mission.mission import Mission
from robot_interface.models.mission.status import MissionStatus, RobotStatus, TaskStatus
from robot_interface.models.mission.task import InspectionTask
from robot_interface.models.mission.task import Task
from robot_interface.models.mission.status import RobotStatus, TaskStatus
from robot_interface.models.mission.task import InspectionTask, Task


class RobotInterface(metaclass=ABCMeta):
Expand All @@ -19,7 +18,7 @@ def initiate_mission(self, mission: Mission) -> None:
"""Send a mission to the robot and initiate execution of the mission
This function should be used in combination with the mission_status function
if the robot is designed to run full missions and not in a stepwise
if the robot is designed to run full missions and not in a taskwise
configuration.
Parameters
Expand All @@ -39,36 +38,36 @@ def initiate_mission(self, mission: Mission) -> None:
Will catch all RobotExceptions not previously listed and retry scheduling of
the mission until the number of allowed retries is exceeded
NotImplementedError
If the robot is designed for stepwise mission execution
If the robot is designed for taskwise mission execution
"""
raise NotImplementedError

@abstractmethod
def initiate_task(self, task: Task) -> None:
"""Send a step to the robot and initiate the execution of the step
"""Send a task to the robot and initiate the execution of the task
This function should be used in combination with the step_status function
if the robot is designed to run stepwise missions and not in a full mission
This function should be used in combination with the task_status function
if the robot is designed to run taskwise missions and not in a full mission
configuration.
Parameters
----------
step : Step
The step that should be initiated on the robot.
task : Task
The task that should be initiated on the robot.
Returns
-------
None
Raises
------
RobotInfeasibleStepException
If the step input is infeasible and the step fails to be scheduled in
RobotInfeasibleTaskException
If the task input is infeasible and the task fails to be scheduled in
a way that means attempting to schedule again is not necessary
RobotException
Will catch all RobotExceptions not previously listed and retry scheduling
of the step until the number of allowed retries is exceeded before the step
of the task until the number of allowed retries is exceeded before the task
will be marked as failed and the mission cancelled
NotImplementedError
If the robot is designed for full mission execution.
Expand All @@ -78,21 +77,21 @@ def initiate_task(self, task: Task) -> None:

@abstractmethod
def task_status(self, task_id: str) -> TaskStatus:
"""Gets the status of the currently active step on robot.
"""Gets the status of the currently active task on robot.
This function should be used in combination with the initiate_step function
if the robot is designed to run stepwise missions and not in a full mission
This function should be used in combination with the initiate_task function
if the robot is designed to run taskwise missions and not in a full mission
configuration.
Returns
-------
StepStatus
Status of the execution of current step.
TaskStatus
Status of the execution of current task.
Raises
------
RobotException
If the step status could not be retrieved.
If the task status could not be retrieved.
NotImplementedError
If the robot is designed for full mission execution.
Expand All @@ -101,7 +100,7 @@ def task_status(self, task_id: str) -> TaskStatus:

@abstractmethod
def stop(self) -> None:
"""Stops the execution of the current step and stops the movement of the robot.
"""Stops the execution of the current task and stops the movement of the robot.
Returns
-------
Expand All @@ -120,7 +119,7 @@ def stop(self) -> None:

@abstractmethod
def pause(self) -> None:
"""Pauses the execution of the current step and stops the movement of the robot.
"""Pauses the execution of the current task and stops the movement of the robot.
Returns
-------
Expand All @@ -139,7 +138,7 @@ def pause(self) -> None:

@abstractmethod
def resume(self) -> None:
"""Resumes the execution of the current step and continues the rest of the mission.
"""Resumes the execution of the current task and continues the rest of the mission.
Returns
-------
Expand All @@ -158,22 +157,22 @@ def resume(self) -> None:

@abstractmethod
def get_inspection(self, task: InspectionTask) -> Inspection:
"""Return the inspections connected to the given step.
"""Return the inspection connected to the given task.
Parameters
----------
step : Step
task : InspectionTask
Returns
-------
Sequence[InspectionResult]
List containing all the inspection results connected to the given step
List containing all the inspection results connected to the given task
Raises
------
RobotRetrieveInspectionException
If the robot package is unable to retrieve the inspections for the relevant
mission or step an error message is logged and the state machine continues
mission or task an error message is logged and the state machine continues
RobotException
Catches other RobotExceptions that lead to the same result as a
RobotRetrieveInspectionException
Expand Down
4 changes: 2 additions & 2 deletions tests/isar/state_machine/test_state_machine.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ def test_state_machine_failed_dependency(
scheduling_utilities: SchedulingUtilities = injector.get(SchedulingUtilities)
scheduling_utilities.start_mission(mission=mission, initial_pose=None)

time.sleep(10)
time.sleep(3)
expected_transitions_list = deque(
[
States.Idle,
Expand Down Expand Up @@ -221,7 +221,7 @@ def test_state_machine_with_successful_collection(
scheduling_utilities: SchedulingUtilities = injector.get(SchedulingUtilities)

scheduling_utilities.start_mission(mission=mission, initial_pose=None)
time.sleep(10)
time.sleep(3)
expected_transitions_list = deque(
[
States.Idle,
Expand Down

0 comments on commit b9300e8

Please sign in to comment.