fix(minco_ws): reference_path_publisher 默认订阅 /body_odom,此前永远卡住

现象:ros2 run scan_planner reference_path_publisher.py --ros-args --params-file ...
打印 'Waiting to publish 5 reference-path points' 后无限挂起,不再有任何输出。

根因:脚本硬编码订阅 **body_pose**,而该名字只存在于 run_vehicle.launch.py
给 scan_planner_node 做的**内部 remap**;总线上真实话题是 /body_odom。
全仓仅 go2_kinematic_sim / open_loop_controller(仿真、开环调试)发布 body_pose,
实车链路没有 ⇒ first_odom_time 永远为 None,try_publish 每 50 ms 直接 return。

另有第二道门槛:initial_path 必须**有订阅者**,而 FSM 只在 navi_mode=3
(REFERENCE_PATH)时才订阅它;用默认 navi_mode=1 同样会卡——两道门表现相同,
原先无法区分。

改动:
- 新增参数 odom_topic(默认 /body_odom)、path_topic(默认 initial_path)
- 卡住时每 3 s 打印具体原因(缺里程计 / 无订阅者),把静默挂起变成可诊断

install(PROGRAMS) 在 --symlink-install 下是符号链接,改动即时生效无需重编。
正确用法:vehicle_bringup.launch.py navi_mode:=3 + 直接 ros2 run(不必再加 remap)。
This commit is contained in:
walunt5
2026-10-29 21:41:39 +08:00
parent 8a412643ca
commit 791a1f554b
@@ -46,10 +46,17 @@ class ReferencePathPublisher(Node):
self.declare_parameter("frame_id", "world")
self.declare_parameter("waypoints", Parameter.Type.DOUBLE_ARRAY)
self.declare_parameter("publish_delay_sec", 0.5)
# 实车链路上里程计的话题名是 /body_odom(body_odom 节点输出)。
# "body_pose" 只是 run_vehicle.launch.py 里给 scan_planner_node 做的**内部 remap**,
# 总线上并不存在;本脚本单独 ros2 run 时拿不到那层 remap,用 body_pose 会永远等不到数据。
self.declare_parameter("odom_topic", "/body_odom")
self.declare_parameter("path_topic", "initial_path")
self.frame_id = self.get_parameter("frame_id").value
self.waypoints = parse_waypoints(self.get_parameter("waypoints").value)
self.publish_delay_sec = float(self.get_parameter("publish_delay_sec").value)
self.odom_topic = self.get_parameter("odom_topic").value
self.path_topic = self.get_parameter("path_topic").value
if not self.frame_id:
raise ValueError("frame_id must not be empty")
if not math.isfinite(self.publish_delay_sec) or self.publish_delay_sec < 0.0:
@@ -60,9 +67,9 @@ class ReferencePathPublisher(Node):
reliability=ReliabilityPolicy.RELIABLE,
durability=DurabilityPolicy.TRANSIENT_LOCAL,
)
self.path_publisher = self.create_publisher(Path, "initial_path", path_qos)
self.path_publisher = self.create_publisher(Path, self.path_topic, path_qos)
self.odom_subscription = self.create_subscription(
Odometry, "body_pose", self.odom_callback, qos_profile_sensor_data
Odometry, self.odom_topic, self.odom_callback, qos_profile_sensor_data
)
self.first_odom_time = None
self.published = False
@@ -76,9 +83,20 @@ class ReferencePathPublisher(Node):
self.first_odom_time = self.get_clock().now()
def try_publish(self):
if self.published or self.first_odom_time is None:
if self.published:
return
if self.first_odom_time is None:
self.get_logger().warn(
f"等待 {self.odom_topic} 的里程计……若该话题无发布者,"
f"检查 body_odom 是否启动(实车应为 /body_odom,不是 body_pose)",
throttle_duration_sec=3.0,
)
return
if self.path_publisher.get_subscription_count() == 0:
self.get_logger().warn(
f"{self.path_topic} 暂无订阅者——FSM 需以 navi_mode:=3 启动才会订阅参考路径",
throttle_duration_sec=3.0,
)
return
elapsed = (self.get_clock().now() - self.first_odom_time).nanoseconds / 1e9
if elapsed < self.publish_delay_sec: