Skip to content

Commit

Permalink
Improve start missions with pressure/battery value
Browse files Browse the repository at this point in the history
  • Loading branch information
mrica-equinor committed May 2, 2024
1 parent 573e8f0 commit 3732f20
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 13 deletions.
21 changes: 8 additions & 13 deletions backend/api/Controllers/MissionSchedulingController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,11 @@ [FromBody] ScheduleMissionQuery scheduledMissionQuery

if (!robot.IsRobotPressureHighEnoughToStartMission())
{
return BadRequest($"The robot pressure on {robot.Name} is too low to start a mission");
return BadRequest($"Low pressure value for robot {robot.Name}, Pressure value is too low to start a mission.");
}

if (!robot.IsRobotBatteryLevelHighEnoughToStartMissions())
{
return BadRequest($"The robot battery level on {robot.Name} is too low to start a mission");
return BadRequest($"Low battery value for robot {robot.Name}. Battery value is too low to start a mission.");
}

var missionRun = await missionRunService.ReadById(missionRunId);
Expand Down Expand Up @@ -134,15 +133,13 @@ [FromBody] ScheduleMissionQuery scheduledMissionQuery
{
return NotFound($"Could not find robot with id {scheduledMissionQuery.RobotId}");
}

if (!robot.IsRobotPressureHighEnoughToStartMission())
{
return BadRequest($"The robot pressure on {robot.Name} is too low to start a mission");
return BadRequest($"Low pressure value for robot {robot.Name}, Pressure value is too low to start a mission.");
}

if (!robot.IsRobotBatteryLevelHighEnoughToStartMissions())
{
return BadRequest($"The robot battery level on {robot.Name} is too low to start a mission");
return BadRequest($"Low battery value for robot {robot.Name}. Battery value is too low to start a mission.");
}

var missionDefinition = await missionDefinitionService.ReadById(missionDefinitionId);
Expand Down Expand Up @@ -221,12 +218,11 @@ [FromBody] ScheduledMissionQuery scheduledMissionQuery

if (!robot.IsRobotPressureHighEnoughToStartMission())
{
return BadRequest($"The robot pressure on {robot.Name} is too low to start a mission");
return BadRequest($"Low pressure value for robot {robot.Name}, Pressure value is too low to start a mission.");
}

if (!robot.IsRobotBatteryLevelHighEnoughToStartMissions())
{
return BadRequest($"The robot battery level on {robot.Name} is too low to start a mission");
return BadRequest($"Low battery value for robot {robot.Name}. Battery value is too low to start a mission.");
}

EchoMission? echoMission;
Expand Down Expand Up @@ -394,12 +390,11 @@ [FromBody] CustomMissionQuery customMissionQuery

if (!robot.IsRobotPressureHighEnoughToStartMission())
{
return BadRequest($"The robot pressure on {robot.Name} is too low to start a mission");
return BadRequest($"Low pressure value for robot {robot.Name}, Pressure value is too low to start a mission.");
}

if (!robot.IsRobotBatteryLevelHighEnoughToStartMissions())
{
return BadRequest($"The robot battery level on {robot.Name} is too low to start a mission");
return BadRequest($"Low battery value for robot {robot.Name}. Battery value is too low to start a mission.");
}

var installation = await installationService.ReadByName(customMissionQuery.InstallationCode);
Expand Down
33 changes: 33 additions & 0 deletions backend/api/Services/MissionSchedulingService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,12 @@ public async Task StartNextMissionRunIfSystemIsAvailable(string robotId)
return;
}

if ((!robot.IsRobotPressureHighEnoughToStartMission() || !robot.IsRobotBatteryLevelHighEnoughToStartMissions()) && !missionRun.IsReturnHomeMission())
{
missionRun = await HandleBatteryAndPressureLevel(robot);
if (missionRun == null) { return; }
}

try { await StartMissionRun(missionRun); }
catch (Exception ex) when (
ex is MissionException
Expand All @@ -123,6 +129,33 @@ or MissionRunNotFoundException
}
}

public async Task<MissionRun?> HandleBatteryAndPressureLevel(Robot robot)
{
if (!robot.IsRobotPressureHighEnoughToStartMission())
{
logger.LogError("Robot with ID: {RobotId} cannot start missions because pressure value is too low.", robot.Id);
signalRService.ReportGeneralFailToSignalR(robot, $"Low pressure value for robot {robot.Name}", "Pressure value is too low to start a mission.");
}
if (!robot.IsRobotBatteryLevelHighEnoughToStartMissions())
{
logger.LogError("Robot with ID: {RobotId} cannot start missions because battery value is too low.", robot.Id);
signalRService.ReportGeneralFailToSignalR(robot, $"Low battery value for robot {robot.Name}", "Battery value is too low to start a mission.");
}

try { await AbortAllScheduledMissions(robot.Id, "Aborted: Robot pressure or battery values are too low."); }
catch (RobotNotFoundException) { logger.LogError("Failed to abort scheduled missions for robot {RobotId}", robot.Id); }

MissionRun? missionRun;
try { missionRun = await returnToHomeService.ScheduleReturnToHomeMissionRunIfNotAlreadyScheduledOrRobotIsHome(robot.Id); }
catch (ReturnToHomeMissionFailedToScheduleException)
{
logger.LogError("Failed to schedule a return to home mission for robot {RobotId}", robot.Id);
await robotService.UpdateCurrentArea(robot.Id, null);
return null;
}
return missionRun;
}

public async Task<bool> OngoingMission(string robotId)
{
var ongoingMissions = await GetOngoingMissions(robotId);
Expand Down
1 change: 1 addition & 0 deletions backend/api/Services/RobotService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -373,5 +373,6 @@ private void NotifySignalROfUpdatedRobot(Robot robot, Installation installation)
{
_ = signalRService.SendMessageAsync("Robot updated", installation, robot != null ? new RobotResponse(robot) : null);
}

}
}

0 comments on commit 3732f20

Please sign in to comment.