From 143de653d25cd7111490df7a80bbc8e3b27531ea Mon Sep 17 00:00:00 2001 From: luoyifan Date: Sun, 22 Jun 2025 16:43:05 +0800 Subject: [PATCH] =?UTF-8?q?double=20->=20float=20=E8=8A=82=E7=BA=A6?= =?UTF-8?q?=E7=A9=BA=E9=97=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/galaxis/rcs/plan/path/AStarNodeState.java | 8 ++++---- .../java/com/galaxis/rcs/plan/path/AStarPathPlanner.java | 16 ++++++++-------- .../java/com/galaxis/rcs/plan/path/GraphInitializer.java | 6 +++--- .../java/com/galaxis/rcs/plan/path/NavigationGraph.java | 8 ++++---- .../java/com/galaxis/rcs/plan/path/NavigationNode.java | 14 ++++++++------ .../main/java/com/galaxis/rcs/plan/path/PathSegment.java | 2 +- yvan-rcs-dev/.lck | 0 7 files changed, 28 insertions(+), 26 deletions(-) create mode 100644 yvan-rcs-dev/.lck diff --git a/servo/src/main/java/com/galaxis/rcs/plan/path/AStarNodeState.java b/servo/src/main/java/com/galaxis/rcs/plan/path/AStarNodeState.java index 129905d..e7f5f10 100644 --- a/servo/src/main/java/com/galaxis/rcs/plan/path/AStarNodeState.java +++ b/servo/src/main/java/com/galaxis/rcs/plan/path/AStarNodeState.java @@ -6,8 +6,8 @@ package com.galaxis.rcs.plan.path; public record AStarNodeState( String nodeId, // 当前节点ID int direction, // 当前方向 (0,90,180,270) - double gCost, // 实际代价 - double hCost, // 启发式代价 + float gCost, // 实际代价 + float hCost, // 启发式代价 AStarNodeState parent // 父节点 ) implements Comparable { @@ -17,13 +17,13 @@ public record AStarNodeState( } // 总代价 - public double fCost() { + public float fCost() { return gCost + hCost; } @Override public int compareTo(AStarNodeState other) { - return Double.compare(this.fCost(), other.fCost()); + return Float.compare(this.fCost(), other.fCost()); } } diff --git a/servo/src/main/java/com/galaxis/rcs/plan/path/AStarPathPlanner.java b/servo/src/main/java/com/galaxis/rcs/plan/path/AStarPathPlanner.java index 99284e5..0c1a830 100644 --- a/servo/src/main/java/com/galaxis/rcs/plan/path/AStarPathPlanner.java +++ b/servo/src/main/java/com/galaxis/rcs/plan/path/AStarPathPlanner.java @@ -26,7 +26,7 @@ public class AStarPathPlanner { PriorityQueue openSet = new PriorityQueue<>(); // 状态管理 - Map gScoreMap = new HashMap<>(); + Map gScoreMap = new HashMap<>(); Map cameFrom = new HashMap<>(); // 初始化起点 @@ -39,7 +39,7 @@ public class AStarPathPlanner { ); openSet.add(start); - gScoreMap.put(start.stateKey(), 0.0); + gScoreMap.put(start.stateKey(), 0.0f); while (!openSet.isEmpty()) { AStarNodeState current = openSet.poll(); @@ -55,12 +55,12 @@ public class AStarPathPlanner { PathSegment segment = graph.getPathSegment(current.nodeId(), neighbor.id()); if (segment == null) continue; - double moveCost = segment.distance(); - double tentativeGCost = current.gCost() + moveCost; + float moveCost = segment.distance(); + float tentativeGCost = current.gCost() + moveCost; String neighborKey = neighbor.id() + ":" + current.direction(); // 发现更好路径 - if (tentativeGCost < gScoreMap.getOrDefault(neighborKey, Double.MAX_VALUE)) { + if (tentativeGCost < gScoreMap.getOrDefault(neighborKey, Float.MAX_VALUE)) { AStarNodeState neighborState = new AStarNodeState( neighbor.id(), current.direction(), @@ -80,12 +80,12 @@ public class AStarPathPlanner { if (currentNode != null && currentNode.rotatable()) { for (int rotation : new int[]{90, -90}) { int newDirection = (current.direction() + rotation + 360) % 360; - double rotateCost = 1.0; // 旋转代价 - double tentativeGCost = current.gCost() + rotateCost; + float rotateCost = 1.0f; // 旋转代价 + float tentativeGCost = current.gCost() + rotateCost; String rotatedKey = current.nodeId() + ":" + newDirection; // 发现更好路径 - if (tentativeGCost < gScoreMap.getOrDefault(rotatedKey, Double.MAX_VALUE)) { + if (tentativeGCost < gScoreMap.getOrDefault(rotatedKey, Float.MAX_VALUE)) { AStarNodeState rotatedState = new AStarNodeState( current.nodeId(), newDirection, diff --git a/servo/src/main/java/com/galaxis/rcs/plan/path/GraphInitializer.java b/servo/src/main/java/com/galaxis/rcs/plan/path/GraphInitializer.java index 2dbd96f..698c7a5 100644 --- a/servo/src/main/java/com/galaxis/rcs/plan/path/GraphInitializer.java +++ b/servo/src/main/java/com/galaxis/rcs/plan/path/GraphInitializer.java @@ -25,9 +25,9 @@ public class GraphInitializer { continue; } - List> tf = (List>) nodeData.get("tf"); - double x = tf.get(0).get(0); - double z = tf.get(0).get(2); + List> tf = (List>) nodeData.get("tf"); + float x = tf.get(0).get(0); + float z = tf.get(0).get(2); // 检查是否为可旋转点 Map dt = (Map) nodeData.get("dt"); diff --git a/servo/src/main/java/com/galaxis/rcs/plan/path/NavigationGraph.java b/servo/src/main/java/com/galaxis/rcs/plan/path/NavigationGraph.java index 9ec0174..08a4db7 100644 --- a/servo/src/main/java/com/galaxis/rcs/plan/path/NavigationGraph.java +++ b/servo/src/main/java/com/galaxis/rcs/plan/path/NavigationGraph.java @@ -20,7 +20,7 @@ public class NavigationGraph { // 添加双向路径 public void addBidirectionalPath(NavigationNode a, NavigationNode b) { - double distance = a.distanceTo(b); + float distance = a.distanceTo(b); pathSegments.put(a.id() + "->" + b.id(), new PathSegment(a, b, distance)); pathSegments.put(b.id() + "->" + a.id(), new PathSegment(b, a, distance)); @@ -55,15 +55,15 @@ public class NavigationGraph { return nodes.values().parallelStream() .filter(NavigationNode::rotatable) - .min(Comparator.comparingDouble(start::distanceTo)) + .min(Comparator.comparing(start::distanceTo)) .orElse(null); } // 计算启发式代价 (使用欧几里得距离) - public double heuristicCost(String fromId, String toId) { + public float heuristicCost(String fromId, String toId) { NavigationNode from = nodes.get(fromId); NavigationNode to = nodes.get(toId); - if (from == null || to == null) return Double.MAX_VALUE; + if (from == null || to == null) return Float.MAX_VALUE; return from.distanceTo(to); } } diff --git a/servo/src/main/java/com/galaxis/rcs/plan/path/NavigationNode.java b/servo/src/main/java/com/galaxis/rcs/plan/path/NavigationNode.java index c8a09b0..2cac8a6 100644 --- a/servo/src/main/java/com/galaxis/rcs/plan/path/NavigationNode.java +++ b/servo/src/main/java/com/galaxis/rcs/plan/path/NavigationNode.java @@ -1,19 +1,21 @@ package com.galaxis.rcs.plan.path; +import org.clever.core.Conv; + /** * 路标节点(地图中的顶点) */ public record NavigationNode( String id, // 节点ID (如 "20", "charger1") - double x, // 向右增长 - double z, // 向下增长 (y无效) + float x, // 向右增长 + float z, // 向下增长 (y无效) boolean rotatable // 是否为可旋转位 ) implements Comparable { // 计算到另一个节点的欧几里得距离 - public double distanceTo(NavigationNode other) { - double dx = this.x - other.x; - double dz = this.z - other.z; - return Math.sqrt(dx * dx + dz * dz); + public float distanceTo(NavigationNode other) { + float dx = this.x - other.x; + float dz = this.z - other.z; + return Conv.asFloat(Math.sqrt(dx * dx + dz * dz)); } @Override diff --git a/servo/src/main/java/com/galaxis/rcs/plan/path/PathSegment.java b/servo/src/main/java/com/galaxis/rcs/plan/path/PathSegment.java index 4ae4654..68c7b0e 100644 --- a/servo/src/main/java/com/galaxis/rcs/plan/path/PathSegment.java +++ b/servo/src/main/java/com/galaxis/rcs/plan/path/PathSegment.java @@ -6,7 +6,7 @@ package com.galaxis.rcs.plan.path; public record PathSegment( NavigationNode start, // 起点节点 NavigationNode end, // 终点节点 - double distance // 路径距离 + float distance // 路径距离 ) { // 路径唯一标识 public String key() { diff --git a/yvan-rcs-dev/.lck b/yvan-rcs-dev/.lck new file mode 100644 index 0000000..e69de29