Skip to content

Commit

Permalink
Add batteryState to robot
Browse files Browse the repository at this point in the history
  • Loading branch information
Eddasol committed Dec 12, 2024
1 parent 37e3ee5 commit aecc67c
Show file tree
Hide file tree
Showing 8 changed files with 1,433 additions and 0 deletions.
3 changes: 3 additions & 0 deletions backend/api/Controllers/Models/RobotResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ public class RobotResponse

public float BatteryLevel { get; set; }

public BatteryState? BatteryState { get; set; }

public float? PressureLevel { get; set; }

public IList<DocumentInfo> Documentation { get; set; }
Expand Down Expand Up @@ -61,6 +63,7 @@ public RobotResponse(Robot robot)
CurrentInstallation = robot.CurrentInstallation;
CurrentArea = robot.CurrentArea != null ? new AreaResponse(robot.CurrentArea) : null;
BatteryLevel = robot.BatteryLevel;
BatteryState = robot.BatteryState;
PressureLevel = robot.PressureLevel;
Documentation = robot.Documentation;
VideoStreams = robot.VideoStreams;
Expand Down
8 changes: 8 additions & 0 deletions backend/api/Database/Models/Robot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ public Robot(CreateRobotQuery createQuery, Installation installation, RobotModel

public float BatteryLevel { get; set; }

public BatteryState? BatteryState { get; set; }

public float? PressureLevel { get; set; }

public bool IsRobotPressureTooLow()
Expand Down Expand Up @@ -192,4 +194,10 @@ public enum RobotCapabilitiesEnum
docking_procedure,
return_to_home,
}

public enum BatteryState
{
Normal,
Charging,
}
}
4 changes: 4 additions & 0 deletions backend/api/EventHandlers/MqttEventHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,10 @@ private async void OnIsarBatteryUpdate(object? sender, MqttReceivedArgs mqttArgs
_logger.LogDebug("Semaphore acquired for updating battery");

var robot = await BatteryTimeseriesService.AddBatteryEntry(batteryStatus.BatteryLevel, batteryStatus.IsarId);
if (robot != null && robot.BatteryState != batteryStatus.BatteryState)
{
robot = await RobotService.UpdateRobotBatteryState(robot.Id, batteryStatus.BatteryState);
}

_updateRobotSemaphore.Release();
_logger.LogDebug("Semaphore released after updating battery");
Expand Down
4 changes: 4 additions & 0 deletions backend/api/MQTT/MessageModels/IsarBattery.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Text.Json.Serialization;
using Api.Database.Models;

namespace Api.Mqtt.MessageModels
{
Expand All @@ -8,6 +9,9 @@ public class IsarBatteryMessage : MqttMessage
[JsonPropertyName("battery_level")]
public float BatteryLevel { get; set; }

[JsonPropertyName("battery_state")]
public BatteryState? BatteryState { get; set; }

[JsonPropertyName("robot_name")]
public string RobotName { get; set; }

Expand Down
Loading

0 comments on commit aecc67c

Please sign in to comment.