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/RemainingPathProcessor.java | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++---
1 files changed, 51 insertions(+), 3 deletions(-)
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 15f7545..a9e0085 100644
--- a/algo-zkd/src/main/java/com/algo/service/RemainingPathProcessor.java
+++ b/algo-zkd/src/main/java/com/algo/service/RemainingPathProcessor.java
@@ -34,6 +34,7 @@
/**
* 澶勭悊鎵�鏈塁TU鐨勫墿浣欒矾寰勶紝鏋勫缓鏃剁┖鍗犵敤琛�
+ * 馃敡 淇锛氬悓鏃跺鐞嗘湁鍓╀綑璺緞鐨凙GV鍜岄潤姝GV鐨勫綋鍓嶄綅缃崰鐢�
*
* @param agvStatusList CTU鐘舵�佸垪琛�
* @return 鏃剁┖鍗犵敤琛紝key涓�"x,y,timeSlot"锛寁alue涓篊TU缂栧彿
@@ -43,11 +44,50 @@
for (AGVStatus agv : agvStatusList) {
if (agv.hasRemainingPath()) {
+ // 澶勭悊鏈夊墿浣欒矾寰勭殑AGV
processRemainingPathOccupancy(agv, occupancyMap);
+ } else if (agv.getPosition() != null && !agv.getPosition().isEmpty()) {
+ // 澶勭悊闈欐AGV鐨勫綋鍓嶄綅缃崰鐢�
+ processStaticAgvOccupancy(agv, occupancyMap);
}
}
return occupancyMap;
+ }
+
+ /**
+ * 澶勭悊闈欐AGV鐨勪綅缃崰鐢�
+ *
+ * @param agv CTU鐘舵��
+ * @param occupancyMap 鏃剁┖鍗犵敤琛�
+ */
+ private void processStaticAgvOccupancy(AGVStatus agv, Map<String, String> occupancyMap) {
+ String position = agv.getPosition();
+ if (position == null || position.isEmpty()) {
+ return;
+ }
+
+ // 鑾峰彇浣嶇疆鍧愭爣
+ int[] coord = JsonUtils.getCoordinate(position, pathMapping);
+ if (coord == null) {
+ return;
+ }
+
+ CTUPhysicalConfig config = agv.getPhysicalConfig();
+ long currentTime = System.currentTimeMillis() / 1000; // 杞崲涓虹
+
+ // 闈欐AGV鍗犵敤褰撳墠浣嶇疆鐨勯暱鏃堕棿娈碉紙鍋囪300绉掞級
+ long occupancyDuration = 300; // 300绉掔殑鍗犵敤鏃堕棿
+
+ for (long timeSlot = currentTime; timeSlot < currentTime + occupancyDuration; timeSlot++) {
+ String spaceTimeKey = coord[0] + "," + coord[1] + "," + timeSlot;
+ occupancyMap.put(spaceTimeKey, agv.getAgvId());
+
+ occupyAdjacentSpaces(coord, timeSlot, agv.getAgvId(), occupancyMap, config);
+ }
+
+ System.out.println(" 闈欐AGV " + agv.getAgvId() + " 鍗犵敤浣嶇疆 " + position +
+ " (鍧愭爣: " + coord[0] + "," + coord[1] + ") " );
}
/**
@@ -153,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;
}
}
@@ -168,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