This commit is contained in:
Đăng Nguyễn 2025-12-30 15:17:42 +07:00
parent a51cfe80c8
commit 2785a8f161
9 changed files with 31 additions and 54 deletions

View File

@ -37,17 +37,15 @@
@if (CurrentState != null) @if (CurrentState != null)
{ {
<MudChip T="string" <MudChip T="string"
Icon="@(IsConnected Icon="@(IsConnected ? Icons.Material.Filled.CheckCircle : Icons.Material.Filled.Error)"
? Icons.Material.Filled.CheckCircle Size="Size.Large"
: Icons.Material.Filled.Error)" Color="@(IsConnected ? Color.Success : Color.Error)"
Size="Size.Large" Variant="Variant.Filled"
Color="@(IsConnected ? Color.Success : Color.Error)" Class="px-6 py-4 text-white"
Variant="Variant.Filled" Style="font-weight: bold; font-size: 1.1rem;">
Class="px-6 py-4 text-white" @(IsConnected ? "ONLINE" : "OFFLINE")
Style="font-weight: bold; font-size: 1.1rem;"> </MudChip>
@(IsConnected ? "ONLINE" : "OFFLINE") }
</MudChip>
}
</MudPaper> </MudPaper>
@ -152,7 +150,7 @@
Rounded="true" Rounded="true"
Striped="true" Striped="true"
Color="@(msg.BatteryState.BatteryCharge > 50 ? Color.Success : Color="@(msg.BatteryState.BatteryCharge > 50 ? Color.Success :
msg.BatteryState.BatteryCharge > 20 ? Color.Warning : Color.Error)" msg.BatteryState.BatteryCharge > 20 ? Color.Warning : Color.Error)"
Class="mb-4" Class="mb-4"
Style="height: 28px;" /> Style="height: 28px;" />
@ -266,7 +264,7 @@
<MudChip T="string" <MudChip T="string"
Size="Size.Small" Size="Size.Small"
Color="@(context.Level.Contains("ERROR", StringComparison.OrdinalIgnoreCase) ? Color.Error : Color="@(context.Level.Contains("ERROR", StringComparison.OrdinalIgnoreCase) ? Color.Error :
context.Level.Contains("WARN", StringComparison.OrdinalIgnoreCase) ? Color.Warning : Color.Info)" context.Level.Contains("WARN", StringComparison.OrdinalIgnoreCase) ? Color.Warning : Color.Info)"
Variant="@Variant.Filled"> Variant="@Variant.Filled">
@context.Level @context.Level
</MudChip> </MudChip>
@ -317,8 +315,8 @@
<MudChip T="string" <MudChip T="string"
Size="Size.Small" Size="Size.Small"
Color="@(context.ActionStatus == "RUNNING" ? Color.Info : Color="@(context.ActionStatus == "RUNNING" ? Color.Info :
context.ActionStatus == "FINISHED" ? Color.Success : context.ActionStatus == "FINISHED" ? Color.Success :
context.ActionStatus == "FAILED" ? Color.Error : Color.Default)" context.ActionStatus == "FAILED" ? Color.Error : Color.Default)"
Variant="@Variant.Filled"> Variant="@Variant.Filled">
@context.ActionStatus @context.ActionStatus
</MudChip> </MudChip>

View File

@ -46,3 +46,4 @@

View File

@ -127,20 +127,6 @@ public sealed class RobotStateClient : IAsyncDisposable
// ================= HANDLE STATE ================= // ================= HANDLE STATE =================
private void HandleState(StateMsg state) private void HandleState(StateMsg state)
{ {
//StateMsg? state;
//try
//{
// state = JsonSerializer.Deserialize<StateMsg>(
// stateJson,
// JsonOptionExtends.Read
// );
//}
//catch
//{
// return;
//}
if (state?.SerialNumber == null) if (state?.SerialNumber == null)
return; return;

View File

@ -64,3 +64,4 @@ window.robotMonitor = {

View File

@ -16,3 +16,4 @@ public class RobotMonitorHub : Hub

View File

@ -107,6 +107,8 @@ public class RobotErrors : IError
=> CreateError(ErrorType.INITIALIZE_ORDER, "Vui lòng kiểm tra lại OrderUpdateId", ErrorLevel.WARNING, $"OrderUpdateId {newOrderUpdateId} nhận được nhỏ hơn OrderUpdateId hiện tại là {oldOrderUpdateId}"); => CreateError(ErrorType.INITIALIZE_ORDER, "Vui lòng kiểm tra lại OrderUpdateId", ErrorLevel.WARNING, $"OrderUpdateId {newOrderUpdateId} nhận được nhỏ hơn OrderUpdateId hiện tại là {oldOrderUpdateId}");
public static Error Error1019() public static Error Error1019()
=> CreateError(ErrorType.INITIALIZE_ORDER, "Vui lòng kiểm tra lại Order", ErrorLevel.WARNING, "Order có node đầu tiên quá xa robot"); => CreateError(ErrorType.INITIALIZE_ORDER, "Vui lòng kiểm tra lại Order", ErrorLevel.WARNING, "Order có node đầu tiên quá xa robot");
public static Error Error1020()
=> CreateError(ErrorType.INITIALIZE_ORDER, "", ErrorLevel.WARNING, "Robot đang ở đích của Order");
public static Error Error2001() public static Error Error2001()
=> CreateError(ErrorType.READ_PERIPHERAL_FAILURE, "2001", ErrorLevel.FATAL, "Có lỗi xảy ra trong quá trình đọc tín hiệu từ hệ thống ngoại vi(PLC)"); => CreateError(ErrorType.READ_PERIPHERAL_FAILURE, "2001", ErrorLevel.FATAL, "Có lỗi xảy ra trong quá trình đọc tín hiệu từ hệ thống ngoại vi(PLC)");

View File

@ -403,6 +403,14 @@ public class RobotOrderController(INavigation NavigationManager,
var nodeDeviation = startNode.NodePosition.AllowedDeviationXY == 0.0 ? NewOrderHandler.Nodes.Length == 1 ? 0.3 : 0.5 : startNode.NodePosition.AllowedDeviationXY; var nodeDeviation = startNode.NodePosition.AllowedDeviationXY == 0.0 ? NewOrderHandler.Nodes.Length == 1 ? 0.3 : 0.5 : startNode.NodePosition.AllowedDeviationXY;
var distance = Localization.DistanceTo(startNode.NodePosition.X, startNode.NodePosition.Y); var distance = Localization.DistanceTo(startNode.NodePosition.X, startNode.NodePosition.Y);
if (distance > nodeDeviation) throw new OrderException(RobotErrors.Error1019()); if (distance > nodeDeviation) throw new OrderException(RobotErrors.Error1019());
if (NewOrderHandler.Nodes.Length > 1)
{
Node endNode = NewOrderHandler.Nodes[^1];
nodeDeviation = endNode.NodePosition.AllowedDeviationXY == 0.0 ? 0.2 : endNode.NodePosition.AllowedDeviationXY;
distance = Localization.DistanceTo(endNode.NodePosition.X, endNode.NodePosition.Y);
if (distance < nodeDeviation) throw new OrderException(RobotErrors.Error1020());
}
HandleNewOrder(NewOrderHandler); HandleNewOrder(NewOrderHandler);
} }
} }
@ -414,7 +422,7 @@ public class RobotOrderController(INavigation NavigationManager,
{ {
ErrorManager.AddError(orEx.Error, TimeSpan.FromSeconds(10)); ErrorManager.AddError(orEx.Error, TimeSpan.FromSeconds(10));
Logger.Warning($"Lỗi khi xử lí Order: {orEx.Error.ErrorDescription}"); Logger.Warning($"Lỗi khi xử lí Order: {orEx.Error.ErrorDescription}");
HandleOrderStop(); if (Nodes.Length == 0) HandleOrderStop();
} }
else Logger.Warning($"Lỗi khi xử lí Order: {orEx.Message}"); else Logger.Warning($"Lỗi khi xử lí Order: {orEx.Message}");
} }

View File

@ -17,8 +17,6 @@ public class RobotStatePublisher(
RobotStates _robotState, RobotStates _robotState,
RobotConnection _robotConnection) : BackgroundService RobotConnection _robotConnection) : BackgroundService
{ {
private bool? _lastRobotConnectionState;
private readonly PeriodicTimer _timer = new(TimeSpan.FromMilliseconds(1000)); // 1 giây/lần private readonly PeriodicTimer _timer = new(TimeSpan.FromMilliseconds(1000)); // 1 giây/lần
protected override async Task ExecuteAsync(CancellationToken stoppingToken) protected override async Task ExecuteAsync(CancellationToken stoppingToken)
@ -28,26 +26,8 @@ public class RobotStatePublisher(
try try
{ {
// ===== SEND STATE ===== // ===== SEND STATE =====
var state = _robotState.GetStateMsg(); await _hubContext.Clients.All.SendAsync("ReceiveState", _robotState.GetStateMsg(), stoppingToken);
//var json = JsonSerializer.Serialize(state, JsonOptionExtends.Write); await _hubContext.Clients.All.SendAsync("ReceiveRobotConnection", _robotConnection.IsConnected, stoppingToken);
await _hubContext.Clients.All
.SendAsync("ReceiveState", state, stoppingToken);
// ===== SEND ROBOT CONNECTION (ONLY WHEN CHANGED) =====
var isConnected = _robotConnection.IsConnected;
if (_lastRobotConnectionState != isConnected)
{
_lastRobotConnectionState = isConnected;
await _hubContext.Clients.All
.SendAsync(
"ReceiveRobotConnection",
isConnected, // payload only bool
stoppingToken
);
}
} }
catch catch
{ {

View File

@ -23,8 +23,8 @@ public class SimulationNavigation : INavigation, IDisposable
protected const int CycleHandlerMilliseconds = 50; protected const int CycleHandlerMilliseconds = 50;
private const double Scale = 1; private const double Scale = 1;
//private WatchTimer<SimulationNavigation>? NavigationTimer; private WatchTimer<SimulationNavigation>? NavigationTimer;
private HighPrecisionTimer<SimulationNavigation>? NavigationTimer; //private HighPrecisionTimer<SimulationNavigation>? NavigationTimer;
protected double TargetAngle = 0; protected double TargetAngle = 0;
protected PID? RotatePID; protected PID? RotatePID;