From 2bceae805609a57c6bba4a69bb9dc3444f582abe Mon Sep 17 00:00:00 2001 From: Thomas Sundvoll <35451859+tsundvoll@users.noreply.github.com> Date: Thu, 12 Dec 2024 15:14:13 +0100 Subject: [PATCH] Reintroduce isar task id in mission task definition for Flotilla to be able to match its existing task request to the one that is returned from ISAR --- .../apis/models/start_mission_definition.py | 130 +++++++++++++----- src/robot_interface/models/mission/task.py | 4 +- 2 files changed, 94 insertions(+), 40 deletions(-) diff --git a/src/isar/apis/models/start_mission_definition.py b/src/isar/apis/models/start_mission_definition.py index bc572593..fb97d95d 100644 --- a/src/isar/apis/models/start_mission_definition.py +++ b/src/isar/apis/models/start_mission_definition.py @@ -46,6 +46,7 @@ class StartMissionInspectionDefinition(BaseModel): class StartMissionTaskDefinition(BaseModel): + id: Optional[str] = None type: TaskType = Field(default=TaskType.Inspection) pose: InputPose inspection: Optional[StartMissionInspectionDefinition] = None @@ -115,48 +116,101 @@ def to_inspection_task(task_definition: StartMissionTaskDefinition) -> TASKS: inspection_definition = task_definition.inspection if inspection_definition.type == InspectionTypes.image: - return TakeImage( - robot_pose=task_definition.pose.to_alitra_pose(), - tag_id=task_definition.tag, - target=task_definition.inspection.inspection_target.to_alitra_position(), - metadata=task_definition.inspection.metadata, - zoom=task_definition.zoom, - ) + if task_definition.id: + return TakeImage( + id=task_definition.id, + robot_pose=task_definition.pose.to_alitra_pose(), + tag_id=task_definition.tag, + target=task_definition.inspection.inspection_target.to_alitra_position(), + metadata=task_definition.inspection.metadata, + zoom=task_definition.zoom, + ) + else: + return TakeImage( + robot_pose=task_definition.pose.to_alitra_pose(), + tag_id=task_definition.tag, + target=task_definition.inspection.inspection_target.to_alitra_position(), + metadata=task_definition.inspection.metadata, + zoom=task_definition.zoom, + ) elif inspection_definition.type == InspectionTypes.video: - return TakeVideo( - robot_pose=task_definition.pose.to_alitra_pose(), - tag_id=task_definition.tag, - target=task_definition.inspection.inspection_target.to_alitra_position(), - duration=inspection_definition.duration, - metadata=task_definition.inspection.metadata, - zoom=task_definition.zoom, - ) + if task_definition.id: + return TakeVideo( + id=task_definition.id, + robot_pose=task_definition.pose.to_alitra_pose(), + tag_id=task_definition.tag, + target=task_definition.inspection.inspection_target.to_alitra_position(), + duration=inspection_definition.duration, + metadata=task_definition.inspection.metadata, + zoom=task_definition.zoom, + ) + else: + return TakeVideo( + robot_pose=task_definition.pose.to_alitra_pose(), + tag_id=task_definition.tag, + target=task_definition.inspection.inspection_target.to_alitra_position(), + duration=inspection_definition.duration, + metadata=task_definition.inspection.metadata, + zoom=task_definition.zoom, + ) elif inspection_definition.type == InspectionTypes.thermal_image: - return TakeThermalImage( - robot_pose=task_definition.pose.to_alitra_pose(), - tag_id=task_definition.tag, - target=task_definition.inspection.inspection_target.to_alitra_position(), - metadata=task_definition.inspection.metadata, - zoom=task_definition.zoom, - ) + if task_definition.id: + return TakeThermalImage( + id=task_definition.id, + robot_pose=task_definition.pose.to_alitra_pose(), + tag_id=task_definition.tag, + target=task_definition.inspection.inspection_target.to_alitra_position(), + metadata=task_definition.inspection.metadata, + zoom=task_definition.zoom, + ) + else: + return TakeThermalImage( + robot_pose=task_definition.pose.to_alitra_pose(), + tag_id=task_definition.tag, + target=task_definition.inspection.inspection_target.to_alitra_position(), + metadata=task_definition.inspection.metadata, + zoom=task_definition.zoom, + ) elif inspection_definition.type == InspectionTypes.thermal_video: - return TakeThermalVideo( - robot_pose=task_definition.pose.to_alitra_pose(), - tag_id=task_definition.tag, - target=task_definition.inspection.inspection_target.to_alitra_position(), - duration=inspection_definition.duration, - metadata=task_definition.inspection.metadata, - zoom=task_definition.zoom, - ) + if task_definition.id: + return TakeThermalVideo( + id=task_definition.id, + robot_pose=task_definition.pose.to_alitra_pose(), + tag_id=task_definition.tag, + target=task_definition.inspection.inspection_target.to_alitra_position(), + duration=inspection_definition.duration, + metadata=task_definition.inspection.metadata, + zoom=task_definition.zoom, + ) + else: + return TakeThermalVideo( + robot_pose=task_definition.pose.to_alitra_pose(), + tag_id=task_definition.tag, + target=task_definition.inspection.inspection_target.to_alitra_position(), + duration=inspection_definition.duration, + metadata=task_definition.inspection.metadata, + zoom=task_definition.zoom, + ) elif inspection_definition.type == InspectionTypes.audio: - return RecordAudio( - robot_pose=task_definition.pose.to_alitra_pose(), - tag_id=task_definition.tag, - target=task_definition.inspection.inspection_target.to_alitra_position(), - duration=inspection_definition.duration, - metadata=task_definition.inspection.metadata, - zoom=task_definition.zoom, - ) + if task_definition.id: + return RecordAudio( + id=task_definition.id, + robot_pose=task_definition.pose.to_alitra_pose(), + tag_id=task_definition.tag, + target=task_definition.inspection.inspection_target.to_alitra_position(), + duration=inspection_definition.duration, + metadata=task_definition.inspection.metadata, + zoom=task_definition.zoom, + ) + else: + return RecordAudio( + robot_pose=task_definition.pose.to_alitra_pose(), + tag_id=task_definition.tag, + target=task_definition.inspection.inspection_target.to_alitra_position(), + duration=inspection_definition.duration, + metadata=task_definition.inspection.metadata, + zoom=task_definition.zoom, + ) else: raise ValueError( f"Inspection type '{inspection_definition.type}' not supported" diff --git a/src/robot_interface/models/mission/task.py b/src/robot_interface/models/mission/task.py index 27c85981..b68c4bea 100644 --- a/src/robot_interface/models/mission/task.py +++ b/src/robot_interface/models/mission/task.py @@ -38,7 +38,7 @@ class Task(BaseModel): status: TaskStatus = Field(default=TaskStatus.NotStarted) error_message: Optional[ErrorMessage] = Field(default=None) tag_id: Optional[str] = Field(default=None) - id: str = Field(default_factory=uuid4_string) + id: str = Field(default_factory=uuid4_string, frozen=True) def is_finished(self) -> bool: if ( @@ -59,7 +59,7 @@ class InspectionTask(Task): Base class for all inspection tasks which produce results to be uploaded. """ - inspection_id: str = Field(default_factory=uuid4_string) + inspection_id: str = Field(default_factory=uuid4_string, frozen=True) robot_pose: Pose = Field(default=None, init=True) metadata: Optional[dict] = Field(default_factory=dict) zoom: Optional[ZoomDescription] = Field(default=None)