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 fa625cd commit 89bc79c
Show file tree
Hide file tree
Showing 5 changed files with 27 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
8 changes: 8 additions & 0 deletions backend/api/Services/RobotService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public interface IRobotService
public Task<Robot> Update(Robot robot);
public Task<Robot> UpdateRobotStatus(string robotId, RobotStatus status);
public Task<Robot> UpdateRobotBatteryLevel(string robotId, float batteryLevel);
public Task<Robot> UpdateRobotBatteryState(string robotId, BatteryState? batteryState);
public Task<Robot> UpdateRobotPressureLevel(string robotId, float? pressureLevel);
public Task<Robot> UpdateRobotPose(string robotId, Pose pose);
public Task<Robot> UpdateRobotIsarConnected(string robotId, bool isarConnected);
Expand Down Expand Up @@ -161,6 +162,13 @@ public async Task<Robot> UpdateRobotBatteryLevel(string robotId, float batteryLe
return robot;
}

public async Task<Robot> UpdateRobotBatteryState(string robotId, BatteryState? batteryState)
{
var robot = await UpdateRobotProperty(robotId, "BatteryState", batteryState, isLogLevelDebug: true);
ThrowIfRobotIsNull(robot, robotId);
return robot;
}

public async Task<Robot> UpdateRobotPressureLevel(string robotId, float? pressureLevel)
{
var robot = await UpdateRobotProperty(robotId, "PressureLevel", pressureLevel);
Expand Down

0 comments on commit 89bc79c

Please sign in to comment.