From c4b6b51afdd3374735ed5f358457987eaa6e476f Mon Sep 17 00:00:00 2001 From: Junjie <540245094@qq.com> Date: 星期五, 05 九月 2025 16:55:20 +0800 Subject: [PATCH] # --- src/main/java/com/zy/common/utils/ShuttleOperaUtils.java | 178 +++++++++++++++++++++++++++++------------------------------ 1 files changed, 87 insertions(+), 91 deletions(-) diff --git a/src/main/java/com/zy/common/utils/ShuttleOperaUtils.java b/src/main/java/com/zy/common/utils/ShuttleOperaUtils.java index 33739d4..2f826fc 100644 --- a/src/main/java/com/zy/common/utils/ShuttleOperaUtils.java +++ b/src/main/java/com/zy/common/utils/ShuttleOperaUtils.java @@ -3,9 +3,7 @@ import com.baomidou.mybatisplus.mapper.EntityWrapper; import com.core.common.SpringUtils; import com.core.exception.CoolException; -import com.zy.asrs.entity.BasShuttle; import com.zy.asrs.entity.DeviceConfig; -import com.zy.asrs.service.BasShuttleService; import com.zy.asrs.service.DeviceConfigService; import com.zy.asrs.utils.Utils; import com.zy.common.model.MapNode; @@ -15,6 +13,7 @@ import com.zy.core.cache.SlaveConnection; import com.zy.core.dispatcher.ShuttleDispatchUtils; import com.zy.core.enums.MapNodeType; +import com.zy.core.enums.RedisKeyType; import com.zy.core.enums.ShuttleRunDirection; import com.zy.core.enums.SlaveType; import com.zy.core.model.command.ShuttleAssignCommand; @@ -36,11 +35,7 @@ public class ShuttleOperaUtils { @Autowired - private BasShuttleService basShuttleService; - @Autowired private NavigateUtils navigateUtils; - @Autowired - private NavigateMapUtils navigateMapUtils; @Autowired private NavigateMapData navigateMapData; @Autowired @@ -49,25 +44,42 @@ private ShuttleDispatchUtils shuttleDispatchUtils; @Autowired private DeviceConfigService deviceConfigService; + @Autowired + private RedisUtil redisUtil; public synchronized List<ShuttleCommand> getStartToTargetCommands(String startLocNo, String endLocNo, List<NavigationMapType> mapTypes, ShuttleAssignCommand assignCommand, ShuttleThread shuttleThread) { - return getStartToTargetCommands(startLocNo, endLocNo, mapTypes, null, assignCommand, shuttleThread); + return getStartToTargetCommands(startLocNo, endLocNo, mapTypes, null, assignCommand, shuttleThread, "move"); } - public synchronized List<ShuttleCommand> getStartToTargetCommands(String startLocNo, String endLocNo, List<NavigationMapType> mapTypes, List<int[]> whites, ShuttleAssignCommand assignCommand, ShuttleThread shuttleThread) { + public synchronized List<ShuttleCommand> getStartToTargetCommands(String startLocNo, String endLocNo, List<NavigationMapType> mapTypes, ShuttleAssignCommand assignCommand, ShuttleThread shuttleThread, String moveType) { + return getStartToTargetCommands(startLocNo, endLocNo, mapTypes, null, assignCommand, shuttleThread, moveType); + } + + public synchronized List<ShuttleCommand> getStartToTargetCommands(String startLocNo, String endLocNo, List<NavigationMapType> mapTypes, List<int[]> whites, ShuttleAssignCommand assignCommand, ShuttleThread shuttleThread, String moveType) { ShuttleProtocol shuttleProtocol = shuttleThread.getStatus(); if (shuttleProtocol == null) { return null; } Integer shuttleNo = shuttleProtocol.getShuttleNo(); //鑾峰彇灏忚溅绉诲姩閫熷害 - Integer runSpeed = Optional.ofNullable(basShuttleService.selectOne(new EntityWrapper<BasShuttle>().eq("shuttle_no", shuttleNo)).getRunSpeed()).orElse(1000); + Integer runSpeed = 1000; + Object speedObj = redisUtil.get(RedisKeyType.SHUTTLE_SPEED_MAP.key); + if (speedObj != null) { + HashMap<Integer, Integer> shuttleSpeedMap = (HashMap<Integer, Integer>) speedObj; + Integer speed = shuttleSpeedMap.get(shuttleNo); + if (speed != null) { + runSpeed = speed; + } + } + + long calcStartTime = System.currentTimeMillis(); List<NavigateNode> nodeList = navigateUtils.calc(startLocNo, endLocNo, mapTypes, Utils.getShuttlePoints(shuttleNo, Utils.getLev(startLocNo)), whites); if (nodeList == null) { News.error("{} dash {} can't find navigate path!", startLocNo, endLocNo); shuttleThread.offerSystemMsg("{} dash {} can't find navigate path!", startLocNo, endLocNo); return null; } + News.info("[RCS Debug] Calc path time:{}", (System.currentTimeMillis() - calcStartTime)); List<NavigateNode> allNode = new ArrayList<>(); List<NavigateNode> lockNode = new ArrayList<>(); @@ -77,7 +89,7 @@ if (whites != null) { boolean flag = false; for (int[] white : whites) { - if(white[0] == node.getX() && white[1] == node.getY()) { + if (white[0] == node.getX() && white[1] == node.getY()) { flag = true; break; } @@ -95,97 +107,66 @@ //鑾峰彇鍒嗘璺緞 List<List<NavigateNode>> data = navigateUtils.getSectionPath(nodeList); long endTime = System.currentTimeMillis(); - News.info("getSection path time:{}", (endTime - startTime)); + News.info("[RCS Debug] getSection path time:{}", (endTime - startTime)); + + long startGetSectionCommandTime = System.currentTimeMillis(); //灏嗘瘡涓�娈佃矾寰勫垎鎴恈ommand鎸囦护 - for (List<NavigateNode> nodes : data) { + for (int i = 0; i < data.size(); i++) { + long startGetStartAndEndPathTime = System.currentTimeMillis(); + List<NavigateNode> nodes = data.get(i); //寮�濮嬭矾寰� NavigateNode startPath = nodes.get(0); - //鐩爣璺緞 NavigateNode endPath = nodes.get(nodes.size() - 1); + News.info("[RCS Debug] getStartAndEndPath idx:{} time:{}", i, (System.currentTimeMillis() - startGetStartAndEndPathTime)); + + long startAllDistanceTime = System.currentTimeMillis(); Integer allDistance = navigateUtils.getCurrentPathAllDistance(nodes);//璁$畻褰撳墠璺緞琛岃蛋鎬昏窛绂� + News.info("[RCS Debug] getAllDistance idx:{} time:{}", i, (System.currentTimeMillis() - startAllDistanceTime)); + + long startGetPosition = System.currentTimeMillis(); //閫氳繃xy鍧愭爣灏忚溅浜岀淮鐮� String startCodeNum = NavigatePositionConvert.xyToPosition(startPath.getX(), startPath.getY(), startPath.getZ()); //閫氳繃xy鍧愭爣灏忚溅浜岀淮鐮� String distCodeNum = NavigatePositionConvert.xyToPosition(endPath.getX(), endPath.getY(), endPath.getZ()); + News.info("[RCS Debug] xyToPosition idx:{} time:{}", i, (System.currentTimeMillis() - startGetPosition)); + + long startGetMoveCommandTime = System.currentTimeMillis(); //鑾峰彇绉诲姩鍛戒护 ShuttleCommand command = shuttleThread.getMoveCommand(assignCommand.getDeviceTaskNo(), startCodeNum, distCodeNum, allDistance, ShuttleRunDirection.get(startPath.getDirection()).id.intValue(), runSpeed, nodes); + News.info("[RCS Debug] getMoveCommand idx:{} time:{}", i, (System.currentTimeMillis() - startGetMoveCommandTime)); + + if (i + 1 == data.size()) { + long startGetInOutLiftTime = System.currentTimeMillis(); + if (moveType.equals("inLift")) { + command = shuttleThread.getMoveLiftCommand(assignCommand.getDeviceTaskNo(), startCodeNum, distCodeNum, allDistance, ShuttleRunDirection.get(startPath.getDirection()).id.intValue(), runSpeed, nodes, true); + }else if (moveType.equals("outLift")) { + command = shuttleThread.getMoveLiftCommand(assignCommand.getDeviceTaskNo(), startCodeNum, distCodeNum, allDistance, ShuttleRunDirection.get(startPath.getDirection()).id.intValue(), runSpeed, nodes, false); + } + News.info("[RCS Debug] getInOutLiftTime idx:{} time:{}", i, (System.currentTimeMillis() - startGetInOutLiftTime)); + } + command.setNodes(nodes);//灏嗚璧拌妭鐐规坊鍔犲埌姣忎竴姝ュ懡浠や腑 commands.add(command); } + News.info("[RCS Debug] getSectionCommand path time:{}", (System.currentTimeMillis() - startGetSectionCommandTime)); assignCommand.setNodes(allNode);//褰撳墠浠诲姟鎵�鍗犵敤鐨勮妭鐐筶ist + assignCommand.setMapTypes(mapTypes); //灏忚溅绉诲姩杩炵画涓嬪彂鎸囦护 boolean shuttleMoveCommandsContinuously = false; - Config shuttleMoveCommandsContinuouslyConfig = configService.selectOne(new EntityWrapper<Config>().eq("code", "shuttleMoveCommandsContinuously")); - if (shuttleMoveCommandsContinuouslyConfig != null) { - if (shuttleMoveCommandsContinuouslyConfig.getValue().equals("Y")) { + Object object = redisUtil.get(RedisKeyType.SYSTEM_CONFIG_MAP.key); + if (object != null) { + HashMap<String, String> systemConfigMap = (HashMap<String, String>) object; + String shuttleMoveCommandsContinuouslyConfig = systemConfigMap.get("shuttleMoveCommandsContinuously"); + if (shuttleMoveCommandsContinuouslyConfig != null && shuttleMoveCommandsContinuouslyConfig.equals("Y")) { shuttleMoveCommandsContinuously = true; } } assignCommand.setShuttleMoveCommandsContinuously(shuttleMoveCommandsContinuously); - return commands; - } - public synchronized List<ShuttleCommand> shuttleInOutLiftCommand(String startLocNo, String endLocNo, List<NavigationMapType> mapTypes, ShuttleAssignCommand assignCommand, ShuttleThread shuttleThread) { - NavigateNode startNode = NavigatePositionConvert.locNoToNode(startLocNo); - NavigateNode endNode = NavigatePositionConvert.locNoToNode(endLocNo); - List<NavigateNode> unlockPath = new ArrayList<>(); - unlockPath.add(startNode); - unlockPath.add(endNode); - - ShuttleProtocol shuttleProtocol = shuttleThread.getStatus(); - if (shuttleProtocol == null) { - return null; - } - - Integer shuttleNo = shuttleProtocol.getShuttleNo(); - //鎵�浣跨敤鐨勮矾寰勮繘琛岄攣瀹�/瑙i攣 - boolean lockResult = navigateMapUtils.writeNavigateNodeToRedisMap(Utils.getLev(endLocNo), shuttleProtocol.getShuttleNo(), unlockPath, false);//鎵�浣跨敤鐨勮矾寰勮繘琛岃В閿� - if (!lockResult) { - News.error("{} dash {} can't find unlock path!", startLocNo, endLocNo); - shuttleThread.offerSystemMsg("{} dash {} can't find unlock path!", startLocNo, endLocNo); - return null;//瑙i攣澶辫触 - } - - //鑾峰彇灏忚溅绉诲姩閫熷害 - Integer runSpeed = Optional.ofNullable(basShuttleService.selectOne(new EntityWrapper<BasShuttle>().eq("shuttle_no", shuttleNo)).getRunSpeed()).orElse(1000); - List<NavigateNode> nodeList = navigateUtils.calc(startLocNo, endLocNo, mapTypes, Utils.getShuttlePoints(shuttleNo, Utils.getLev(startLocNo)), null); - if (nodeList == null) { - News.error("{} dash {} can't find navigate path!", startLocNo, endLocNo); - shuttleThread.offerSystemMsg("{} dash {} can't find navigate path!", startLocNo, endLocNo); - return null; - } - - List<NavigateNode> allNode = new ArrayList<>(); - for (NavigateNode node : nodeList) { - allNode.add(node.clone()); - } - - List<ShuttleCommand> commands = new ArrayList<>(); - //鑾峰彇鍒嗘璺緞 - List<List<NavigateNode>> data = navigateUtils.getSectionPath(nodeList); - //灏嗘瘡涓�娈佃矾寰勫垎鎴恈ommand鎸囦护 - for (List<NavigateNode> nodes : data) { - //寮�濮嬭矾寰� - NavigateNode startPath = nodes.get(0); - - //鐩爣璺緞 - NavigateNode endPath = nodes.get(nodes.size() - 1); - Integer allDistance = navigateUtils.getCurrentPathAllDistance(nodes);//璁$畻褰撳墠璺緞琛岃蛋鎬昏窛绂� - //閫氳繃xy鍧愭爣灏忚溅浜岀淮鐮� - String startCodeNum = NavigatePositionConvert.xyToPosition(startPath.getX(), startPath.getY(), startPath.getZ()); - //閫氳繃xy鍧愭爣灏忚溅浜岀淮鐮� - String distCodeNum = NavigatePositionConvert.xyToPosition(endPath.getX(), endPath.getY(), endPath.getZ()); - //鑾峰彇绉诲姩鍛戒护 - ShuttleCommand command = shuttleThread.getMoveCommand(assignCommand.getDeviceTaskNo(), startCodeNum, distCodeNum, allDistance, ShuttleRunDirection.get(startPath.getDirection()).id.intValue(), runSpeed, nodes); - command.setNodes(nodes);//灏嗚璧拌妭鐐规坊鍔犲埌姣忎竴姝ュ懡浠や腑 - commands.add(command); - } - - assignCommand.setNodes(allNode);//褰撳墠浠诲姟鎵�鍗犵敤鐨勮妭鐐筶ist - + News.info("{}浠诲姟锛寋}灏忚溅锛寋} - {} 璺緞鍛戒护鍖呰绠楁垚鍔燂紝鑰楁椂:{}ms", assignCommand.getTaskNo(), shuttleProtocol.getShuttleNo(), startLocNo, endLocNo, System.currentTimeMillis() - startTime); return commands; } @@ -213,17 +194,20 @@ return commands; } - //妫�娴嬮殰纰嶇墿杞� - public synchronized boolean checkObstacle(String locNo, List<Integer> whiteShuttles) { + /** + * 妫�娴嬮殰纰嶇墿杞� + * @return 0:鏃犻殰纰� 1:鏈夐殰纰嶈皟搴︽垚鍔� 2:鏈夐殰纰嶈皟搴﹀け璐� + */ + public synchronized int checkObstacle(String locNo, List<Integer> whiteShuttles, List<NavigateNode> whiteNodes) { int innerCircle = 0; int outerCircle = 3; Config avoidInnerCircleConfig = configService.selectOne(new EntityWrapper<Config>().eq("code", "avoidInnerCircle")); - if(avoidInnerCircleConfig != null) { + if (avoidInnerCircleConfig != null) { innerCircle = Integer.parseInt(avoidInnerCircleConfig.getValue()); } Config avoidOuterCircleConfig = configService.selectOne(new EntityWrapper<Config>().eq("code", "avoidOuterCircle")); - if(avoidOuterCircleConfig != null) { + if (avoidOuterCircleConfig != null) { outerCircle = Integer.parseInt(avoidOuterCircleConfig.getValue()); } @@ -247,11 +231,11 @@ List<NavigateNode> innerNodes = getInnerNodes(locNo, innerCircle, whiteShuttlePointList); List<Integer> nodesCar = findNodesCar(innerNodes); if (nodesCar.isEmpty()) { - return false;//鍐呭湀涓棤杞� + return 0;//鍐呭湀涓棤杞� } //鑾峰彇澶栧湀鑺傜偣 - List<NavigateNode> outerNodes = getOuterNodes(locNo, outerCircle, whiteShuttlePointList, innerNodes); + List<NavigateNode> outerNodes = getOuterNodes(locNo, outerCircle, whiteShuttlePointList, innerNodes, whiteNodes); //灏嗗唴鍦堣妭鐐逛腑闅滅灏忚溅璋冪 for (Integer shuttleNo : nodesCar) { @@ -274,20 +258,21 @@ List<NavigateNode> avoidInnerNodes = getInnerNodes(dispatchLocNo, innerCircle, new ArrayList<>()); //璁$畻鍐呭湀鏄惁鏈夊皬杞� List<Integer> avoidNodesCar = findNodesCar(avoidInnerNodes); - if(!avoidNodesCar.isEmpty()) { - continue; + if (!avoidNodesCar.isEmpty()) { + continue; } targetLocNo = dispatchLocNo; break; } - if(targetLocNo == null) { + if (targetLocNo == null) { continue; } - shuttleDispatchUtils.dispatchShuttle(null, targetLocNo, shuttleNo); + boolean dispatched = shuttleDispatchUtils.dispatchShuttle(null, targetLocNo, shuttleNo); + return dispatched ? 1 : 2; } - return true;//鍐呭湀涓湁杞� + return 2;//鍐呭湀涓湁杞� } private HashMap<String, Integer> findCarMap() { @@ -328,7 +313,7 @@ return list; } - private List<NavigateNode> getOuterNodes(String locNo, int outerCircle, List<int[]> whiteShuttlePointList, List<NavigateNode> innerNodes) { + private List<NavigateNode> getOuterNodes(String locNo, int outerCircle, List<int[]> whiteShuttlePointList, List<NavigateNode> innerNodes, List<NavigateNode> whiteNodes) { List<NavigateNode> outerNodes = new ArrayList<>(); List<NavigateNode> outerNodesTmp = new ArrayList<>(); int lev = Utils.getLev(locNo); @@ -353,13 +338,24 @@ for (NavigateNode node : outerNodesTmp) { boolean flag = false; for (NavigateNode innerNode : innerNodes) { - if(node.getX() == innerNode.getX() && node.getY() == innerNode.getY()) { + if (node.getX() == innerNode.getX() && node.getY() == innerNode.getY()) { flag = true; break; } } - if(flag) { + if (flag) { + continue; + } + + for (NavigateNode whiteNode : whiteNodes) { + if (node.getX() == whiteNode.getX() && node.getY() == whiteNode.getY()) { + flag = true; + break; + } + } + + if (flag) { continue; } @@ -560,7 +556,7 @@ private boolean is_valid(int[][] map, int x, int y) { if (x < 0 || x >= map.length - || y < 0 || y >= map[0].length) { + || y < 0 || y >= map[1].length) { return false; } // 濡傛灉缁撶偣鐨勪綅缃皬浜�0锛屽垯涓嶅悎娉� -- Gitblit v1.9.1