| | |
| | | |
| | | if (commandType == StationCommandType.MOVE) { |
| | | if (!stationId.equals(targetStationId)) { |
| | | List<Integer> path = calcPathStationIds(stationId, targetStationId); |
| | | List<NavigateNode> nodes = calcPathNavigateNodes(stationId, targetStationId); |
| | | List<Integer> path = new ArrayList<>(); |
| | | List<Integer> liftTransferPath = new ArrayList<>(); |
| | | for (NavigateNode n : nodes) { |
| | | JSONObject v = JSONObject.parseObject(n.getNodeValue()); |
| | | if (v == null) { |
| | | continue; |
| | | } |
| | | Integer stationNo = v.getInteger("stationId"); |
| | | if (stationNo == null) { |
| | | continue; |
| | | } |
| | | path.add(stationNo); |
| | | if (Boolean.TRUE.equals(n.getIsLiftTransferPoint())) { |
| | | liftTransferPath.add(stationNo); |
| | | } |
| | | } |
| | | stationCommand.setNavigatePath(path); |
| | | stationCommand.setLiftTransferPath(liftTransferPath); |
| | | } |
| | | } |
| | | return stationCommand; |
| | |
| | | return zyStationConnectDriver.readOriginCommand(address, length); |
| | | } |
| | | |
| | | private List<Integer> calcPathStationIds(Integer startStationId, Integer targetStationId) { |
| | | private List<NavigateNode> calcPathNavigateNodes(Integer startStationId, Integer targetStationId) { |
| | | NavigateUtils navigateUtils = SpringUtils.getBean(NavigateUtils.class); |
| | | if (navigateUtils == null) { |
| | | return new ArrayList<>(); |
| | | } |
| | | List<NavigateNode> nodes = navigateUtils.calcByStationId(startStationId, targetStationId); |
| | | List<Integer> ids = new ArrayList<>(); |
| | | for (NavigateNode n : nodes) { |
| | | JSONObject v = JSONObject.parseObject(n.getNodeValue()); |
| | | if (v != null) { |
| | | ids.add(v.getInteger("stationId")); |
| | | } |
| | | } |
| | | return ids; |
| | | return navigateUtils.calcByStationId(startStationId, targetStationId); |
| | | } |
| | | |
| | | private void executeMoveWithSeg(StationCommand original) { |
| | | int stationCommandSendLength = 20; |
| | | Object systemConfigMapObj = redisUtil.get(RedisKeyType.SYSTEM_CONFIG_MAP.key); |
| | | if (systemConfigMapObj != null) { |
| | | try { |
| | | HashMap<String, String> systemConfigMap = (HashMap<String, String>) systemConfigMapObj; |
| | | String stationCommandSendLengthStr = systemConfigMap.get("stationCommandSendLength"); |
| | | if(stationCommandSendLengthStr != null){ |
| | | stationCommandSendLength = Integer.parseInt(stationCommandSendLengthStr); |
| | | } |
| | | } catch (Exception ignore) {} |
| | | } |
| | | |
| | | if(original.getCommandType() == StationCommandType.MOVE){ |
| | | List<Integer> path = JSON.parseArray(JSON.toJSONString(original.getNavigatePath(), SerializerFeature.DisableCircularReferenceDetect), Integer.class); |
| | | List<Integer> liftTransferPath = JSON.parseArray(JSON.toJSONString(original.getLiftTransferPath(), SerializerFeature.DisableCircularReferenceDetect), Integer.class); |
| | | if (path == null || path.isEmpty()) { |
| | | return; |
| | | } |
| | | |
| | | int total = path.size(); |
| | | List<Integer> segmentTargets = new ArrayList<>(); |
| | | List<Integer> segmentEndIndices = new ArrayList<>(); |
| | | int idx = 0; |
| | | while (idx < total) { |
| | | int end = Math.min(idx + stationCommandSendLength, total) - 1; |
| | | segmentTargets.add(path.get(end)); |
| | | segmentEndIndices.add(end); |
| | | idx = end + 1; |
| | | if (liftTransferPath != null) { |
| | | for (Integer liftTransferStationId : liftTransferPath) { |
| | | int endIndex = path.indexOf(liftTransferStationId); |
| | | // 避免以起点作为切点导致空分段 |
| | | if (endIndex <= 0) { |
| | | continue; |
| | | } |
| | | if (segmentEndIndices.isEmpty() || endIndex > segmentEndIndices.get(segmentEndIndices.size() - 1)) { |
| | | segmentEndIndices.add(endIndex); |
| | | } |
| | | } |
| | | } |
| | | if (segmentEndIndices.isEmpty() || segmentEndIndices.get(segmentEndIndices.size() - 1) != total - 1) { |
| | | segmentEndIndices.add(total - 1); |
| | | } |
| | | |
| | | List<StationCommand> segmentCommands = new ArrayList<>(); |
| | | int buildStartIdx = 0; |
| | | for (Integer endIdx : segmentEndIndices) { |
| | | if (endIdx == null || endIdx < buildStartIdx) { |
| | | continue; |
| | | } |
| | | List<Integer> segmentPath = new ArrayList<>(path.subList(buildStartIdx, endIdx + 1)); |
| | | if (segmentPath.isEmpty()) { |
| | | buildStartIdx = endIdx + 1; |
| | | continue; |
| | | } |
| | | |
| | | StationCommand segmentCommand = new StationCommand(); |
| | | segmentCommand.setTaskNo(original.getTaskNo()); |
| | | segmentCommand.setCommandType(original.getCommandType()); |
| | | segmentCommand.setPalletSize(original.getPalletSize()); |
| | | segmentCommand.setBarcode(original.getBarcode()); |
| | | segmentCommand.setOriginalNavigatePath(path); |
| | | segmentCommand.setNavigatePath(segmentPath); |
| | | // 每段命令:起点=当前段首站点,终点=当前段末站点 |
| | | segmentCommand.setStationId(segmentPath.get(0)); |
| | | segmentCommand.setTargetStaNo(segmentPath.get(segmentPath.size() - 1)); |
| | | segmentCommands.add(segmentCommand); |
| | | |
| | | // 分段边界点需要同时作为下一段的起点(例如 [221,220,219] + [219,213,212]) |
| | | buildStartIdx = endIdx; |
| | | } |
| | | |
| | | if (segmentCommands.isEmpty()) { |
| | | return; |
| | | } |
| | | |
| | | int segCursor = 0; |
| | | Integer currentTarget = segmentTargets.get(segCursor); |
| | | Integer currentEndIdx = segmentEndIndices.get(segCursor); |
| | | Integer currentStartIdx = 0; |
| | | |
| | | StationCommand segCmd = new StationCommand(); |
| | | segCmd.setTaskNo(original.getTaskNo()); |
| | | segCmd.setStationId(original.getStationId()); |
| | | segCmd.setTargetStaNo(original.getTargetStaNo()); |
| | | segCmd.setCommandType(original.getCommandType()); |
| | | segCmd.setPalletSize(original.getPalletSize()); |
| | | segCmd.setNavigatePath(new ArrayList<>(path.subList(0, currentEndIdx + 1))); |
| | | sendCommand(segCmd); |
| | | while (true) { |
| | | CommandResponse commandResponse = sendCommand(segmentCommands.get(segCursor)); |
| | | if (commandResponse == null) { |
| | | try { |
| | | Thread.sleep(200); |
| | | } catch (Exception ignore) {} |
| | | continue; |
| | | } |
| | | if (commandResponse.getResult()) { |
| | | break; |
| | | } |
| | | try { |
| | | Thread.sleep(200); |
| | | } catch (Exception ignore) {} |
| | | } |
| | | |
| | | long runTime = System.currentTimeMillis(); |
| | | boolean firstRun = true; |
| | |
| | | if (remaining <= 0) { |
| | | break; |
| | | } |
| | | int currentSegEndIndex = path.indexOf(segmentTargets.get(segCursor)); |
| | | int currentSegStartIndex = segCursor == 0 ? 0 : path.indexOf(segmentTargets.get(segCursor - 1)) + 1; |
| | | int currentSegEndIndex = segmentEndIndices.get(segCursor); |
| | | int currentSegStartIndex = segCursor == 0 ? 0 : segmentEndIndices.get(segCursor - 1); |
| | | int segLen = currentSegEndIndex - currentSegStartIndex + 1; |
| | | int remainingSegment = Math.max(0, currentSegEndIndex - currentIndex); |
| | | int thresholdSegment = (int) Math.ceil(segLen * 0.3); |
| | | if (remainingSegment <= thresholdSegment && segCursor < segmentTargets.size() - 1) { |
| | | if (remainingSegment <= thresholdSegment && segCursor < segmentCommands.size() - 1) { |
| | | segCursor++; |
| | | currentEndIdx = segmentEndIndices.get(segCursor); |
| | | currentStartIdx = segmentEndIndices.get(segCursor - 1) + 1; |
| | | |
| | | StationCommand nextCmd = new StationCommand(); |
| | | nextCmd.setTaskNo(original.getTaskNo()); |
| | | nextCmd.setStationId(original.getStationId()); |
| | | nextCmd.setTargetStaNo(original.getTargetStaNo()); |
| | | nextCmd.setCommandType(original.getCommandType()); |
| | | nextCmd.setPalletSize(original.getPalletSize()); |
| | | nextCmd.setNavigatePath(new ArrayList<>(path.subList(currentStartIdx, currentEndIdx + 1))); |
| | | nextCmd.setOriginalNavigatePath(path); |
| | | while (true) { |
| | | CommandResponse commandResponse = sendCommand(nextCmd); |
| | | CommandResponse commandResponse = sendCommand(segmentCommands.get(segCursor)); |
| | | if (commandResponse == null) { |
| | | Thread.sleep(200); |
| | | continue; |