| | |
| | | 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; |
| | |
| | | lockNode.add(node.clone()); |
| | | } |
| | | |
| | | long startTime = System.currentTimeMillis(); |
| | | List<ShuttleCommand> commands = new ArrayList<>(); |
| | | //获取分段路径 |
| | | List<List<NavigateNode>> data = navigateUtils.getSectionPath(nodeList); |
| | | long endTime = System.currentTimeMillis(); |
| | | News.info("getSection path time:{}", (endTime - startTime)); |
| | | //将每一段路径分成command指令 |
| | | for (List<NavigateNode> nodes : data) { |
| | | //开始路径 |
| | |
| | | } |
| | | |
| | | assignCommand.setNodes(allNode);//当前任务所占用的节点list |
| | | 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, 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(); |
| | | //所使用的路径进行锁定/解锁 |
| | | 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;//解锁失败 |
| | | } |
| | | |
| | | //获取小车移动速度 |
| | | 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); |
| | | //将每一段路径分成command指令 |
| | | 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);//当前任务所占用的节点list |
| | | |
| | | assignCommand.setShuttleMoveCommandsContinuously(shuttleMoveCommandsContinuously); |
| | | return commands; |
| | | } |
| | | |
| | |
| | | } |
| | | |
| | | //检测障碍物车 |
| | | 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()); |
| | | } |
| | | |
| | |
| | | } |
| | | |
| | | //获取外圈节点 |
| | | List<NavigateNode> outerNodes = getOuterNodes(locNo, outerCircle, whiteShuttlePointList, innerNodes); |
| | | List<NavigateNode> outerNodes = getOuterNodes(locNo, outerCircle, whiteShuttlePointList, innerNodes, whiteNodes); |
| | | |
| | | //将内圈节点中障碍小车调离 |
| | | for (Integer shuttleNo : nodesCar) { |
| | |
| | | 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); |
| | |
| | | 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); |
| | |
| | | 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; |
| | | } |
| | | |
| | |
| | | |
| | | 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,则不合法 |