From 71f29001d7ec27a72b33143dc104abd34822268a Mon Sep 17 00:00:00 2001 From: jianghaiyue <jianghaiyue@zkyt.com> Date: 星期二, 21 十月 2025 09:47:35 +0800 Subject: [PATCH] 更新了null值处理 --- algo-zkd/src/main/java/com/algo/service/CollisionDetector.java | 9 +++- algo-zkd/src/main/java/com/algo/service/PathPlanningService.java | 45 ++++++++++++++++++---- algo-zkd/src/main/java/com/algo/service/RemainingPathProcessor.java | 14 +++++- 3 files changed, 54 insertions(+), 14 deletions(-) diff --git a/algo-zkd/src/main/java/com/algo/service/CollisionDetector.java b/algo-zkd/src/main/java/com/algo/service/CollisionDetector.java index 2e378c5..2398831 100644 --- a/algo-zkd/src/main/java/com/algo/service/CollisionDetector.java +++ b/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); + } } // 鑰冭檻鍔犻�熷拰鍑忛�熸椂闂� diff --git a/algo-zkd/src/main/java/com/algo/service/PathPlanningService.java b/algo-zkd/src/main/java/com/algo/service/PathPlanningService.java index 026b64b..705d554 100644 --- a/algo-zkd/src/main/java/com/algo/service/PathPlanningService.java +++ b/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(); + + // 浼扮畻褰撳墠閫熷害锛圓GV绉诲姩涓负姝e父閫熷害锛涢潤姝负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; diff --git a/algo-zkd/src/main/java/com/algo/service/RemainingPathProcessor.java b/algo-zkd/src/main/java/com/algo/service/RemainingPathProcessor.java index 0c411d6..a9e0085 100644 --- a/algo-zkd/src/main/java/com/algo/service/RemainingPathProcessor.java +++ b/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瀛楁涓簄ull"); + } + 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绉� -- Gitblit v1.9.1