| | |
| | | |
| | | @Override |
| | | public StationCommand getCommand(StationCommandType commandType, Integer taskNo, Integer stationId, Integer targetStationId, Integer palletSize) { |
| | | return getCommand(commandType, taskNo, stationId, targetStationId, palletSize, null); |
| | | } |
| | | |
| | | @Override |
| | | public StationCommand getCommand(StationCommandType commandType, |
| | | Integer taskNo, |
| | | Integer stationId, |
| | | Integer targetStationId, |
| | | Integer palletSize, |
| | | Double pathLenFactor) { |
| | | StationCommand stationCommand = new StationCommand(); |
| | | stationCommand.setTaskNo(taskNo); |
| | | stationCommand.setStationId(stationId); |
| | |
| | | |
| | | if (commandType == StationCommandType.MOVE) { |
| | | if (!stationId.equals(targetStationId)) { |
| | | List<NavigateNode> nodes = calcPathNavigateNodes(stationId, targetStationId); |
| | | List<NavigateNode> nodes = calcPathNavigateNodes(taskNo, stationId, targetStationId, pathLenFactor); |
| | | List<Integer> path = new ArrayList<>(); |
| | | List<Integer> liftTransferPath = new ArrayList<>(); |
| | | for (NavigateNode n : nodes) { |
| | |
| | | if (Boolean.TRUE.equals(n.getIsLiftTransferPoint())) { |
| | | liftTransferPath.add(stationNo); |
| | | } |
| | | } |
| | | if (path.isEmpty()) { |
| | | log.warn("输送线命令生成失败,路径为空,taskNo={}, stationId={}, targetStationId={}", |
| | | taskNo, stationId, targetStationId); |
| | | return null; |
| | | } |
| | | stationCommand.setNavigatePath(path); |
| | | stationCommand.setLiftTransferPath(liftTransferPath); |
| | |
| | | return zyStationConnectDriver.readOriginCommand(address, length); |
| | | } |
| | | |
| | | private List<NavigateNode> calcPathNavigateNodes(Integer startStationId, Integer targetStationId) { |
| | | private List<NavigateNode> calcPathNavigateNodes(Integer taskNo, |
| | | Integer startStationId, |
| | | Integer targetStationId, |
| | | Double pathLenFactor) { |
| | | NavigateUtils navigateUtils = SpringUtils.getBean(NavigateUtils.class); |
| | | if (navigateUtils == null) { |
| | | return new ArrayList<>(); |
| | | } |
| | | return navigateUtils.calcByStationId(startStationId, targetStationId); |
| | | return navigateUtils.calcByStationId(startStationId, targetStationId, taskNo, pathLenFactor); |
| | | } |
| | | |
| | | private void executeMoveWithSeg(StationCommand original) { |
| | |
| | | } |
| | | |
| | | int segCursor = 0; |
| | | 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) {} |
| | | if (!sendSegmentWithRetry(segmentCommands.get(segCursor), original.getTaskNo())) { |
| | | return; |
| | | } |
| | | |
| | | long runTime = System.currentTimeMillis(); |
| | |
| | | int thresholdSegment = (int) Math.ceil(segLen * segmentAdvanceRatio); |
| | | if (remainingSegment <= thresholdSegment && segCursor < segmentCommands.size() - 1) { |
| | | segCursor++; |
| | | while (true) { |
| | | CommandResponse commandResponse = sendCommand(segmentCommands.get(segCursor)); |
| | | if (commandResponse == null) { |
| | | Thread.sleep(200); |
| | | continue; |
| | | } |
| | | |
| | | if (commandResponse.getResult()) { |
| | | break; |
| | | } |
| | | |
| | | Thread.sleep(200); |
| | | if (!sendSegmentWithRetry(segmentCommands.get(segCursor), original.getTaskNo())) { |
| | | break; |
| | | } |
| | | } |
| | | Thread.sleep(500); |
| | |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | private boolean sendSegmentWithRetry(StationCommand command, Integer taskNo) { |
| | | while (true) { |
| | | if (isTaskMoveReset(taskNo)) { |
| | | return false; |
| | | } |
| | | CommandResponse commandResponse = sendCommand(command); |
| | | if (commandResponse == null) { |
| | | sleepQuietly(200L); |
| | | continue; |
| | | } |
| | | if (commandResponse.getResult()) { |
| | | return true; |
| | | } |
| | | sleepQuietly(200L); |
| | | } |
| | | } |
| | | |
| | | private boolean isTaskMoveReset(Integer taskNo) { |
| | | if (taskNo == null || redisUtil == null) { |
| | | return false; |
| | | } |
| | | Object cancel = redisUtil.get(RedisKeyType.DEVICE_STATION_MOVE_RESET.key + taskNo); |
| | | return cancel != null; |
| | | } |
| | | |
| | | private void sleepQuietly(long millis) { |
| | | try { |
| | | Thread.sleep(millis); |
| | | } catch (Exception ignore) { |
| | | } |
| | | } |
| | | } |