From c50f66695f4decb3786d11e4c5dfa515ce9a994b Mon Sep 17 00:00:00 2001
From: lsh <lsh@163.com>
Date: 星期二, 14 一月 2025 15:33:38 +0800
Subject: [PATCH] *

---
 src/main/java/com/zy/core/thread/RgvThread.java                   |    2 +
 src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java       |   18 +++++++--
 src/main/java/com/zy/core/model/protocol/RgvProtocol.java         |    1 
 src/main/java/com/zy/asrs/utils/SortTheExecutionOfTheCarUtil.java |   88 ++++++++++++++++++++++++++++++++++++++++++--
 src/main/resources/application.yml                                |    2 
 5 files changed, 102 insertions(+), 9 deletions(-)

diff --git a/src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java b/src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java
index 8353ed6..35dc5bd 100644
--- a/src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java
+++ b/src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java
@@ -267,10 +267,20 @@
                             && rgvProtocol.getTaskNo1() == 0
                             && rgvProtocol.getAlarm() == 0) {
                         if (rgvProtocol.getStatusType() == RgvStatusType.ROAM) {
-                            double finalVelocity = 0.0;     // 鏈�缁堥�熷害 (m/s)
-                            double distance = (Math.pow(finalVelocity, 2) - Math.pow(rgvProtocol.instantaneousSpeed / 60, 2)) / (2 * acceleration);
-                            BasDevpPosition basDevpPosition = basDevpPositionService.selectOne(new EntityWrapper<BasDevpPosition>().eq("dev_no", wrkMast.getSourceStaNo()));
-                            if (distance * proportion > ((SortTheExecutionOfTheCarUtil.LatelyAndLessThan(basDevpPosition.getPlcPosition(), rgvProtocol.getRgvPos(), perimeter) + (rgvProtocol.instantaneousSpeed / 60) * proportion * rgvDate))) {
+//                            double finalVelocity = 0.0;     // 鏈�缁堥�熷害 (m/s)
+//                            double distance = (Math.pow(finalVelocity, 2) - Math.pow(rgvProtocol.instantaneousSpeed / 60, 2)) / (2 * acceleration);
+//                            BasDevpPosition basDevpPosition = basDevpPositionService.selectOne(new EntityWrapper<BasDevpPosition>().eq("dev_no", wrkMast.getSourceStaNo()));
+//                            if (distance * proportion > ((SortTheExecutionOfTheCarUtil.LatelyAndLessThan(basDevpPosition.getPlcPosition(), rgvProtocol.getRgvPos(), perimeter) + (rgvProtocol.instantaneousSpeed / 60) * proportion * rgvDate))) {
+//                                continue;
+//                            }
+                            List<BasDevpPosition> basDevpPositions = basDevpPositionService.selectList(new EntityWrapper<BasDevpPosition>().orderBy("plc_position", true));
+                            if (basDevpPositions.isEmpty()) {
+                                log.error("鑾峰彇鎵�鏈夌珯鐐逛俊鎭紓甯�,RGV浠诲姟涓嬪彂澶辫触锛岃鑱旂郴绠$悊鍛橈紒锛侊紒");
+                                break runRgv;
+                            }
+                            List<Integer> devpList = SortTheExecutionOfTheCarUtil.BasDevpPositionExtractSites(basDevpPositions);
+
+                            if (!SortTheExecutionOfTheCarUtil.calculateShortestDistanceDirection(devpList,wrkMast.getSourceStaNo().intValue(),rgvProtocol.getEndStaM().intValue())){
                                 continue;
                             }
                         }
diff --git a/src/main/java/com/zy/asrs/utils/SortTheExecutionOfTheCarUtil.java b/src/main/java/com/zy/asrs/utils/SortTheExecutionOfTheCarUtil.java
index 77a1873..7590c64 100644
--- a/src/main/java/com/zy/asrs/utils/SortTheExecutionOfTheCarUtil.java
+++ b/src/main/java/com/zy/asrs/utils/SortTheExecutionOfTheCarUtil.java
@@ -462,16 +462,96 @@
     public static Double LatelyAndLessThan(long devPosition,long rgvPosition,long perimeter){
         long Difference = perimeter;
         if (devPosition >= rgvPosition){
-            if ((devPosition-rgvPosition) < Difference){
+//            if ((devPosition-rgvPosition) < Difference){
                 Difference = devPosition-rgvPosition;
-            }
+//            }
         } else {
-            if (perimeter - (rgvPosition - devPosition) < Difference){
+//            if (perimeter - (rgvPosition - devPosition) < Difference){
                 Difference = perimeter - (rgvPosition - devPosition);
-            }
+//            }
         }
         return Double.valueOf(Difference);
     }
 
+    public static int calculateShortestDistanceDistance(List<Integer> data, int a, int b) {
+        Result result = calculateShortestDistance(data, a, b);
+        return result.distance;
+    }
+
+    public static List<Integer> calculateShortestDistancePassedData(List<Integer> data, int a, int b) {
+        Result result = calculateShortestDistance(data, a, b);
+        return result.passedData;
+    }
+
+//    public static String calculateShortestDistanceDirection(List<Integer> data, int a, int b) {
+//        Result result = calculateShortestDistance(data, a, b);
+//        return result.direction;
+//    }
+
+    public static boolean calculateShortestDistanceDirection(List<Integer> data, int a, int b) {
+        Result result = calculateShortestDistance(data, a, b);
+        return result.direction.equals("鍚戝墠璧帮紙椤烘椂閽堬級");
+    }
+
+
+    public static void main(String[] args) {
+        List<Integer> data = new ArrayList<>();
+        // 鐢� List<Integer> 鍒濆鍖栨暟鎹�
+        for (int i = 1; i <= 9; i++) {
+            data.add(i);
+        }
+
+        int a = 3; // 璧风偣
+        int b = 3; // 缁堢偣
+
+        Result result = calculateShortestDistance(data, a, b);
+        System.out.println("鏈�杩戠殑璺濈鏄�: " + result.distance);
+        System.out.println("缁忚繃鐨勬暟鎹�: " + result.passedData);
+        System.out.println("鏂瑰悜: " + result.direction);
+    }
+
+    public static Result calculateShortestDistance(List<Integer> data, int a, int b) {
+        int length = data.size();
+        int indexA = data.indexOf(a);
+        int indexB = data.indexOf(b);
+
+        if (indexA == -1 || indexB == -1) {
+            throw new IllegalArgumentException("鍒楄〃涓湭鎵惧埌鎸囧畾鐨勫厓绱�");
+        }
+
+        // 椤烘椂閽堟柟鍚戠殑璺濈鍙婄粡杩囩殑鏁版嵁
+        List<Integer> clockwiseData = new ArrayList<>();
+        int clockwiseDistance = (indexB - indexA + length) % length;
+        for (int i = 0; i <= clockwiseDistance; i++) {
+            clockwiseData.add(data.get((indexA + i) % length));
+        }
+
+        // 閫嗘椂閽堟柟鍚戠殑璺濈鍙婄粡杩囩殑鏁版嵁
+        List<Integer> counterClockwiseData = new ArrayList<>();
+        int counterClockwiseDistance = (indexA - indexB + length) % length;
+        for (int i = 0; i <= counterClockwiseDistance; i++) {
+            counterClockwiseData.add(data.get((indexA - i + length) % length));
+        }
+
+        // 姣旇緝璺濈骞惰繑鍥炵粨鏋�
+        if (clockwiseDistance <= counterClockwiseDistance) {
+            return new Result(clockwiseDistance, clockwiseData, "鍚戝墠璧帮紙椤烘椂閽堬級");
+        } else {
+            return new Result(counterClockwiseDistance, counterClockwiseData, "鍚戝悗璧帮紙閫嗘椂閽堬級");
+        }
+    }
+
+    // 鐢ㄤ簬杩斿洖缁撴灉鐨勭被
+    static class Result {
+        public int distance;
+        public List<Integer> passedData;
+        public String direction;
+
+        public Result(int distance, List<Integer> passedData, String direction) {
+            this.distance = distance;
+            this.passedData = passedData;
+            this.direction = direction;
+        }
+    }
 
 }
diff --git a/src/main/java/com/zy/core/model/protocol/RgvProtocol.java b/src/main/java/com/zy/core/model/protocol/RgvProtocol.java
index 6defaa9..b44627f 100644
--- a/src/main/java/com/zy/core/model/protocol/RgvProtocol.java
+++ b/src/main/java/com/zy/core/model/protocol/RgvProtocol.java
@@ -65,6 +65,7 @@
      */
     public Long RgvPos;
     public Double instantaneousSpeed;// 鐬椂閫熷害 (m/min)
+    public Short endStaM;// 鐬椂閫熷害 (m/min)  婕父鐩殑鍦�
 
     /**
      * 璧拌鍦ㄥ畾浣�
diff --git a/src/main/java/com/zy/core/thread/RgvThread.java b/src/main/java/com/zy/core/thread/RgvThread.java
index 39c6825..b367363 100644
--- a/src/main/java/com/zy/core/thread/RgvThread.java
+++ b/src/main/java/com/zy/core/thread/RgvThread.java
@@ -149,6 +149,7 @@
         try {
             OperateResultExOne<byte[]> result = siemensNet.Read("DB100.0", (short) 20);
             OperateResultExOne<byte[]> resultV = siemensNet.Read("DB20.16", (short) 2);
+            OperateResultExOne<byte[]> resultE = siemensNet.Read("DB20.26", (short) 2);
             if (result.IsSuccess) {
                 if (null == rgvProtocol) {
                     rgvProtocol = new RgvProtocol();
@@ -164,6 +165,7 @@
                 rgvProtocol.setxSpeed(siemensNet.getByteTransform().TransInt16(result.Content, 14));
                 rgvProtocol.setRgvPos(siemensNet.getByteTransform().TransUInt32(result.Content, 16));
                 rgvProtocol.setInstantaneousSpeed(Double.valueOf(siemensNet.getByteTransform().TransInt16(resultV.Content, 0)));
+                rgvProtocol.setEndStaM(siemensNet.getByteTransform().TransInt16(resultE.Content, 0));
 //                rgvProtocol.setRgvPos((long)NumUtils.GetRandomIntInRange(1737000));
                 OutputQueue.RGV.offer(MessageFormat.format("銆恵0}銆慬id:{1}] <<<<< 瀹炴椂鏁版嵁鏇存柊鎴愬姛",DateUtils.convert(new Date()), slave.getId()));
 
diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml
index 1507a49..f068d4f 100644
--- a/src/main/resources/application.yml
+++ b/src/main/resources/application.yml
@@ -42,7 +42,7 @@
   # 灏忚溅鏁�
   rgvCount: 10
   # 寤惰繜鏃堕棿
-  rgvDate: 2
+  rgvDate: 0.5
 
 # 涓嬩綅鏈洪厤缃�
 wcs-slave:

--
Gitblit v1.9.1