From afc40334b592f431c758df407f9146cb953aa557 Mon Sep 17 00:00:00 2001 From: haakonsf Date: Wed, 10 Apr 2024 16:13:59 +0200 Subject: [PATCH] Add configurability for return to home missions --- backend/api/Database/Models/MissionTask.cs | 11 ++++++++--- backend/api/EventHandlers/MqttEventHandler.cs | 4 ++-- backend/api/Services/Models/IsarStep.cs | 2 ++ 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/backend/api/Database/Models/MissionTask.cs b/backend/api/Database/Models/MissionTask.cs index 228a0c7f8..6fb0f5bd1 100644 --- a/backend/api/Database/Models/MissionTask.cs +++ b/backend/api/Database/Models/MissionTask.cs @@ -1,6 +1,5 @@ using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; -using System.Globalization; using Api.Controllers.Models; using Api.Services.Models; using Api.Utilities; @@ -175,8 +174,14 @@ public void UpdateStatus(IsarTaskStatus isarStatus) public static string ConvertMissionTaskTypeToIsarTaskType(MissionTaskType missionTaskType) { - if (missionTaskType == MissionTaskType.ReturnHome) { return "drive_to"; } - else { return missionTaskType.ToString().ToLower(CultureInfo.CurrentCulture); } + return missionTaskType switch + { + MissionTaskType.ReturnHome => "return_to_home", + MissionTaskType.Localization => "localization", + MissionTaskType.Inspection => "inspection", + _ => throw new ArgumentException($"ISAR Mission task type '{missionTaskType}' not supported"), + }; + ; } } diff --git a/backend/api/EventHandlers/MqttEventHandler.cs b/backend/api/EventHandlers/MqttEventHandler.cs index a735cb27c..3be7d54a4 100644 --- a/backend/api/EventHandlers/MqttEventHandler.cs +++ b/backend/api/EventHandlers/MqttEventHandler.cs @@ -329,9 +329,9 @@ private async void OnIsarStepUpdate(object? sender, MqttReceivedArgs mqttArgs) var step = (IsarStepMessage)mqttArgs.Message; - // Flotilla does not care about DriveTo, Localization or MoveArm steps + // Flotilla does not care about DriveTo, Localization, MoveArm or ReturnToHome steps var stepType = IsarStep.StepTypeFromString(step.StepType); - if (stepType is IsarStepType.DriveToPose or IsarStepType.Localize or IsarStepType.MoveArm) return; + if (stepType is IsarStepType.DriveToPose or IsarStepType.Localize or IsarStepType.MoveArm or IsarStepType.ReturnToHome) return; IsarStepStatus status; try { status = IsarStep.StatusFromString(step.Status); } diff --git a/backend/api/Services/Models/IsarStep.cs b/backend/api/Services/Models/IsarStep.cs index 16ef16a40..0c19c7716 100644 --- a/backend/api/Services/Models/IsarStep.cs +++ b/backend/api/Services/Models/IsarStep.cs @@ -36,6 +36,7 @@ public static IsarStepType StepTypeFromString(string isarClassName) "TakeThermalImage" => IsarStepType.TakeThermalImage, "TakeThermalVideo" => IsarStepType.TakeThermalVideo, "Localize" => IsarStepType.Localize, + "ReturnToHome" => IsarStepType.ReturnToHome, "MoveArm" => IsarStepType.MoveArm, _ => throw new ArgumentException( @@ -58,6 +59,7 @@ public enum IsarStepType { DriveToPose, Localize, + ReturnToHome, TakeImage, TakeVideo, TakeThermalImage,