Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve safezone stability #1759

Merged
merged 6 commits into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions backend/api/Controllers/Models/UpdateRobotModelQuery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,10 @@ public struct UpdateRobotModelQuery
/// Lower pressure warning threshold in Bar
/// </summary>
public float? LowerPressureWarningThreshold { get; set; }

/// <summary>
/// Lower battery threshold at which to allow missions to be scheduled, in percentage
/// </summary>
public float? BatteryMissionStartThreshold { get; set; }
}
}
7 changes: 7 additions & 0 deletions backend/api/Database/Models/Robot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,13 @@ public bool IsRobotBatteryTooLow()
return Model.BatteryWarningThreshold >= BatteryLevel;
}

public bool IsRobotReadyToStartMissions()
{
if (IsRobotBatteryTooLow()) return false;
if (Model.BatteryMissionStartThreshold != null && Model.BatteryMissionStartThreshold > BatteryLevel) return false;
return !IsRobotPressureTooHigh() && !IsRobotPressureTooLow();
}

public IList<DocumentInfo> Documentation { get; set; }

public IList<VideoStream> VideoStreams { get; set; }
Expand Down
6 changes: 6 additions & 0 deletions backend/api/Database/Models/RobotModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ public RobotModel(CreateRobotModelQuery query)
/// </summary>
public float? LowerPressureWarningThreshold { get; set; }

/// <summary>
/// Lower battery threshold at which to allow missions to be scheduled, in percentage
/// </summary>
public float? BatteryMissionStartThreshold { get; set; }

/// <summary>
/// The average time in seconds spent by this model on a single tag (excluding recording duration for video/audio)
/// </summary>
Expand All @@ -69,6 +74,7 @@ public void Update(UpdateRobotModelQuery updateQuery)
BatteryWarningThreshold = updateQuery.BatteryWarningThreshold;
UpperPressureWarningThreshold = updateQuery.UpperPressureWarningThreshold;
LowerPressureWarningThreshold = updateQuery.LowerPressureWarningThreshold;
BatteryMissionStartThreshold = updateQuery.BatteryMissionStartThreshold;
}
}
}
7 changes: 3 additions & 4 deletions backend/api/EventHandlers/MissionEventHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,9 @@ private async void OnSendRobotToSafezoneTriggered(object? sender, RobotEmergency
return;
}

try { await MissionScheduling.FreezeMissionRunQueueForRobot(e.RobotId); }
catch (RobotNotFoundException) { return; }

if (robot.FlotillaStatus == e.RobotFlotillaStatus)
{
_logger.LogInformation("Did not send robot to safezone since robot {RobotId} was already in the correct state", e.RobotId);
Expand All @@ -182,10 +185,6 @@ private async void OnSendRobotToSafezoneTriggered(object? sender, RobotEmergency
return;
}

try { await MissionScheduling.FreezeMissionRunQueueForRobot(e.RobotId); }
catch (RobotNotFoundException) { return; }


Area? area;
try
{
Expand Down
4 changes: 2 additions & 2 deletions backend/api/EventHandlers/MqttEventHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ private async void OnIsarBatteryUpdate(object? sender, MqttReceivedArgs mqttArgs
_logger.LogInformation("Sending robot '{RobotName}' to its safe zone as its battery level is too low.", robot.Name);
EmergencyActionService.SendRobotToSafezone(new RobotEmergencyEventArgs(robot.Id, RobotFlotillaStatus.Recharging));
}
else if (robot.FlotillaStatus == RobotFlotillaStatus.Recharging && !(robot.IsRobotBatteryTooLow() || robot.IsRobotPressureTooHigh() || robot.IsRobotPressureTooLow()))
else if (robot.FlotillaStatus == RobotFlotillaStatus.Recharging && robot.IsRobotReadyToStartMissions())
{
_logger.LogInformation("Releasing robot '{RobotName}' from its safe zone as its battery and pressure levels are good enough to run missions.", robot.Name);
EmergencyActionService.ReleaseRobotFromSafezone(new RobotEmergencyEventArgs(robot.Id, RobotFlotillaStatus.Normal));
Expand All @@ -431,7 +431,7 @@ private async void OnIsarPressureUpdate(object? sender, MqttReceivedArgs mqttArg
_logger.LogInformation("Sending robot '{RobotName}' to its safe zone as its pressure is too low or high.", robot.Name);
EmergencyActionService.SendRobotToSafezone(new RobotEmergencyEventArgs(robot.Id, RobotFlotillaStatus.Recharging));
}
else if (robot.FlotillaStatus == RobotFlotillaStatus.Recharging && !(robot.IsRobotBatteryTooLow() || robot.IsRobotPressureTooHigh() || robot.IsRobotPressureTooLow()))
else if (robot.FlotillaStatus == RobotFlotillaStatus.Recharging && robot.IsRobotReadyToStartMissions())
{
_logger.LogInformation("Releasing robot '{RobotName}' from its safe zone as its battery and pressure levels are good enough to run missions.", robot.Name);
EmergencyActionService.ReleaseRobotFromSafezone(new RobotEmergencyEventArgs(robot.Id, RobotFlotillaStatus.Normal));
Expand Down
Loading
Loading