From c2fd0845cbef1bbb390dabf9fdd73bd9f84dbea3 Mon Sep 17 00:00:00 2001 From: Thomas Sundvoll <35451859+tsundvoll@users.noreply.github.com> Date: Tue, 3 Dec 2024 14:20:32 +0100 Subject: [PATCH] wip Set task.inspection.id on start_mission --- .../apis/models/start_mission_definition.py | 11 +++++ src/isar/script.py | 4 +- tests/isar/apis/models/__init__.py | 0 .../models/test_start_mission_definition.py | 44 +++++++++++++++++++ 4 files changed, 57 insertions(+), 2 deletions(-) create mode 100644 tests/isar/apis/models/__init__.py create mode 100644 tests/isar/apis/models/test_start_mission_definition.py diff --git a/src/isar/apis/models/start_mission_definition.py b/src/isar/apis/models/start_mission_definition.py index 655c6c98..de6dd047 100644 --- a/src/isar/apis/models/start_mission_definition.py +++ b/src/isar/apis/models/start_mission_definition.py @@ -12,6 +12,7 @@ from robot_interface.models.mission.task import ( TASKS, DockingProcedure, + InspectionTask, Localize, RecordAudio, ReturnToHome, @@ -69,7 +70,17 @@ def to_isar_mission(start_mission_definition: StartMissionDefinition) -> Mission for start_mission_task_definition in start_mission_definition.tasks: task: TASKS = create_isar_task(start_mission_task_definition) if start_mission_task_definition.id: + # If the id is None from the incoming start_mission_task_definition, we will + # just use the autogenerated id task.id = start_mission_task_definition.id + + if isinstance(task, InspectionTask): + if start_mission_task_definition.inspection.id: + # If the id is None from the incoming + # start_mission_task_definition.inspection, we will just use the + # autogenerated id + task.inspection.id = start_mission_task_definition.inspection.id + isar_tasks.append(task) if not isar_tasks: diff --git a/src/isar/script.py b/src/isar/script.py index ec023c86..853d4558 100644 --- a/src/isar/script.py +++ b/src/isar/script.py @@ -20,10 +20,10 @@ from isar.services.service_connections.mqtt.robot_info_publisher import ( RobotInfoPublisher, ) -from robot_interface.models.inspection.inspection import Inspection -from robot_interface.models.mission.mission import Mission from isar.state_machine.state_machine import StateMachine, main from isar.storage.uploader import Uploader +from robot_interface.models.inspection.inspection import Inspection +from robot_interface.models.mission.mission import Mission from robot_interface.robot_interface import RobotInterface diff --git a/tests/isar/apis/models/__init__.py b/tests/isar/apis/models/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/tests/isar/apis/models/test_start_mission_definition.py b/tests/isar/apis/models/test_start_mission_definition.py new file mode 100644 index 00000000..94dc2398 --- /dev/null +++ b/tests/isar/apis/models/test_start_mission_definition.py @@ -0,0 +1,44 @@ +from isar.apis.models.models import InputOrientation, InputPose, InputPosition +from isar.apis.models.start_mission_definition import ( + InspectionTypes, + StartMissionDefinition, + StartMissionInspectionDefinition, + StartMissionTaskDefinition, + TaskType, + to_isar_mission, +) +from robot_interface.models.mission.mission import Mission +from robot_interface.models.mission.task import TakeImage + + +def test_to_isar_mission(): + + DUMMY_MISSION_ID = "123-45-567" + DUMMY_MISSION_NAME = "mission_name" + DUMMY_ISAR_TASK_ID = "abc-de-fgh" + + inspection_definition = StartMissionInspectionDefinition( + type=InspectionTypes.image, + inspection_target=InputPosition(x=0, y=0, z=0), + id=DUMMY_ISAR_TASK_ID, + ) + task_pose = InputPose( + position=InputPosition(x=0, y=0, z=0), + orientation=InputOrientation(x=0, y=0, z=0, w=0), + ) + task_definition = StartMissionTaskDefinition( + type=TaskType.Inspection, pose=task_pose, inspection=inspection_definition + ) + mission_definition = StartMissionDefinition( + tasks=[task_definition], id=DUMMY_MISSION_ID, name=DUMMY_MISSION_NAME + ) + + # expected_task = TakeImage() + + # # expected_mission = Mission( + # # tasks=[expected_task], id=DUMMY_MISSION_ID, name=DUMMY_MISSION_NAME + # # ) + + resulting_isar_mission = to_isar_mission(mission_definition) + + assert resulting_isar_mission.tasks[0].inspection.id == DUMMY_ISAR_TASK_ID