jianghaiyue
2 天以前 71f29001d7ec27a72b33143dc104abd34822268a
更新了null值处理
3个文件已修改
68 ■■■■ 已修改文件
algo-zkd/src/main/java/com/algo/service/CollisionDetector.java 9 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
algo-zkd/src/main/java/com/algo/service/PathPlanningService.java 45 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
algo-zkd/src/main/java/com/algo/service/RemainingPathProcessor.java 14 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
algo-zkd/src/main/java/com/algo/service/CollisionDetector.java
@@ -198,9 +198,12 @@
            travelTime += (long) ((distance / speed) * 1000); // 转换为毫秒
            // 如果有方向变化,增加转向时间
            if (!currentCode.getDirection().equals(previousCode.getDirection())) {
                double turnTime = calculateTurnTime(previousCode.getDirection(), currentCode.getDirection(), config);
                travelTime += (long) (turnTime * 1000);
            // 添加null检查
            if (currentCode.getDirection() != null && previousCode.getDirection() != null) {
                if (!currentCode.getDirection().equals(previousCode.getDirection())) {
                    double turnTime = calculateTurnTime(previousCode.getDirection(), currentCode.getDirection(), config);
                    travelTime += (long) (turnTime * 1000);
                }
            }
            // 考虑加速和减速时间
algo-zkd/src/main/java/com/algo/service/PathPlanningService.java
@@ -4,7 +4,6 @@
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;
@@ -270,17 +269,45 @@
        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;
    }
@@ -378,9 +405,12 @@
                // 如果有方向变化,增加转向时间
                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);
                    }
                }
            }
        }
@@ -613,7 +643,6 @@
    /**
     * 路径规划结果类
     */
    @Data
    public static class PathPlanningResult {
        private int totalAgvs;
        private int executingTasksCount;
algo-zkd/src/main/java/com/algo/service/RemainingPathProcessor.java
@@ -193,8 +193,16 @@
            String currentDirection = currentCode.getDirection();
            String nextDirection = nextCode.getDirection();
            if (!currentDirection.equals(nextDirection)) {
                stayTime += config.getTurnTime(currentDirection, nextDirection);
            if (currentDirection != null && nextDirection != null) {
                if (!currentDirection.equals(nextDirection)) {
                    stayTime += config.getTurnTime(currentDirection, nextDirection);
                }
            } else {
                if (pathIndex == agv.getCurrentPathIndex()) {
                    System.out.println("AGV " + agv.getAgvId() +
                                     " 的剩余路径中direction字段为null");
                }
                stayTime += 0.5;
            }
        }
@@ -208,7 +216,7 @@
                    stayTime += 2.0; // 放货需要2秒
                    break;
                case "3": // 充电
                    stayTime += 10.0; // 充电停靠需要10秒
                    stayTime += 100.0; // 充电停靠
                    break;
                default:
                    stayTime += 1.0; // 其他动作需要1秒