Skip to content

Commit

Permalink
Avoid excess site updates
Browse files Browse the repository at this point in the history
  • Loading branch information
andchiind committed Jan 9, 2024
1 parent 11a63b3 commit f3a3fc3
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 15 deletions.
29 changes: 29 additions & 0 deletions src/isar_exr/api/energy_robotics_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,35 @@ def pause_current_mission(self, exr_robot_id: str) -> None:
raise RobotMissionStatusException(
error_description=f"Invalid status after pausing mission: '{status}'"
)

def get_point_of_interest_by_customer_tag(
self, customer_tag: str, site_id: str
) -> str:
variable_definitions_graphql: DSLVariableDefinitions = DSLVariableDefinitions()

point_of_interest_query: DSLQuery = DSLQuery(
self.schema.Query.pointOfInterestByCustomerTag.args(
customerTag=variable_definitions_graphql.customerTag, siteId=variable_definitions_graphql.siteId
).select(self.schema.PointOfInterestType.id)
)

point_of_interest_query.variable_definitions = (
variable_definitions_graphql
)

params: dict = {"customerTag": customer_tag, "siteId": site_id}

try:
response_dict: dict[str, Any] = self.client.query(
dsl_gql(point_of_interest_query), params
)
except Exception:
return None

if response_dict["pointOfInterestByCustomerTag"] is None:
raise None

return response_dict["pointOfInterestByCustomerTag"]["id"]

def create_point_of_interest(
self, point_of_interest_input: AddPointOfInterestInput
Expand Down
4 changes: 4 additions & 0 deletions src/isar_exr/api/models/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ class AddPointOfInterestInput(BaseModel):
photoAction: Optional[PointOfInterestActionPhotoInput] = None
videoAction: Optional[PointOfInterestActionVideoInput] = None

class PointOfInterestByCustomerTag(BaseModel):
customerTag: str
siteId: str


class RobotTypeEnum(str, Enum):
SPOT: str = "SPOT"
Expand Down
2 changes: 1 addition & 1 deletion src/isar_exr/config/settings.env
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
CAPABILITIES = '["take_image", "take_video", "drive_to_pose", "take_thermal_image"]'
CAPABILITIES = '["take_image", "take_video", "drive_to_pose", "take_thermal_image", "localize"]'
ROBOT_MODEL = ExR2
41 changes: 27 additions & 14 deletions src/isar_exr/robotinterface.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
Point3DInput,
PointOfInterestActionPhotoInput,
PointOfInterestActionVideoInput,
PointOfInterestByCustomerTag,
PointOfInterestTypeEnum,
Pose3DInput,
Pose3DStampedInput,
Expand Down Expand Up @@ -90,26 +91,34 @@ def initiate_mission(self, mission: Mission) -> None:
curent_stage_id = self.api.get_current_site_stage(settings.ROBOT_EXR_SITE_ID)
if curent_stage_id is not None:
self.api.discard_stage(stage_id=curent_stage_id)
stage_id: str = self.api.create_stage(site_id=settings.ROBOT_EXR_SITE_ID)
stage_id: str = self.api.create_stage(site_id=settings.ROBOT_EXR_SITE_ID) # Do we need a new stage here?
updating_site = False
poi_ids: List[str] = []
for task in mission.tasks:
for step in task.steps:
if isinstance(step, DriveToPose):
robot_pose: Pose = step.pose
if isinstance(step, InspectionStep):
poi_id: str = self._create_and_add_poi(
task=task, step=step, robot_pose=robot_pose, stage_id=stage_id
)
poi_ids.append(poi_id)

snapshot_id: str = self.api.commit_site_to_snapshot(stage_id=stage_id)

self.api.set_snapshot_as_head(
snapshot_id=snapshot_id, site_id=settings.ROBOT_EXR_SITE_ID
)
existing_poi_id = self.api.get_point_of_interest_by_customer_tag(customer_tag=task.tag_id, site_id=settings.ROBOT_EXR_SITE_ID)
if (existing_poi_id == None):
poi_id: str = self._create_and_add_poi( # Here we should only create if it does not already exist
task=task, step=step, robot_pose=robot_pose, stage_id=stage_id
)
poi_ids.append(poi_id)
updating_site = True
else:
poi_ids.append(existing_poi_id)

if updating_site:
# We should only do the following if we changed the site
snapshot_id: str = self.api.commit_site_to_snapshot(stage_id=stage_id)

self.api.set_snapshot_as_head(
snapshot_id=snapshot_id, site_id=settings.ROBOT_EXR_SITE_ID
)

while not self.api.is_pipeline_completed(site_id=settings.ROBOT_EXR_SITE_ID):
time.sleep(settings.API_SLEEP_TIME)
while not self.api.is_pipeline_completed(site_id=settings.ROBOT_EXR_SITE_ID):
time.sleep(settings.API_SLEEP_TIME)

mission_definition_id: str = self.api.create_mission_definition(
site_id=settings.ROBOT_EXR_SITE_ID,
Expand All @@ -136,6 +145,10 @@ def initiate_mission(self, mission: Mission) -> None:
mission_definition_id=mission_definition_id, robot_id=settings.ROBOT_EXR_ID
)

# TODO: maybe store current mission, so that we can interpret idle but with mission as not idle

time.sleep(5) # Waits for mission to start in order to avoid returning Successful to ISAR

def mission_status(self) -> MissionStatus:
try:
return self.api.get_mission_status(settings.ROBOT_EXR_ID)
Expand Down Expand Up @@ -278,7 +291,7 @@ def _create_and_add_poi(
)

add_point_of_interest_input: dict[str, PointOfInterestActionPhotoInput] = {
"name": step.id,
"name": task.tag_id if task.tag_id != None else step.id,
"customerTag": task.tag_id,
"frame": "map",
"type": PointOfInterestTypeEnum.GENERIC,
Expand Down

0 comments on commit f3a3fc3

Please sign in to comment.