Skip to content

Commit

Permalink
Add safe zone exception
Browse files Browse the repository at this point in the history
  • Loading branch information
mrica-equinor committed Nov 1, 2023
1 parent 206038d commit 682ec73
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 3 deletions.
10 changes: 9 additions & 1 deletion backend/api/EventHandlers/MissionEventHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,15 @@ private async void OnEmergencyButtonPressedForRobot(object? sender, EmergencyBut
return;
}

await MissionSchedulingService.ScheduleMissionToReturnToSafePosition(e.RobotId, area.Id);
try
{
await MissionSchedulingService.ScheduleMissionToReturnToSafePosition(e.RobotId, area.Id);
}
catch (SafeZoneException ex)
{
_logger.LogError(ex, "Failed to schedule return to safe zone mission on robot {RobotName} because: {ErrorMessage}", robot.Name, ex.Message);
await MissionSchedulingService.UnfreezeMissionRunQueueForRobot(e.RobotId);
}

MqttEventHandlerService.TriggerRobotAvailable(new RobotAvailableEventArgs(robot.Id));

Expand Down
3 changes: 2 additions & 1 deletion backend/api/EventHandlers/MissionScheduling.cs
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,6 @@ public async Task StopCurrentMissionRun(string robotId)
return;
}


var ongoingMissions = await GetOngoingMission(robot.Id);

if (ongoingMissions == null)
Expand All @@ -196,6 +195,8 @@ public async Task StopCurrentMissionRun(string robotId)
{
foreach (var mission in ongoingMissions)
{
if (mission.MissionRunPriority == MissionRunPriority.Emergency) continue;

var newMission = new MissionRun
{
Name = mission.Name,
Expand Down
3 changes: 2 additions & 1 deletion backend/api/Services/MissionSchedulingService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ public Pose ClosestSafePosition(Pose robotPose, IList<SafePosition> safePosition
{
if (safePositions == null || !safePositions.Any())
{
throw new ArgumentException("List of safe positions cannot be null or empty.");
string message = "No safe position for area the robot is localized in";
throw new SafeZoneException(message);
}

var closestPose = safePositions[0].Pose;
Expand Down
5 changes: 5 additions & 0 deletions backend/api/Utilities/Exceptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,9 @@ public class DeckExistsException : Exception
{
public DeckExistsException(string message) : base(message) { }
}

public class SafeZoneException : Exception
{
public SafeZoneException(string message) : base(message) { }
}
}

0 comments on commit 682ec73

Please sign in to comment.