Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement stop button #140

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions src/isar_exr/api/energy_robotics_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
RobotInfeasibleMissionException,
RobotMapException,
RobotMissionStatusException,
RobotActionException,
)
from robot_interface.models.mission.status import MissionStatus

Expand Down Expand Up @@ -173,6 +174,50 @@ def pause_current_mission(self, exr_robot_id: str) -> None:
error_description=f"Invalid status after pausing mission: '{status}'"
)

def stop_current_mission(self, exr_robot_id: str) -> None:
params: dict = {"robotID": exr_robot_id}

variable_definitions_graphql: DSLVariableDefinitions = DSLVariableDefinitions()

stop_current_mission_mutation: DSLMutation = DSLMutation(
self.schema.Mutation.resetMissionExecution.args(
robotID=variable_definitions_graphql.robotID
).select(
self.schema.MissionExecutionType.id,
self.schema.MissionExecutionType.status,
self.schema.MissionExecutionType.failures,
)
)

stop_current_mission_mutation.variable_definitions = (
variable_definitions_graphql
)

try:
result: Dict[str, Any] = self.client.query(
dsl_gql(stop_current_mission_mutation), params
)
except TransportQueryError as e:
raise RobotActionException(
f"Could not stop the running mission since it is in a conflicting state: {e}"
)
except Exception as e:
raise RobotCommunicationException(
error_description=f"Could not stop the running mission: {e}",
)

status: ExrMissionStatus = ExrMissionStatus(
result["resetMissionExecution"]["status"]
)
success: bool = status in [
ExrMissionStatus.ResetRequested,
ExrMissionStatus.Completed,
]
if not success:
raise RobotMissionStatusException(
error_description=f"Invalid status after stopping mission: '{status}'"
)

def get_point_of_interest_by_customer_tag(
self, customer_tag: str, site_id: str
) -> str:
Expand Down
2 changes: 1 addition & 1 deletion src/isar_exr/models/step_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ class ExrMissionStatus(str, Enum):
StartRequested: str = "START_REQUESTED"
PauseRequested: str = "PAUSE_REQUESTED"
ResumeRequested: str = "RESUME_REQUESTED"
ResetRequested: str = "RESET_REQUESTED"
Rejected: str = "REJECTED"
WakingUp: str = "WAKING_UP"
Starting: str = "STARTING"
InProgress: str = "IN_PROGRESS"
Paused: str = "PAUSED"
Completed: str = "COMPLETED"
ResetRequested: str = "RESET_REQUESTED"

def to_mission_status(self) -> MissionStatus:
return {
Expand Down
29 changes: 21 additions & 8 deletions src/isar_exr/robotinterface.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
RobotMissionNotSupportedException,
RobotMissionStatusException,
RobotStepStatusException,
RobotActionException,
)
from robot_interface.models.initialize import InitializeParams
from robot_interface.models.inspection.inspection import Inspection
Expand Down Expand Up @@ -280,14 +281,26 @@ def step_status(self) -> StepStatus:
return step_status

def stop(self) -> None:
try:
self.api.pause_current_mission(self.exr_robot_id)
except Exception:
message: str = "Could not stop the running mission\n"
self.logger.error(message)
raise RobotCommunicationException(
error_description=message,
)
max_request_attempts: int = 10
stop_mission_attempts: int = 0
while stop_mission_attempts < max_request_attempts:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe a comment on why we need to try stopping so many times?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I'll test soon without these retries and see how reliable it is now that we have more error handling. We might not need the retries.

try:
self.api.stop_current_mission(self.exr_robot_id)
except RobotActionException as e:
self.logger.warning(f"Failed to stop current mission: {e.error_reason}")
stop_mission_attempts += 1
time.sleep(1)
continue
except Exception as e:
message: str = "Could not stop the running mission\n"
self.logger.error(message)
raise RobotCommunicationException(
error_description=message,
)
return
raise RobotActionException(
f"Failed to stop current mission after {stop_mission_attempts} failed attempts"
)

def get_inspections(self, step: InspectionStep) -> Sequence[Inspection]:
raise NotImplementedError
Expand Down
Loading