Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
andchiind committed Apr 17, 2024
1 parent e80c040 commit 279a0de
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
8 changes: 6 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,8 @@ 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:
# TODO: occurs when mission is for a different site. We should compare robot and mission locations before running them
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
8 changes: 5 additions & 3 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 All @@ -262,7 +264,7 @@ def step_status(self) -> StepStatus:
try:
step: List[str] = list(
filter(lambda step: current_task_id in step, self.mission_task_ids)
)[0]
)[0] # TODO: get all steps and figure out what is actually being executed. Return step status not task status
task_index: int = self.mission_task_ids.index(step)
except ValueError or IndexError:
value_error_message: str = (
Expand Down

0 comments on commit 279a0de

Please sign in to comment.