8. 导航与规划消息
本文详述 planning_msgs、nav_msgs(proto Action/Service)、vision_msgs、visualization_msgs 等导航栈上层消息。
8.1 planning_msgs
头文件:autonomy/commsgs/planning_msgs.hpp
导航栈路径与里程计的核心消息包。
8.1.1 Path
字段 |
类型 |
说明 |
|---|---|---|
|
|
路径坐标系(通常 |
|
|
有序路径点 |
commsgs::planning_msgs::Path path;
path.header.stamp = commsgs::builtin_interfaces::Time::Now();
path.header.frame_id = "map";
commsgs::geometry_msgs::PoseStamped wp;
wp.header = path.header;
wp.pose.position.x = 5.0;
wp.pose.orientation.w = 1.0;
path.poses.push_back(wp);
使用方:PlannerServer 输出、ControllerServer 输入、可视化模块。
8.1.2 Odometry
字段 |
类型 |
说明 |
|---|---|---|
|
|
|
|
|
机器人坐标系( |
|
|
位姿估计 |
|
|
速度估计 |
8.1.3 Goals
字段 |
类型 |
说明 |
|---|---|---|
|
|
目标坐标系 |
|
|
多目标点序列 |
8.1.4 转换完整度
类型 |
ToProto |
FromProto |
|---|---|---|
|
✅ |
✅ |
|
⏳ 部分 |
⏳ 部分 |
|
⏳ 部分 |
⏳ 部分 |
8.3 error_code
头文件:autonomy/commsgs/proto/error_code.pb.h
仅 proto 层,无 C++ struct 包装。
8.3.1 StatusPb
message StatusPb {
ErrorCode error_code = 1;
string msg = 2;
}
8.3.2 常用错误码
错误码 |
值 |
场景 |
|---|---|---|
|
0 |
成功 |
|
6007 |
无可用路径 |
|
1013 |
控制器无有效命令 |
|
1014 |
碰撞检测 |
|
1011 |
TF 变换失败 |
|
9003 |
任务取消 |
|
9009 |
规划失败 |
|
9010 |
控制失败 |
|
7003 |
地图未就绪 |
完整列表见 autonomy/commsgs/proto/error_code.proto。
8.4 vision_msgs
头文件:autonomy/commsgs/vision_msgs.hpp
目标检测与分类消息,对齐 ROS vision_msgs。
8.4.1 2D 检测
类型 |
组成 |
说明 |
|---|---|---|
|
|
2D 点 |
|
|
2D 位姿 |
|
|
2D 包围盒 |
|
|
分类假设 |
|
|
单个 2D 检测 |
|
|
检测数组 |
8.4.2 3D 检测
类型 |
组成 |
说明 |
|---|---|---|
|
|
3D 包围盒 |
|
|
单个 3D 检测 |
|
|
检测数组 |
8.4.3 分类
类型 |
说明 |
|---|---|
|
|
|
|
|
标签元数据 |
|
视觉模块信息 |
8.4.4 使用方
autonomy/visualization 模块支持发布 Detection2DArray、BoundingBox3DArray 等到可视化服务。
8.5 visualization_msgs
头文件:autonomy/commsgs/visualization_msgs.hpp
RViz 风格可视化消息(转换函数为 stub)。
8.5.1 Marker
字段 |
说明 |
|---|---|
|
坐标系 |
|
命名空间 |
|
唯一 ID |
|
形状枚举(ARROW/CUBE/SPHERE/LINE_STRIP 等) |
|
ADD / MODIFY / DELETE |
|
位姿 |
|
尺寸 (Vector3) |
|
颜色 (ColorRGBA) |
|
点集(LINE_STRIP 等) |
|
逐点颜色 |
|
TEXT 类型文本 |
|
显示时长 |
type 枚举常用值:
值 |
常量 |
形状 |
|---|---|---|
0 |
|
箭头 |
1 |
|
立方体 |
2 |
|
球体 |
3 |
|
圆柱 |
4 |
|
折线 |
5 |
|
线段列表 |
6 |
|
立方体列表 |
7 |
|
球体列表 |
8 |
|
点云 |
9 |
|
文字 |
8.5.2 其他类型
类型 |
说明 |
|---|---|
|
Marker 批量 |
|
可交互标记 |
|
交互控制 |
|
交互反馈 |
|
右键菜单项 |
|
图像上标记 |
|
3D 网格文件 |
8.6 其他消息包
8.6.1 trajectory_msgs
类型 |
说明 |
|---|---|
|
关节位置/速度/加速度 |
|
关节轨迹序列 |
|
多自由度轨迹点 |
|
多自由度轨迹 |
cpp 转换函数为空 stub,适用于机械臂场景。
8.6.2 diagnostic_msgs
类型 |
说明 |
|---|---|
|
键值对 |
|
诊断状态(OK/WARN/ERROR/STALE) |
|
诊断数组 |
8.6.3 shape_msgs
类型 |
说明 |
|---|---|
|
基本几何体(BOX/SPHERE/CYLINDER/CONE/PLANE) |
|
三角网格 |
|
平面 |
|
三角面片 |
注意:当前 hpp 中 struct 命名空间有误,应为
shape_msgs而非builtin_interfaces。
8.6.4 vehicle_msgs
类型 |
说明 |
|---|---|
|
机器人事件(空 struct,待扩展) |
|
机器人状态(空 struct,待扩展) |
8.6.5 pcl_msgs
PCL 相关消息,当前为空 namespace,预留扩展。
8.7 导航栈消息依赖图
nav_msgs.proto (Action/Service)
│
┌────────────┼────────────┐
▼ ▼ ▼
planning_msgs geometry_msgs error_code
│ │
▼ ▼
Path PoseStamped / Twist
│ │
▼ ▼
Controller Transform
│ │
▼ ▼
cmd_vel TF tree
8.8 Action 使用模式(Autolink)
#include "autonomy/commsgs/proto/nav_msgs.pb.h"
using ActionT = commsgs::proto::nav_msgs::NavigateToPoseAction;
using Goal = ActionT::Goal;
using Feedback = ActionT::Feedback;
using Result = ActionT::Result;
auto client = node->CreateActionClient<ActionT>("navigate_to_pose");
Goal goal;
*goal.mutable_pose() = commsgs::geometry_msgs::ToProto(target_pose);
goal.set_behavior_tree("navigate_to_pose_w_replanning.xml");
client->SendGoal(goal,
[](const Result& result) {
if (result.error_code() != commsgs::proto::error_code::OK) {
// 处理错误
}
},
[](const Feedback& fb) {
// distance_remaining = fb.distance_remaining()
});
8.9 消息选择指南
需求 |
推荐消息 |
包 |
|---|---|---|
全局路径 |
|
planning_msgs |
单点目标 |
|
geometry_msgs |
多航点导航 |
|
nav_msgs proto |
路径跟踪 |
|
nav_msgs proto |
路径有效性检查 |
|
nav_msgs proto |
速度限制 |
|
nav_msgs |
目标检测可视化 |
|
vision_msgs |
路径可视化 |
|
visualization_msgs |
操作结果 |
|
error_code proto |