Skip to content

Commit

Permalink
Improve stability of communication
Browse files Browse the repository at this point in the history
Handle a new authentication response.
Increase energy robotics API timeout.
Handle null values when fetching battery status.
Handle duplicate custom tags.
Handle getting step status before mission starts.
  • Loading branch information
andchiind committed Apr 17, 2024
1 parent e80c040 commit 9403f87
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
7 changes: 5 additions & 2 deletions src/isar_exr/api/energy_robotics_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -593,7 +593,10 @@ def get_battery_level(self, exr_robot_id: str) -> Optional[float]:
error_description=message,
)

if not result["currentRobotStatus"]["isConnected"]:
if result["currentRobotStatus"]["isConnected"] == None:
return None

if result["currentRobotStatus"]["batteryStatus"] == None or result["currentRobotStatus"]["batteryStatus"]["percentage"] == None:
return None

battery_level: float = result["currentRobotStatus"]["batteryStatus"][
Expand Down Expand Up @@ -696,7 +699,7 @@ def start_mission_execution(self, mission_definition_id: str, robot_id: str) ->
response_dict: dict[str, Any] = self.client.query(
dsl_gql(start_mission_execution_mutation), params
)
except Exception:
except Exception as e:
message: str = "Could not start mission execution"
self.logger.error(message)
raise RobotInfeasibleMissionException(
Expand Down
4 changes: 2 additions & 2 deletions src/isar_exr/api/graphql_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def _initialize_session(self) -> None:
schema: GraphQLSchema = build_ast_schema(self.document)

transport: HTTPXTransport = HTTPXTransport(
url=settings.ROBOT_API_URL, headers=auth_header
url=settings.ROBOT_API_URL, headers=auth_header, timeout=30
)
self.client: Client = Client(transport=transport, schema=schema) # type: ignore
self.schema: DSLSchema = DSLSchema(self.client.schema)
Expand Down Expand Up @@ -104,7 +104,7 @@ def query(
self.logger.error("The connection to the GraphQL endpoint is closed")
raise
except TransportServerError as e:
if e.code == 302:
if e.code == 302 or e.code == 401:
if self._reauthenticated:
self.logger.error(
"Transport server error - Error in Energy Robotics server even after reauthentication"
Expand Down
6 changes: 4 additions & 2 deletions src/isar_exr/robotinterface.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def update_site_with_tasks(
robot_pose: Pose = step.pose
if isinstance(step, InspectionStep):
is_possible_return_to_home_mission = False
customer_tag: str = task.tag_id + "|" + str(robot_pose)
customer_tag: str = task.tag_id + "|" + str(robot_pose) + "|" + str(step.target)
existing_poi_id = (
self.api.get_point_of_interest_by_customer_tag(
customer_tag=customer_tag,
Expand Down Expand Up @@ -216,6 +216,8 @@ def initiate_mission(self, mission: Mission) -> None:
mission_definition_id=mission_definition_id, robot_id=settings.ROBOT_EXR_ID
)

time.sleep(5)

def mission_status(self) -> MissionStatus:
try:
return self.api.get_mission_status(settings.ROBOT_EXR_ID)
Expand All @@ -241,7 +243,7 @@ def step_status(self) -> StepStatus:
step_status: StepStatus = ExrStepStatus(mission_status).to_step_status()
except NoMissionRunningException:
# This is a temporary solution until we have mission status by mission id
return MissionStatus.Successful
return StepStatus.NotStarted
except Exception as e:
message: str = "Could not get status of running mission\n"
self.logger.error(message)
Expand Down

0 comments on commit 9403f87

Please sign in to comment.