Skip to content

Commit

Permalink
Reintroduce isar task id in mission task definition
Browse files Browse the repository at this point in the history
for Flotilla to be able to match its existing task request to the
one that is returned from ISAR
  • Loading branch information
tsundvoll committed Dec 12, 2024
1 parent c8ff71c commit 2bceae8
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 40 deletions.
130 changes: 92 additions & 38 deletions src/isar/apis/models/start_mission_definition.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions src/robot_interface/models/mission/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand All @@ -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)
Expand Down

0 comments on commit 2bceae8

Please sign in to comment.