From 507d28f90ec6772b3e4d73a57aad59263031112b Mon Sep 17 00:00:00 2001
From: vincentlu <t1341870251@gmail.com>
Date: 星期五, 21 三月 2025 08:13:51 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/jbly' into jbly

---
 zy-acs-manager/src/main/java/com/zy/acs/manager/core/service/MainService.java |    2 +-
 zy-acs-manager/src/main/java/com/zy/acs/manager/core/service/MapService.java  |   14 +++++++++++++-
 2 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/zy-acs-manager/src/main/java/com/zy/acs/manager/core/service/MainService.java b/zy-acs-manager/src/main/java/com/zy/acs/manager/core/service/MainService.java
index 19e6b38..060eea6 100644
--- a/zy-acs-manager/src/main/java/com/zy/acs/manager/core/service/MainService.java
+++ b/zy-acs-manager/src/main/java/com/zy/acs/manager/core/service/MainService.java
@@ -667,7 +667,7 @@
             List<Action> actionList = new ArrayList<>();
             // start node
             Code lastCode = codeService.getCacheById(agvDetail.getRecentCode());
-            Double lastDirection = agvDetail.getAgvAngle();
+            Double lastDirection = MapService.mapToNearest(agvDetail.getAgvAngle());
             if (!lastCode.getData().equals(pathList.get(0))) {
                 throw new CoolException("AGV[" + agvNo + "]瀹氫綅鍋忕Щ...");
             }
diff --git a/zy-acs-manager/src/main/java/com/zy/acs/manager/core/service/MapService.java b/zy-acs-manager/src/main/java/com/zy/acs/manager/core/service/MapService.java
index 1f0817d..cb00614 100644
--- a/zy-acs-manager/src/main/java/com/zy/acs/manager/core/service/MapService.java
+++ b/zy-acs-manager/src/main/java/com/zy/acs/manager/core/service/MapService.java
@@ -123,6 +123,18 @@
         }).collect(Collectors.toList());
     }
 
+    public static Double mapToNearest(Double angle) {
+        if (null == angle) {
+            return null;
+        }
+        angle = (angle + 360) % 360;
+        double remainder = angle % 45;
+        if (remainder < 22.5) {
+            return angle - remainder;
+        } else {
+            return angle + (45 - remainder);
+        }
+    }
 
     // 瑙掑害璁$畻
     public Double calculateDirection(Code startCode, Code endCode, int angleOffsetVal) {
@@ -134,7 +146,7 @@
 
         double deltaX = x1 - x0;
         double deltaY = y1 - y0;
-        double angle = -Math.atan2(deltaX, deltaY);
+        double angle = Math.atan2(deltaX, deltaY);
         angle = Math.toDegrees(angle) + angleOffsetVal;
         angle = (angle + 360) % 360; // 灏嗚搴﹁浆鎹负姝e��
 

--
Gitblit v1.9.1