ros_tutorials
  • 简介
  • 1 安装并配置ROS环境
    • 1.1 安装ROS
    • 1.2 管理环境变量
    • 1.3 创建ROS工作空间
  • 2 ROS文件系统介绍
    • 2.1 快速了解文件系统概念
    • 2.2 文件系统工具
    • 2.3 回顾
  • 3 创建ROS程序包(Packages)
    • 3.1 catkin程序包由什么组成?
    • 3.2 在catkin工作空间中的程序包
    • 3.3 创建一个catkin程序包
    • 3.4 编译程序包
    • 3.5 程序包依赖关系
    • 3.6 自定义你的程序包
  • 4 编译ROS程序包(packages)
    • 4.1 使用 catkin_make
    • 4.2 编译你的程序包Package
  • 5 理解ROS节点(nodes)
    • 5.1 图(Graph)概念
    • 5.2 节点(Nodes)
    • 5.3 客户端库(Client Libraries)
    • 5.4 roscore
    • 5.5 使用rosnode
    • 5.6 使用rosrun
    • 5.7 回顾
  • 6 理解ROS话题(topics)
    • 6.1 开始
    • 6.2 ros topics
    • 6.3 ROS Messages
    • 6.4 继续学习 rostopic
    • 6.5 使用 rqt_plot
  • 7 理解ROS服务和参数
    • 7.1 ROS Services
    • 7.2 使用rosservice
    • 7.3 使用 rosparam
  • 8 使用 rqt_console 和 roslaunch
    • 8.1 预先安装rqt和turtlesim程序包
    • 8.2 使用rqt_console和rqt_logger_level
  • 9 使用rosed编辑ROS中的文件
    • 9.1 使用 rosed
    • 9.2 使用Tab键补全文件名
    • 9.3编辑器
  • 10 创建ROS消息和ROS服务
    • 10.1 消息(msg)和服务(srv)介绍
    • 10.2 使用 msg
    • 10.3 使用 srv
    • 10.4 msg和srv都需要的步骤
    • 10.5 获得帮助
    • 10.6 回顾
  • 11 编写简单的Publisher和Subscriber(C++)
    • 11.1 编写Publisher Node
    • 11.2 编写Subscriber Node
    • 11.3 编译nodes
  • 12 编写简单的Publisher和Subscriber(Python)
    • 12.1 编写Publisher Node
    • 12.2 编写Subscriber Node
    • 12.3 编译nodes
  • 13 测试消息Publisher和Subscriber
    • 13.1 启动发布器(Publisher)
    • 13.2 启动订阅器(Subscriber)
  • 14 编写简单的Service和Client (C++)
    • 14.1 编写Service节点
    • 14.2 编写Client节点
    • 14.3 编译nodes
  • 15 编写简单的Service和Client (Python)
    • 15.1 编写Service Node
    • 15.2 编写Client节点
    • 15.3 编译nodes
    • 15.4 试试看
  • 16 测试简单的Service和Client
    • 16.1 运行Service
    • 16.2 运行Client
    • 16.3 关于Service和Client节点的更多例子
  • 17 录制与回放数据
    • 17.1 录制数据(通过创建一个bag文件)
    • 17.2 检查并回放bag文件
    • 17.3 录制数据子集
    • 17.4 rosbag record/play 命令的局限性
  • 18 roswtf入门
    • 18.1 安装检查
    • 18.2 运行时检查(在有ROS节点运行时)
    • 18.3 错误报告
  • 19 探索ROS维基
    • 19.1 基础
    • 19.2 高级
  • 20 接下来做什么
    • 20.1 使用模拟器
    • 20.2 使用 RViz
    • 20.3 理解 TF
    • 20.4 更进一步
Powered by GitBook
On this page
  • 6.2.1 使用 rqt_graph
  • 6.2.2 rostopic介绍
  • 6.2.3 使用 rostopic echo
  • 6.2.4 使用 rostopic list
  1. 6 理解ROS话题(topics)

6.2 ros topics

Previous6.1 开始Next6.3 ROS Messages

Last updated 7 years ago

turtlesim_node节点和turtle_teleop_key节点之间是通过一个ROS话题来互相通信的。

turtle_teleop_key在一个话题上发布按键输入消息,而turtlesim则订阅该话题以接收该消息。 下面让我们使用rqt_graph来显示当前运行的节点和话题。

6.2.1 使用 rqt_graph

rqt_graph能够创建一个显示当前系统运行情况的动态图形。 rqt_graph是rqt功能包中的一部分。 如果你没有安装,请通过以下命令来安装:

$ sudo apt-get install ros-indigo-rqt
$ sudo apt-get install ros-indigo-rqt-common-plugins

在一个新终端中运行:

$ rosrun rqt_graph rqt_graph

你会看到类似下图所示的图形:

image

如果你将鼠标放在/turtle1/command_velocity上方,相应的ROS节点(蓝色和绿色)和话题(红色)就会高亮显示。

正如你所看到的turtlesim_node和turtle_teleop_key节点正通过一个名为/turtle1/command_velocity的话题来互相通信。

6.2.2 rostopic介绍

rostopic命令工具能让你获取有关ROS话题的信息。 你可以使用help选项查看rostopic的子命令:

$ rostopic -h

    rostopic bw     display bandwidth used by topic
    rostopic echo   print messages to screen
    rostopic hz     display publishing rate of topic    
    rostopic list   print information about active topics
    rostopic pub    publish data to topic
    rostopic type   print topic type

或者在rostopic之后按Tab键打印可能的子命令:

$ rostopic 
bw    echo  find  hz    info  list  pub   type

接下来我们将使用其中的一些子命令来查看turtlesim。

6.2.3 使用 rostopic echo

rostopicecho可以显示在某个话题上发布的数据。 用法:

rostopic echo [topic]

让我们在一个新终端中看一下turtle_teleop_key节点在/turtle1/command_velocit话题上发布的数据。

$ rostopic echo /turtle1/cmd_vel

接下来我们通过按下方向键使turtle_teleop_key节点发布数据。

记住如果turtle没有动起来的话就需要你重新选中turtle_teleop_key节点运行时所在的终端窗口。

现在当你按下向上方向键时应该会看到下面的信息:

linear: 
  x: 2.0
  y: 0.0
  z: 0.0
angular: 
  x: 0.0
  y: 0.0
  z: 0.0
---

现在让我们再看一下rqt_graph(你可能需要刷新一下ROS graph)。

6.2.4 使用 rostopic list

rostopic list能够列出所有当前订阅和发布的话题。 让我们查看一下list子命令需要的参数,在一个新终端中运行:

$ rostopic list -h

显示

Usage: rostopic list [/topic]

Options:
  -h, --help            show this help message and exit
  -b BAGFILE, --bag=BAGFILE
                        list topics in .bag file
  -v, --verbose         list full details about each topic
  -p                    list only publishers
  -s                    list only subscribers

在rostopic list中使用verbose选项:

$ rostopic list -v

这会显示出有关所发布和订阅的话题及其类型的详细信息。

Published topics:
 * /turtle1/color_sensor [turtlesim/Color] 1 publisher
 * /turtle1/cmd_vel [geometry_msgs/Twist] 1 publisher
 * /rosout [rosgraph_msgs/Log] 2 publishers
 * /rosout_agg [rosgraph_msgs/Log] 1 publisher
 * /turtle1/pose [turtlesim/Pose] 1 publisher

Subscribed topics:
 * /turtle1/cmd_vel [geometry_msgs/Twist] 1 subscriber
 * /rosout [rosgraph_msgs/Log] 1 subscriber
image

正如你所看到的rostopic echo(红色显示部分)现在也订阅了turtle1/command_velocity话题。

image