Skip to content

Commit

Permalink
Use robot batteryStartMissionThreshold
Browse files Browse the repository at this point in the history
  • Loading branch information
andchiind committed Oct 25, 2024
1 parent ede56fd commit b98b123
Show file tree
Hide file tree
Showing 7 changed files with 1,461 additions and 2 deletions.
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;
}
}
}
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

0 comments on commit b98b123

Please sign in to comment.