用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
直接命令不会经过审查 Prompt;运行前请先检查来源。
npx skills add https://github.com/MIUAV/vibe-coding-ros2 --skill ros2-debug命令会保持在同一行。复制前请横向滚动并检查完整内容。
想先保存到本地?可下载 SkillsMP 当前能够提供的文件。
正在显示 SKILL.md
基于 SOC 职业分类
| name | ros2-debug |
| description | ROS2 调试技能 — 编译错误诊断、运行时崩溃处理、QoS 静默失败排查、Lifecycle 状态机调试 |
| argument-hint | ROS2编译错误 OR rclcpp崩溃 OR 话题不通 OR Lifecycle卡住 OR ros2 topic echo OR colcon build失败 |
| user-invocable | true |
ROS2 问题按频率排列:
# 编译错误
colcon build --event-handlers console_direct+
# 运行时崩溃
gdb -ex run -ex bt --args <你的节点>
# 话题通信
ros2 topic list # 列出所有话题
ros2 topic info <topic> # 查看话题类型/QoS
ros2 topic hz <topic> # 频率监控
ros2 topic echo <topic> # 实时打印数据
# 节点通信
ros2 node list # 列出所有节点
ros2 node info <node> # 节点订阅/发布/服务
# 服务调用
ros2 service list # 列出所有服务
ros2 service call <service> <type> <data>
# 参数
ros2 param list # 节点参数
ros2 param get <node> <param> # 获取参数值
ros2 param set <node> <param> <value> # 设置参数
# 生命周期
ros2 lifecycle list <node> # 查看节点生命周期状态
ros2 lifecycle set <node> <state> # 切换状态
# 代价地图可视化
ros2 run nav2_map_server map_saver_cli -f my_map
# 工具箱
ros2 run rqt_graph rqt_graph # 节点关系图(最常用!)
ros2 run rqt_topic rqt_topic # 话题监控
ros2 run rqt_console rqt_console # 日志查看器
ros2 run rqt_msg rqt_msg # 消息定义查看器
undefined reference to 'ros2_xxx'原因: 缺少 ament_export_dependencies 或 ament_target_dependencies
修复: 在 CMakeLists.txt 中添加:
ament_target_dependencies(${PROJECT_NAME}
rclcpp
std_msgs
)
ament_export_dependencies(rclcpp)
fatal error: rclcpp/rclcpp.hpp: No such file or directory原因: CMakeLists.txt 缺少 find_package(rclcpp REQUIRED)
修复: 在 find_package 区域添加:
find_package(rclcpp REQUIRED)
find_package(std_msgs REQUIRED)
ament_export_include_directories: .../include is not a directory原因: include 目录不存在或路径错误
修复: 确认目录结构:
ls -la <package>/include/<package>/
Could not find a package 'ament_auto'修复: 改用标准 ament_cmake:
find_package(ament_cmake REQUIRED)
find_package(rclcpp REQUIRED)
library path 链接错误原因: install 名/库名不匹配
修复: 检查 CMakeLists.txt 的 install 语句:
install(TARGETS ${PROJECT_NAME}
RUNTIME DESTINATION ${AMENT_PACKAGE_BIN_DESTINATION}
LIBRARY DESTINATION ${AMENT_PACKAGE_LIB_DESTINATION}
)
定位方法:
gdb -ex run -ex bt --args colcon test --packages-select <package> --event-handlers console_direct+
# 或
gdb ./install/<package>/lib/<package>/<node>
(gdb) run
# 等待崩溃
(gdb) bt # 打印堆栈
常见原因:
原因: 节点名以 / 开头(绝对名),ROS2 不允许。
修复:
// ❌ 错误
auto node = rclcpp::Node::make_shared("/my_node"); // 错误!
// ✅ 正确
auto node = rclcpp::Node::make_shared("my_node"); // 相对名称
原因: QoS 不兼容。
修复: 见 ros2-qos-checker 技能。
# 查看当前状态
ros2 lifecycle list /my_lifecycle_node
# 手动触发转换
ros2 lifecycle set /my_lifecycle_node configure
ros2 lifecycle set /my_lifecycle_node activate
常见原因: 在 on_activate 里执行了阻塞操作。
// ❌ on_activate 禁止阻塞
rclcpp_lifecycle::node_interfaces::LifecycleNodeInterface::CallbackReturn
on_activate() override {
// 不要在这里 sleep()、等待服务、循环查询
RCLCPP_INFO(get_logger(), "Activating...");
// ✅ 只做状态设置,立即返回
return rclcpp_lifecycle::node_interfaces::LifecycleNodeInterface::CallbackReturn::SUCCESS;
}
排查步骤:
# 1. 确认话题存在
ros2 topic list | grep <topic>
# 2. 查看 QoS 配置
ros2 topic info /<topic> --verbose
# 3. 检查发布/订阅是否在同一命名空间
ros2 node list
# 4. 尝试直接 echo
ros2 topic echo /<topic>
常见原因:
/ns1,订阅在 /ns2)# 列出服务
ros2 service list
# 查看服务类型
ros2 service type /add_two_ints
# 同步调用
ros2 service call /add_two_ints example_interfaces/srv/AddTwoInts "{a: 2, b: 3}"
1. colcon build --packages-select <pkg> 2>&1
2. 如有错误 → 提取错误类型 → 应用本技能修复建议
3. 重新编译 → 直到 0 错误
4. ros2 run <pkg> <node> --ros-args --log-level debug
5. ros2 topic list / echo 验证数据流通
# ❌ 禁止:只用 printf 调试(ROS2 用 RCLCPP_INFO)
std::cout << "debug" << std::endl; // 太原始
RCLCPP_INFO(this->get_logger(), "Current value: %d", val); // ✅
# ❌ 禁止:kill -9 强制杀掉节点(导致状态机混乱)
kill -9 <pid> # 可能留下僵尸资源
# ✅ 正确:优雅关闭
ros2 lifecycle set /node shutdown