From 6daf900a09adcca981f620744bf89851654d88e0 Mon Sep 17 00:00:00 2001 From: Junjie <fallin.jie@qq.com> Date: 星期二, 05 八月 2025 09:58:08 +0800 Subject: [PATCH] # --- src/main/java/com/zy/common/utils/ShuttleOperaUtils.java | 199 +++++++++++++++++++++++++------------------------ 1 files changed, 103 insertions(+), 96 deletions(-) diff --git a/src/main/java/com/zy/common/utils/ShuttleOperaUtils.java b/src/main/java/com/zy/common/utils/ShuttleOperaUtils.java index 4c14010..0b3fd1f 100644 --- a/src/main/java/com/zy/common/utils/ShuttleOperaUtils.java +++ b/src/main/java/com/zy/common/utils/ShuttleOperaUtils.java @@ -4,21 +4,22 @@ 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; import com.zy.common.model.NavigateNode; +import com.zy.common.model.enums.NavigationMapType; import com.zy.core.News; import com.zy.core.cache.SlaveConnection; import com.zy.core.dispatcher.ShuttleDispatchUtils; import com.zy.core.enums.MapNodeType; import com.zy.core.enums.ShuttleRunDirection; import com.zy.core.enums.SlaveType; -import com.zy.core.model.ShuttleSlave; import com.zy.core.model.command.ShuttleAssignCommand; import com.zy.core.model.command.ShuttleCommand; import com.zy.core.model.protocol.ShuttleProtocol; -import com.zy.core.properties.SlaveProperties; import com.zy.core.thread.ShuttleThread; import com.zy.system.entity.Config; import com.zy.system.service.ConfigService; @@ -45,15 +46,15 @@ @Autowired private ConfigService configService; @Autowired - private SlaveProperties slaveProperties; - @Autowired private ShuttleDispatchUtils shuttleDispatchUtils; + @Autowired + private DeviceConfigService deviceConfigService; - public synchronized List<ShuttleCommand> getStartToTargetCommands(String startLocNo, String endLocNo, Integer mapType, ShuttleAssignCommand assignCommand, ShuttleThread shuttleThread) { - return getStartToTargetCommands(startLocNo, endLocNo, mapType, null, assignCommand, shuttleThread); + public synchronized List<ShuttleCommand> getStartToTargetCommands(String startLocNo, String endLocNo, List<NavigationMapType> mapTypes, ShuttleAssignCommand assignCommand, ShuttleThread shuttleThread) { + return getStartToTargetCommands(startLocNo, endLocNo, mapTypes, null, assignCommand, shuttleThread); } - public synchronized List<ShuttleCommand> getStartToTargetCommands(String startLocNo, String endLocNo, Integer mapType, List<int[]> whites, ShuttleAssignCommand assignCommand, ShuttleThread shuttleThread) { + public synchronized List<ShuttleCommand> getStartToTargetCommands(String startLocNo, String endLocNo, List<NavigationMapType> mapTypes, List<int[]> whites, ShuttleAssignCommand assignCommand, ShuttleThread shuttleThread) { ShuttleProtocol shuttleProtocol = shuttleThread.getStatus(); if (shuttleProtocol == null) { return null; @@ -61,7 +62,7 @@ Integer shuttleNo = shuttleProtocol.getShuttleNo(); //鑾峰彇灏忚溅绉诲姩閫熷害 Integer runSpeed = Optional.ofNullable(basShuttleService.selectOne(new EntityWrapper<BasShuttle>().eq("shuttle_no", shuttleNo)).getRunSpeed()).orElse(1000); - List<NavigateNode> nodeList = navigateUtils.calc(startLocNo, endLocNo, mapType, Utils.getShuttlePoints(shuttleNo, Utils.getLev(startLocNo)), whites); + 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); @@ -89,11 +90,14 @@ lockNode.add(node.clone()); } + long startTime = System.currentTimeMillis(); List<ShuttleCommand> commands = new ArrayList<>(); //鑾峰彇鍒嗘璺緞 - ArrayList<ArrayList<NavigateNode>> data = navigateUtils.getSectionPath(nodeList); + List<List<NavigateNode>> data = navigateUtils.getSectionPath(nodeList); + long endTime = System.currentTimeMillis(); + News.info("getSection path time:{}", (endTime - startTime)); //灏嗘瘡涓�娈佃矾寰勫垎鎴恈ommand鎸囦护 - for (ArrayList<NavigateNode> nodes : data) { + for (List<NavigateNode> nodes : data) { //寮�濮嬭矾寰� NavigateNode startPath = nodes.get(0); @@ -111,74 +115,17 @@ } assignCommand.setNodes(allNode);//褰撳墠浠诲姟鎵�鍗犵敤鐨勮妭鐐筶ist + assignCommand.setMapTypes(mapTypes); - boolean result = navigateMapUtils.writeNavigateNodeToRedisMap(Utils.getLev(startLocNo), shuttleNo, lockNode, true);//閿佸畾璺緞 - if (!result) { - News.error("{} dash {} can't lock path!", startLocNo, endLocNo); - shuttleThread.offerSystemMsg("{} dash {} can't lock path!", startLocNo, endLocNo); - return null;//璺緞閿佸畾澶辫触 + //灏忚溅绉诲姩杩炵画涓嬪彂鎸囦护 + boolean shuttleMoveCommandsContinuously = false; + Config shuttleMoveCommandsContinuouslyConfig = configService.selectOne(new EntityWrapper<Config>().eq("code", "shuttleMoveCommandsContinuously")); + if (shuttleMoveCommandsContinuouslyConfig != null) { + if (shuttleMoveCommandsContinuouslyConfig.getValue().equals("Y")) { + shuttleMoveCommandsContinuously = true; + } } - return commands; - } - - public synchronized List<ShuttleCommand> shuttleInOutLiftCommand(String startLocNo, String endLocNo, Integer mapType, 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, mapType, 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<>(); - //鑾峰彇鍒嗘璺緞 - ArrayList<ArrayList<NavigateNode>> data = navigateUtils.getSectionPath(nodeList); - //灏嗘瘡涓�娈佃矾寰勫垎鎴恈ommand鎸囦护 - for (ArrayList<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 - + assignCommand.setShuttleMoveCommandsContinuously(shuttleMoveCommandsContinuously); return commands; } @@ -207,16 +154,16 @@ } //妫�娴嬮殰纰嶇墿杞� - public synchronized boolean checkObstacle(String locNo, List<Integer> whiteShuttles) { + public synchronized boolean 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()); } @@ -244,7 +191,7 @@ } //鑾峰彇澶栧湀鑺傜偣 - List<NavigateNode> outerNodes = getOuterNodes(locNo, outerCircle, whiteShuttlePointList, innerNodes); + List<NavigateNode> outerNodes = getOuterNodes(locNo, outerCircle, whiteShuttlePointList, innerNodes, whiteNodes); //灏嗗唴鍦堣妭鐐逛腑闅滅灏忚溅璋冪 for (Integer shuttleNo : nodesCar) { @@ -260,19 +207,21 @@ continue; } - HashMap<String, Integer> carMap = findCarMap(); - String targetLocNo = null; for (NavigateNode node : outerNodes) { String dispatchLocNo = NavigatePositionConvert.nodeToLocNo(node); - if (carMap.containsKey(dispatchLocNo)) { + //鑾峰彇鍐呭湀鑺傜偣 + List<NavigateNode> avoidInnerNodes = getInnerNodes(dispatchLocNo, innerCircle, new ArrayList<>()); + //璁$畻鍐呭湀鏄惁鏈夊皬杞� + List<Integer> avoidNodesCar = findNodesCar(avoidInnerNodes); + if (!avoidNodesCar.isEmpty()) { continue; } targetLocNo = dispatchLocNo; break; } - if(targetLocNo == null) { + if (targetLocNo == null) { continue; } shuttleDispatchUtils.dispatchShuttle(null, targetLocNo, shuttleNo); @@ -283,8 +232,11 @@ private HashMap<String, Integer> findCarMap() { HashMap<String, Integer> carMap = new HashMap<>(); - for (ShuttleSlave slave : slaveProperties.getShuttle()) { - ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, slave.getId()); + + List<DeviceConfig> shuttleList = deviceConfigService.selectList(new EntityWrapper<DeviceConfig>() + .eq("device_type", String.valueOf(SlaveType.Shuttle))); + for (DeviceConfig device : shuttleList) { + ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, device.getDeviceNo()); if (shuttleThread == null) { continue; } @@ -297,7 +249,7 @@ continue; } - carMap.put(currentLocNo, slave.getId()); + carMap.put(currentLocNo, device.getDeviceNo()); } return carMap; } @@ -316,7 +268,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); @@ -324,14 +276,14 @@ NavigateNode currentNode = new NavigateNode(pointArr[0], pointArr[1]); currentNode.setZ(lev); - List<List<MapNode>> lists = navigateMapData.getJsonData(lev, -1, null, null);//鑾峰彇瀹屾暣鍦板浘 + List<List<MapNode>> lists = navigateMapData.getJsonData(lev, NavigationMapType.getMapTypes(NavigationMapType.NONE), null, null);//鑾峰彇瀹屾暣鍦板浘 int[][] map = navigateMapData.parseJsonDataArr(lists); int nodeValue = map[pointArr[0]][pointArr[1]]; currentNode.setNodeValue(nodeValue); for (int i = 0; i < outerCircle; i++) { int idx = i + 1; - List<NavigateNode> list = extend_nodes(map, currentNode, idx); + List<NavigateNode> list = extend_outer_nodes(map, currentNode, idx); if (list.isEmpty()) { continue; } @@ -341,13 +293,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; } @@ -365,14 +328,14 @@ currentNode.setZ(lev); innerNodes.add(currentNode); - List<List<MapNode>> lists = navigateMapData.getJsonData(lev, -1, null, null);//鑾峰彇瀹屾暣鍦板浘 + List<List<MapNode>> lists = navigateMapData.getJsonData(lev, NavigationMapType.getMapTypes(NavigationMapType.NONE), null, null);//鑾峰彇瀹屾暣鍦板浘 int[][] map = navigateMapData.parseJsonDataArr(lists); int nodeValue = map[pointArr[0]][pointArr[1]]; currentNode.setNodeValue(nodeValue); for (int i = 0; i < innerCircle; i++) { int idx = i + 1; - List<NavigateNode> list = extend_nodes(map, currentNode, idx); + List<NavigateNode> list = extend_inner_nodes(map, currentNode, idx); if (list.isEmpty()) { continue; } @@ -395,7 +358,7 @@ return innerNodes; } - private List<NavigateNode> extend_nodes(int[][] map, NavigateNode startNode, int innerCircleIdx) { + private List<NavigateNode> extend_inner_nodes(int[][] map, NavigateNode startNode, int innerCircleIdx) { //榛樿鍦板浘姣嶈建鏂瑰悜x String mapDirection = "x"; ConfigService configService = SpringUtils.getBean(ConfigService.class); @@ -502,9 +465,53 @@ return nodes; } + private List<NavigateNode> extend_outer_nodes(int[][] map, NavigateNode startNode, int innerCircleIdx) { + ArrayList<NavigateNode> nodes = new ArrayList<>(); + int x = startNode.getX(); + int y = startNode.getY(); + int z = startNode.getZ(); + + if (is_valid(map, x + innerCircleIdx, y)) { + NavigateNode node = new NavigateNode(x + innerCircleIdx, y); + node.setNodeValue(map[x + innerCircleIdx][y]); + node.setZ(z); + if (node.getNodeValue().equals(startNode.getNodeValue())) { + nodes.add(node); + } + } + + if (is_valid(map, x - innerCircleIdx, y)) { + NavigateNode node = new NavigateNode(x - innerCircleIdx, y); + node.setNodeValue(map[x - innerCircleIdx][y]); + node.setZ(z); + if (node.getNodeValue().equals(startNode.getNodeValue())) { + nodes.add(node); + } + } + + if (is_valid(map, x, y + innerCircleIdx)) { + NavigateNode node = new NavigateNode(x, y + innerCircleIdx); + node.setNodeValue(map[x][y + innerCircleIdx]); + node.setZ(z); + if (node.getNodeValue().equals(startNode.getNodeValue())) { + nodes.add(node); + } + } + + if (is_valid(map, x, y - innerCircleIdx)) { + NavigateNode node = new NavigateNode(x, y - innerCircleIdx); + node.setNodeValue(map[x][y - innerCircleIdx]); + node.setZ(z); + if (node.getNodeValue().equals(startNode.getNodeValue())) { + nodes.add(node); + } + } + return nodes; + } + 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