diff --git a/RobotApp.Client/Pages/Components/Monitor/RobotMonitorView.razor b/RobotApp.Client/Pages/Components/Monitor/RobotMonitorView.razor index 826bb53..3ece892 100644 --- a/RobotApp.Client/Pages/Components/Monitor/RobotMonitorView.razor +++ b/RobotApp.Client/Pages/Components/Monitor/RobotMonitorView.razor @@ -134,6 +134,7 @@ @code { + [Parameter] public RobotMonitorDto? MonitorData { get; set; } [Parameter] public bool IsConnected { get; set; } @@ -178,7 +179,7 @@ // Auto-follow robot private bool AutoFollowRobot = false; - + private void OnAutoFollowRobotChanged(bool value) { AutoFollowRobot = value; @@ -194,7 +195,7 @@ private const double MapImageOriginY = -20.0; // OriginY in world coordinates (meters) private const double MapImageResolution = 0.1; // Resolution: meters per pixel private const string MapImageUrl = "images/gara20250309.png"; - + private bool MapImageLoaded = false; private double MapImageWidth = 0; // Width in world coordinates (meters) private double MapImageHeight = 0; // Height in world coordinates (meters) @@ -233,11 +234,11 @@ try { var imageDimensions = await JS.InvokeAsync("robotMonitor.loadImageAndGetDimensions", MapImageUrl); - + // Convert pixel dimensions to world coordinates (meters) MapImageWidth = imageDimensions.Width * MapImageResolution; MapImageHeight = imageDimensions.Height * MapImageResolution; - + if (MapImageWidth > 0 && MapImageHeight > 0) { MapImageLoaded = true; @@ -278,16 +279,17 @@ // Kích thước robot trong world coordinates (mét) const double RobotWidthMeters = 0.606; const double RobotLengthMeters = 1.106; - + // Điều chỉnh kích thước dựa trên ZoomScale // Tăng kích thước lên 1.5x để robot to hơn double scaleFactor = 2 / ZoomScale; // Tăng kích thước hiển thị - + scaleFactor = scaleFactor < 1 ? 1 : scaleFactor; + double width = RobotWidthMeters * scaleFactor; double height = RobotLengthMeters * scaleFactor; double x = -width / 2; double y = -height / 2; - + return (x, y, width, height); } diff --git a/RobotApp/Services/HighPrecisionTimer.cs b/RobotApp/Services/HighPrecisionTimer.cs index 8e5ad70..8ad8716 100644 --- a/RobotApp/Services/HighPrecisionTimer.cs +++ b/RobotApp/Services/HighPrecisionTimer.cs @@ -116,7 +116,7 @@ public class HighPrecisionTimer(int Interval, Action Callback, Logger? Log Thread.Start(); } } - else throw new ObjectDisposedException(nameof(WatchTimer)); + else throw new ObjectDisposedException(nameof(HighPrecisionTimer)); } public void Stop() diff --git a/RobotApp/Services/Robot/RobotOrderController.cs b/RobotApp/Services/Robot/RobotOrderController.cs index bfd0aee..589e169 100644 --- a/RobotApp/Services/Robot/RobotOrderController.cs +++ b/RobotApp/Services/Robot/RobotOrderController.cs @@ -1,5 +1,4 @@ -using MudBlazor; -using RobotApp.Common.Shares.Dtos; +using RobotApp.Common.Shares.Dtos; using RobotApp.Common.Shares.Enums; using RobotApp.Interfaces; using RobotApp.Services.Exceptions; @@ -9,7 +8,6 @@ using RobotApp.VDA5050.Order; using RobotApp.VDA5050.State; using System.Collections.Concurrent; using System.Data; -using System.Xml.Linq; using Action = RobotApp.VDA5050.InstantAction.Action; namespace RobotApp.Services.Robot; @@ -31,7 +29,7 @@ public class RobotOrderController(INavigation NavigationManager, public int LastNodeSequenceId => LastNode is null ? 0 : LastNode.SequenceId; public (NodeState[], EdgeStateDto[]) CurrentPath => GetCurrentPath(); - private const int CycleHandlerMilliseconds = 100; + private const int CycleHandlerMilliseconds = 200; private WatchTimer? OrderTimer; private readonly Dictionary OrderActions = []; @@ -435,7 +433,7 @@ public class RobotOrderController(INavigation NavigationManager, private EdgeStateDto[] SplitChecking(Node lastNode, Node nearLastNode, VDA5050.Order.Edge edge) { List pathEdges = []; - var splitStartPath = RobotPathPlanner.PathSplit([lastNode, nearLastNode], [edge], 0.1); + var splitStartPath = RobotPathPlanner.PathSplit([lastNode, nearLastNode], [edge], 0.5); if (splitStartPath is not null && splitStartPath.Length > 0) { int index = 0; @@ -450,17 +448,31 @@ public class RobotOrderController(INavigation NavigationManager, index = i; } } - for (int i = index; i < splitStartPath.Length - 1; i++) + if (edge.Trajectory is null || edge.Trajectory.Degree == 1) { pathEdges.Add(new() { - StartX = splitStartPath[i].NodePosition.X, - StartY = splitStartPath[i].NodePosition.Y, - EndX = splitStartPath[i + 1].NodePosition.X, - EndY = splitStartPath[i + 1].NodePosition.Y, + StartX = splitStartPath[index].NodePosition.X, + StartY = splitStartPath[index].NodePosition.Y, + EndX = nearLastNode.NodePosition.X, + EndY = nearLastNode.NodePosition.Y, Degree = 1, }); } + else + { + for (int i = index; i < splitStartPath.Length - 1; i++) + { + pathEdges.Add(new() + { + StartX = splitStartPath[i].NodePosition.X, + StartY = splitStartPath[i].NodePosition.Y, + EndX = splitStartPath[i + 1].NodePosition.X, + EndY = splitStartPath[i + 1].NodePosition.Y, + Degree = 1, + }); + } + } } return [.. pathEdges]; } diff --git a/RobotApp/Services/Robot/RobotStatePublisher.cs b/RobotApp/Services/Robot/RobotStatePublisher.cs index a9061ff..c5222c7 100644 --- a/RobotApp/Services/Robot/RobotStatePublisher.cs +++ b/RobotApp/Services/Robot/RobotStatePublisher.cs @@ -1,14 +1,5 @@ using Microsoft.AspNetCore.SignalR; -using Microsoft.Extensions.Hosting; -using Microsoft.Extensions.Logging; -using RobotApp.Common.Shares; using RobotApp.Hubs; -using RobotApp.Interfaces; -using RobotApp.Services.State; -using RobotApp.VDA5050.State; -using RobotApp.VDA5050.Type; -using RobotApp.VDA5050.Visualization; -using System.Text.Json; namespace RobotApp.Services.Robot; diff --git a/RobotApp/Services/WatchTimerAsync.cs b/RobotApp/Services/WatchTimerAsync.cs index 4512275..6fb4f16 100644 --- a/RobotApp/Services/WatchTimerAsync.cs +++ b/RobotApp/Services/WatchTimerAsync.cs @@ -68,7 +68,7 @@ public class WatchTimerAsync(int Interval, Func Callback, Logger? Lo Timer.Change(Interval, Timeout.Infinite); } } - else throw new ObjectDisposedException(nameof(WatchTimer)); + else throw new ObjectDisposedException(nameof(WatchTimerAsync)); } public void Stop()