From 8d6708ad6b4353fd1da4d3d950fa61514ed41add Mon Sep 17 00:00:00 2001
From: Junjie <fallin.jie@qq.com>
Date: 星期四, 11 五月 2023 09:07:22 +0800
Subject: [PATCH] 四向穿梭车命令封装

---
 src/main/java/com/zy/core/thread/ShuttleThread.java |  304 +++++++++++++++++++++++---------------------------
 1 files changed, 140 insertions(+), 164 deletions(-)

diff --git a/src/main/java/com/zy/core/thread/ShuttleThread.java b/src/main/java/com/zy/core/thread/ShuttleThread.java
index 2a0f24a..2df784a 100644
--- a/src/main/java/com/zy/core/thread/ShuttleThread.java
+++ b/src/main/java/com/zy/core/thread/ShuttleThread.java
@@ -394,7 +394,6 @@
         if (!assignCommand.getAuto()) {
             List<NavigateNode> allNode = new ArrayList<>();
             List<ShuttleCommand> commands = new ArrayList<>();
-            ShuttleCommand command = new ShuttleCommand();
             LocMastService locMastService = SpringUtils.getBean(LocMastService.class);
             NavigateMapData navigateMapData;
             switch (assignCommand.getTaskMode()) {
@@ -420,52 +419,20 @@
                             NavigateNode endPath = nodes.get(nodes.size() - 1);
                             Integer allDistance = NavigateUtils.getCurrentPathAllDistance(nodes);//璁$畻褰撳墠璺緞琛岃蛋鎬昏窛绂�
 
-                            ShuttleCommand command1 = new ShuttleCommand();
-                            command1.setCommandWord((short) 1);
-                            command1.setStartCodeNum(NavigatePositionConvert.xyToPosition(startPath.getX(), startPath.getY(), 1));
-                            command1.setMiddleCodeNum((short) 1);
-                            command1.setDistCodeNum(NavigatePositionConvert.xyToPosition(endPath.getX(), endPath.getY(), 1));
-                            command1.setStartToDistDistance(allDistance);
-                            command1.setRunDirection(ShuttleRunDirection.get(startPath.getDirection()).id);
-                            command1.setForceMoveDistance(0);
-                            command1.setIOControl((short) 0);
-                            command1.setRunSpeed((short) 1000);
-                            command1.setCommandEnd((short) 1);
-                            commands.add(command1);
+                            //姝e父绉诲姩鍛戒护
+                            Short startCode = NavigatePositionConvert.xyToPosition(startPath.getX(), startPath.getY(), 1);//寮�濮嬩簩缁寸爜
+                            Short distCode = NavigatePositionConvert.xyToPosition(endPath.getX(), endPath.getY(), 1);//鐩爣浜岀淮鐮�
+                            commands.add(getMoveCommand(startCode,distCode,allDistance,ShuttleRunDirection.get(startPath.getDirection()).id));
                         }
 
                         //鎵樼洏椤跺崌
-                        ShuttleCommand command2 = new ShuttleCommand();
-                        command2.setCommandWord((short) 2);
-                        command2.setStartCodeNum((short) 0);
-                        command2.setMiddleCodeNum((short) 0);
-                        command2.setDistCodeNum((short) 0);
-                        command2.setStartToDistDistance(0);
-                        command2.setMiddleToDistDistance(0);
-                        command2.setRunDirection((short) 0);
-                        command2.setForceMoveDistance(0);
-                        command2.setPalletLift((short) 1);
-                        command2.setRunSpeed((short) 0);
-                        command2.setCommandEnd((short) 1);
-                        commands.add(command2);
+                        commands.add(getPalletCommand((short) 1));
                     }else {
                         //娌℃湁璁$畻鍒拌矾寰勶紝鍙兘瀛樺湪灏忚溅浣嶇疆灏辨槸璧风偣浣嶇疆
                         if (currentLocMast.getLocNo().equals(assignCommand.getSourceLocNo())) {
                             //灏忚溅浣嶇疆灏辨槸璧风偣浣嶇疆锛屾棤闇�绉诲姩锛岀洿鎺ラ《鍗�
                             //鎵樼洏椤跺崌
-                            ShuttleCommand command2 = new ShuttleCommand();
-                            command2.setCommandWord((short) 2);
-                            command2.setStartCodeNum((short) 0);
-                            command2.setMiddleCodeNum((short) 0);
-                            command2.setDistCodeNum((short) 0);
-                            command2.setStartToDistDistance(0);
-                            command2.setMiddleToDistDistance(0);
-                            command2.setRunDirection((short) 0);
-                            command2.setForceMoveDistance(0);
-                            command2.setPalletLift((short) 1);
-                            command2.setRunSpeed((short) 0);
-                            command2.setCommandEnd((short) 1);
-                            commands.add(command2);
+                            commands.add(getPalletCommand((short) 1));
                         }
                     }
 
@@ -485,115 +452,41 @@
                             NavigateNode endPath = nodes.get(nodes.size() - 1);
                             Integer allDistance = NavigateUtils.getCurrentPathAllDistance(nodes);//璁$畻褰撳墠璺緞琛岃蛋鎬昏窛绂�
 
-                            ShuttleCommand command1 = new ShuttleCommand();
-                            command1.setCommandWord((short) 1);
-                            command1.setStartCodeNum(NavigatePositionConvert.xyToPosition(startPath.getX(), startPath.getY(), 1));
-                            command1.setMiddleCodeNum((short) 1);
-                            command1.setDistCodeNum(NavigatePositionConvert.xyToPosition(endPath.getX(), endPath.getY(), 1));
-                            command1.setStartToDistDistance(allDistance);
-                            command1.setRunDirection(ShuttleRunDirection.get(startPath.getDirection()).id);
-                            command1.setForceMoveDistance(0);
-                            command1.setIOControl((short) 0);
-                            command1.setRunSpeed((short) 1000);
-                            command1.setCommandEnd((short) 1);
-                            commands.add(command1);
+                            //姝e父绉诲姩鍛戒护
+                            Short startCode = NavigatePositionConvert.xyToPosition(startPath.getX(), startPath.getY(), 1);//寮�濮嬩簩缁寸爜
+                            Short distCode = NavigatePositionConvert.xyToPosition(endPath.getX(), endPath.getY(), 1);//鐩爣浜岀淮鐮�
+                            commands.add(getMoveCommand(startCode, distCode, allDistance, ShuttleRunDirection.get(startPath.getDirection()).id));
                         }
 
                         //鎵樼洏涓嬮檷
-                        ShuttleCommand command2 = new ShuttleCommand();
-                        command2.setCommandWord((short) 2);
-                        command2.setStartCodeNum((short) 0);
-                        command2.setMiddleCodeNum((short) 0);
-                        command2.setDistCodeNum((short) 0);
-                        command2.setStartToDistDistance(0);
-                        command2.setMiddleToDistDistance(0);
-                        command2.setRunDirection((short) 0);
-                        command2.setForceMoveDistance(0);
-                        command2.setPalletLift((short) 2);
-                        command2.setRunSpeed((short) 0);
-                        command2.setCommandEnd((short) 1);
-                        commands.add(command2);
+                        commands.add(getPalletCommand((short) 2));
                     }
                     break;
                 case 3://鎵樼洏椤跺崌
                 case 4://鎵樼洏涓嬮檷
-                    command.setCommandWord((short) 2);
-                    command.setStartCodeNum((short) 0);
-                    command.setMiddleCodeNum((short) 0);
-                    command.setDistCodeNum((short) 0);
-                    command.setStartToDistDistance(0);
-                    command.setMiddleToDistDistance(0);
-                    command.setRunDirection((short) 0);
-                    command.setForceMoveDistance(0);
-                    command.setPalletLift(assignCommand.getTaskMode() == 3 ? (short)1 : (short)2);
-                    command.setRunSpeed((short) 0);
-                    command.setCommandEnd((short) 1);
-                    commands.add(command);
+                    commands.add(getPalletCommand(assignCommand.getTaskMode() == 3 ? (short) 1 : (short) 2));
                     break;
                 case 5://寮哄埗宸︾Щ
                 case 6://寮哄埗鍙崇Щ
                 case 7://寮哄埗涓婄Щ
                 case 8://寮哄埗涓嬬Щ
-                    command.setCommandWord((short) 3);
-                    command.setStartCodeNum((short) 0);
-                    command.setMiddleCodeNum((short) 0);
-                    command.setDistCodeNum((short) 0);
-                    command.setStartToDistDistance(600);
-                    command.setRunDirection((short) (assignCommand.getTaskMode() - 4));
-                    command.setForceMoveDistance(600);
-                    command.setIOControl((short) 0);
-                    command.setCommandEnd((short) 1);
-                    command.setRunSpeed((short) 1000);
-                    commands.add(command);
+                    commands.add(getForceMoveCommand((short) (assignCommand.getTaskMode() - 4)));
                     break;
                 case 9://鐘舵�佸浣�
-                    command.setCommandWord((short) 6);
-                    command.setStartCodeNum((short) 0);
-                    command.setMiddleCodeNum((short) 0);
-                    command.setDistCodeNum((short) 0);
-                    command.setStartToDistDistance(0);
-                    command.setMiddleToDistDistance(0);
-                    command.setRunDirection((short) 0);
-                    command.setPalletLift((short) 0);
-                    command.setPalletLift((short) 0);
-                    command.setForceMoveDistance(0);
-                    command.setChargeSwitch((short) 0);
-                    command.setIOControl((short) 0);
-                    command.setRunSpeed((short) 0);
-                    command.setCommandEnd((short) 1);
-                    commands.add(command);
+                    ShuttleCommand reset = getResetCommand();
+                    commands.add(reset);
                     break;
                 case 10://鍚戞鏂瑰悜(宸�)瀵诲簱浣�
-                    command.setCommandWord((short) 4);
-                    command.setRunDirection((short) 1);
-                    command.setStartToDistDistance(3000);
-                    command.setRunSpeed((short) 1000);
-                    command.setCommandEnd((short) 1);
-                    commands.add(command);
+                    commands.add(getFindLocCommand((short) 1));
                     break;
                 case 11://鍚戣礋鏂瑰悜(鍙�)瀵诲簱浣�
-                    command.setCommandWord((short) 4);
-                    command.setRunDirection((short) 2);
-                    command.setStartToDistDistance(3000);
-                    command.setRunSpeed((short) 1000);
-                    command.setCommandEnd((short) 1);
-                    commands.add(command);
+                    commands.add(getFindLocCommand((short) 2));
                     break;
                 case 12://鍚戞鏂瑰悜(鍓�)瀵诲簱浣�
-                    command.setCommandWord((short) 4);
-                    command.setRunDirection((short) 4);
-                    command.setStartToDistDistance(3000);
-                    command.setRunSpeed((short) 1000);
-                    command.setCommandEnd((short) 1);
-                    commands.add(command);
+                    commands.add(getFindLocCommand((short) 4));
                     break;
                 case 13://鍚戣礋鏂瑰悜(鍚�)瀵诲簱浣�
-                    command.setCommandWord((short) 4);
-                    command.setRunDirection((short) 3);
-                    command.setStartToDistDistance(3000);
-                    command.setRunSpeed((short) 1000);
-                    command.setCommandEnd((short) 1);
-                    commands.add(command);
+                    commands.add(getFindLocCommand((short) 3));
                     break;
                 case 14://绉诲姩鍒扮洰鏍囧簱浣�
                     LocMast locMast = locMastService.queryByQrCode(shuttleProtocol.getCurrentCode().toString());
@@ -616,25 +509,14 @@
 
                             LocMast distLocMast = locMastService.queryByLoc(assignCommand.getLocNo());
                             String qrCodeValue = distLocMast.getQrCodeValue();
-                            command.setCommandWord((short) 1);
-                            command.setStartCodeNum(shuttleProtocol.getCurrentCode());
-                            command.setMiddleCodeNum((short) 1);
-                            command.setDistCodeNum((short) Integer.parseInt(qrCodeValue));
-                            command.setStartToDistDistance(allDistance);
-                            command.setRunSpeed((short) 1000);
-                            command.setRunDirection(ShuttleRunDirection.get(startPath.getDirection()).id);
-                            command.setForceMoveDistance(0);
-                            command.setIOControl((short) 0);
-                            command.setCommandEnd((short) 1);
-                            commands.add(command);
+
+                            //姝e父绉诲姩鍛戒护
+                            commands.add(getMoveCommand(shuttleProtocol.getCurrentCode(),(short) Integer.parseInt(qrCodeValue),allDistance,ShuttleRunDirection.get(startPath.getDirection()).id));
                         }
                     }
                     break;
                 case 15://鍏呯數寮�鍏�
-                    command.setCommandWord((short) 8);
-                    command.setIOControl((short) 4);
-                    command.setCommandEnd((short) 1);
-                    commands.add(command);
+                    commands.add(getChargeSwitchCommand());
                     break;
                 default:
             }
@@ -993,29 +875,13 @@
         ShuttleCommand command = commands.get(commandStep - 1);
 
         //澶嶄綅鍛戒护
-        ShuttleCommand resetCommand = new ShuttleCommand();
-        resetCommand.setCommandWord((short) 6);
-        resetCommand.setStartCodeNum((short) 0);
-        resetCommand.setMiddleCodeNum((short) 0);
-        resetCommand.setDistCodeNum((short) 0);
-        resetCommand.setStartToDistDistance(0);
-        resetCommand.setMiddleToDistDistance(0);
-        resetCommand.setRunDirection((short) 0);
-        resetCommand.setPalletLift((short) 0);
-        resetCommand.setPalletLift((short) 0);
-        resetCommand.setForceMoveDistance(0);
-        resetCommand.setChargeSwitch((short) 0);
-        resetCommand.setIOControl((short) 0);
-        resetCommand.setRunSpeed((short) 0);
-        resetCommand.setCommandEnd((short) 1);
+        ShuttleCommand resetCommand = getResetCommand();
         list.add(resetCommand);
 
         //杞﹁締绌洪棽锛岀瓑寰呭啓鍏ユ壘搴撲綅鍛戒护
         //鎵惧簱浣嶅懡浠�
-        ShuttleCommand searchCommand = new ShuttleCommand();
-        searchCommand.setCommandWord((short) 4);
         short direction = 1;
-        switch (command.getRunDirection()) {
+        switch (command.getRunDirection()) {//杞崲杩愯鏂瑰悜
             case 1:
                 direction = 2;
                 break;
@@ -1031,11 +897,8 @@
             default:
                 direction = 1;
         }
-
-        searchCommand.setRunDirection(direction);//杩愯鏂瑰悜
-        searchCommand.setStartToDistDistance(1200);
-        searchCommand.setRunSpeed((short) 1000);
-        searchCommand.setCommandEnd((short) 1);
+        //鎵惧簱浣嶅懡浠�
+        ShuttleCommand searchCommand = getFindLocCommand(direction, 1200, (short) 1000);
         list.add(searchCommand);
 
         //绉诲姩杞﹁締锛岄渶瑕佸湪鎵ц瀹屽鎵惧畾浣嶇偣鍚庡啀鎵ц
@@ -1051,6 +914,119 @@
         return true;
     }
 
+    /**
+     * 鑾峰彇鎵樼洏椤跺崌鍛戒护
+     * @param lift 1椤跺崌锛�2涓嬮檷
+     */
+    private ShuttleCommand getPalletCommand(Short lift) {
+        ShuttleCommand command = new ShuttleCommand();
+        command.setCommandWord((short) 2);
+        command.setStartCodeNum((short) 0);
+        command.setMiddleCodeNum((short) 0);
+        command.setDistCodeNum((short) 0);
+        command.setStartToDistDistance(0);
+        command.setMiddleToDistDistance(0);
+        command.setRunDirection((short) 0);
+        command.setForceMoveDistance(0);
+        command.setPalletLift(lift);
+        command.setRunSpeed((short) 0);
+        command.setCommandEnd((short) 1);
+        return command;
+    }
+
+    /**
+     * 姝e父绉诲姩鍛戒护
+     * @return
+     */
+    private ShuttleCommand getMoveCommand(Short startCodeNum, Short distCodeNum, Integer startToDistDistance, Short runDirection) {
+        ShuttleCommand command = new ShuttleCommand();
+        command.setCommandWord((short) 1);
+        command.setStartCodeNum(startCodeNum);
+        command.setMiddleCodeNum((short) 1);
+        command.setDistCodeNum(distCodeNum);
+        command.setStartToDistDistance(startToDistDistance);
+        command.setRunDirection(runDirection);
+        command.setForceMoveDistance(0);
+        command.setIOControl((short) 0);
+        command.setRunSpeed((short) 1000);
+        command.setCommandEnd((short) 1);
+        return command;
+    }
+
+    /**
+     * 寮哄埗绉诲姩鍛戒护
+     * @param direction 绉诲姩鏂瑰悜 1宸︾Щ锛�2鍙崇Щ锛�3鍓嶇Щ锛�4鍚庣Щ
+     */
+    private ShuttleCommand getForceMoveCommand(Short direction) {
+        ShuttleCommand command = new ShuttleCommand();
+        command.setCommandWord((short) 3);
+        command.setStartCodeNum((short) 0);
+        command.setMiddleCodeNum((short) 0);
+        command.setDistCodeNum((short) 0);
+        command.setStartToDistDistance(600);
+        command.setRunDirection(direction);
+        command.setForceMoveDistance(600);
+        command.setIOControl((short) 0);
+        command.setCommandEnd((short) 1);
+        command.setRunSpeed((short) 1000);
+        return command;
+    }
+
+    /**
+     * 鐘舵�佸浣嶅懡浠�
+     */
+    private ShuttleCommand getResetCommand() {
+        ShuttleCommand command = new ShuttleCommand();
+        command.setCommandWord((short) 6);
+        command.setStartCodeNum((short) 0);
+        command.setMiddleCodeNum((short) 0);
+        command.setDistCodeNum((short) 0);
+        command.setStartToDistDistance(0);
+        command.setMiddleToDistDistance(0);
+        command.setRunDirection((short) 0);
+        command.setPalletLift((short) 0);
+        command.setPalletLift((short) 0);
+        command.setForceMoveDistance(0);
+        command.setChargeSwitch((short) 0);
+        command.setIOControl((short) 0);
+        command.setRunSpeed((short) 0);
+        command.setCommandEnd((short) 1);
+        return command;
+    }
+
+    /**
+     * 鑾峰彇瀵诲簱浣嶅懡浠�
+     * @param direction 1:鍚戞鏂瑰悜(宸�)瀵诲簱浣�,2:鍚戣礋鏂瑰悜(鍙�)瀵诲簱浣�,3:鍚戣礋鏂瑰悜(鍚�)瀵诲簱浣�,4:鍚戞鏂瑰悜(鍓�)瀵诲簱浣�
+     */
+    private ShuttleCommand getFindLocCommand(Short direction, Integer startToDistance, Short runSpeed) {
+        ShuttleCommand command = new ShuttleCommand();
+        command.setCommandWord((short) 4);
+        command.setRunDirection(direction);
+        command.setStartToDistDistance(startToDistance);
+        command.setRunSpeed((short) runSpeed);
+        command.setCommandEnd((short) 1);
+        return command;
+    }
+
+    /**
+     * 鑾峰彇瀵诲簱浣嶅懡浠わ紝榛樿绉诲姩璺濈3000锛岃繍琛岄�熷害1000
+     * @param direction 1:鍚戞鏂瑰悜(宸�)瀵诲簱浣�,2:鍚戣礋鏂瑰悜(鍙�)瀵诲簱浣�,3:鍚戣礋鏂瑰悜(鍚�)瀵诲簱浣�,4:鍚戞鏂瑰悜(鍓�)瀵诲簱浣�
+     */
+    private ShuttleCommand getFindLocCommand(Short direction) {
+        return getFindLocCommand(direction, 3000, (short) 1000);
+    }
+
+    /**
+     * 鑾峰彇鍏呯數寮�鍏冲懡浠�
+     */
+    private ShuttleCommand getChargeSwitchCommand() {
+        ShuttleCommand command = new ShuttleCommand();
+        command.setCommandWord((short) 8);
+        command.setIOControl((short) 4);
+        command.setCommandEnd((short) 1);
+        return command;
+    }
+
     /******************************************************************************************/
     /**************************************** 娴嬭瘯涓撶敤 *****************************************/
     /*****************************************************************************************/

--
Gitblit v1.9.1