rqt_graph 源码详细分析

rqt_graph 源码详细分析

工作区路径:/home/cp/work2/ros2Learn/ros2_humble/src/ros-visualization/rqt_graph
版本:1.3.2

rqt_graph图形化方式展示 ROS 2 计算图(节点、话题、连接关系),是调试系统结构最常用的 rqt 插件之一。


1. 仓库结构

1
2
3
4
5
6
7
8
9
10
rqt_graph/
├── plugin.xml # RosGraph 插件声明
├── scripts/rqt_graph # standalone 入口
├── src/rqt_graph/
│ ├── main.py
│ ├── ros_graph.py # Plugin 主类 RosGraph
│ ├── rosgraph2_impl.py # ROS 2 图数据获取
│ ├── dotcode.py # 生成 DOT
│ └── interactive_graphics_view.py
└── resource/RosGraph.ui

2. 插件注册

1
2
<class name="RosGraph" type="rqt_graph.ros_graph.RosGraph"
base_class_type="rqt_gui_py::Plugin">

3. 数据流

RosGraph Widgetrosgraph2_implrclpy graph API\nget_topic_names_and_types等dotcode.pyqt_dotgraph 渲染
  1. 定时或按需查询 ROS 2 graph
  2. 转为 DOT 描述
  3. qt_dotgraph 绘制为 Qt 场景
  4. interactive_graphics_view 支持缩放、拖拽

4. 核心类 RosGraph

  • 继承 rqt_gui_py.plugin.Plugin
  • 加载 RosGraph.ui
  • 刷新按钮触发 rosgraph2_impl 更新
  • 可过滤 namespace、隐藏 leaf topic 等(见 UI 选项)

5. rosgraph2_impl

封装 ROS 2 特有 API(对比 ROS 1 的 rosgraph):

  • 节点列表
  • 话题 pub/sub 关系
  • 服务(视实现版本)

6. 依赖

1
2
3
4
rqt_graph
├── rqt_gui_py, rclpy
├── qt_dotgraph (qt_gui_core)
└── python_qt_binding

7. 启动

1
ros2 run rqt_graph rqt_graph

8. 小结

rqt_graph = ROS 2 graph introspection + DOT 可视化;核心在 rosgraph2_impldotcode,UI 层薄。

文章互动

阅读 --

留言

0 条留言

正在加载留言…