| | |
| | | import com.algo.model.*; |
| | | import com.algo.util.JsonUtils; |
| | | import com.algo.util.PathTimeCalculator; |
| | | import lombok.Data; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | |
| | | PlannedPath remainingPath = agv.getRemainingPath(); |
| | | List<PathCode> remainingCodes = new ArrayList<>(); |
| | | |
| | | // 从当前位置开始,获取剩余路径 |
| | | // 获取剩余路径 |
| | | List<PathCode> originalCodes = remainingPath.getCodeList(); |
| | | for (int i = agv.getCurrentPathIndex(); i < originalCodes.size(); i++) { |
| | | remainingCodes.add(originalCodes.get(i)); |
| | | PathCode originalCode = originalCodes.get(i); |
| | | PathCode newCode = new PathCode(originalCode.getCode(), originalCode.getDirection()); |
| | | newCode.setActionType(originalCode.getActionType()); |
| | | newCode.setTaskId(originalCode.getTaskId()); |
| | | newCode.setPosType(originalCode.getPosType()); |
| | | newCode.setLev(originalCode.getLev()); |
| | | newCode.setTargetPoint(originalCode.isTargetPoint()); |
| | | remainingCodes.add(newCode); |
| | | } |
| | | |
| | | // 创建新的路径对象 |
| | | PlannedPath processedPath = new PlannedPath(); |
| | | processedPath.setAgvId(agv.getAgvId()); |
| | | processedPath.setCodeList(remainingCodes); |
| | | processedPath.setSegId(agv.getAgvId() + "_REMAINING_" + System.currentTimeMillis()); |
| | | |
| | | if (timeCalculator != null && !remainingCodes.isEmpty()) { |
| | | // 获取AGV的下一个路径点到达时间作为起始时间 |
| | | long startTime = agv.getNextPointArrivalTime(); |
| | | |
| | | CTUPhysicalConfig config = agv.getPhysicalConfig(); |
| | | |
| | | // 估算当前速度(AGV移动中为正常速度;静止为0) |
| | | double initialSpeed = agv.hasRemainingPath() && agv.getRemainingPathLength() > 0 |
| | | ? config.getNormalSpeed() : 0.0; |
| | | |
| | | // 计算时间信息 |
| | | // arrivalTime, departureTime, cumulativeTime |
| | | timeCalculator.calculatePathTiming( |
| | | processedPath, |
| | | startTime, |
| | | config, |
| | | initialSpeed |
| | | ); |
| | | } else { |
| | | System.out.println(" 未能为剩余路径设置时间信息 - AGV: " + agv.getAgvId()); |
| | | } |
| | | |
| | | return processedPath; |
| | | } |
| | |
| | | |
| | | // 如果有方向变化,增加转向时间 |
| | | PathCode nextCode = codeList.get(i + 1); |
| | | if (!pathCode.getDirection().equals(nextCode.getDirection())) { |
| | | double turnTime = config.getTurnTime(pathCode.getDirection(), nextCode.getDirection()); |
| | | currentTime += (long) (turnTime * 1000); |
| | | // 添加null检查 |
| | | if (pathCode.getDirection() != null && nextCode.getDirection() != null) { |
| | | if (!pathCode.getDirection().equals(nextCode.getDirection())) { |
| | | double turnTime = config.getTurnTime(pathCode.getDirection(), nextCode.getDirection()); |
| | | currentTime += (long) (turnTime * 1000); |
| | | } |
| | | } |
| | | } |
| | | } |
| | |
| | | /** |
| | | * 路径规划结果类 |
| | | */ |
| | | @Data |
| | | public static class PathPlanningResult { |
| | | private int totalAgvs; |
| | | private int executingTasksCount; |