marker主题 ros_了解ROS topics(主题)

1.在上面node的例子基础上再开一个Terminal后运行如下命令:rosrun turtlesim turtle_teleop_key

此时Terminal会有如下提示输出:Reading from keyboard

---------------------------

Use arrow keys to move the turtle.

这时在该Terminal按键盘的方向键,就可以看到node例子里的乌龟在移动。

2.打开一个新的Terminal,运行如下命令就可以看到node之间通过topic通信的关系:rosrun rqt_graph rqt_graph

命令运行后有如下界面:

rqt_graph

运行rostopic -h命令可以看到如下帮助信息:rostopic is a command-line tool for printinginformation about ROS Topics.

Commands:

rostopicbw display bandwidth used by topic

rostopic delay display delayof topic from timestamp in header

rostopic echo  printmessages to screen

rostopic find  find topicsby type

rostopic hz displaypublishing rate of topic

rostopic info  printinformation about active topic

rostopic list  list activetopics

rostopic pub   publish datato topic

rostopic type  print topicor field type

Type rostopic -h for moredetailed usage, e.g. 'rostopic echo -h'

4.使用rostopic echo命令查看主题发布的数据

运行rostopic echo /turtle1/cmd_vel命令,并在可以接收键盘方向键的Terminal操作方向键,可以看到如下返回信息:linear:

x: -2.0

y: 0.0

z: 0.0

angular:

x: 0.0

y: 0.0

z: 0.0

---

相应的刷新rqt_graph界面,更新为如下;

rqt_graph

5.使用rostopic list查看当前所有订阅和发布的主题

运行rostopic list -h可以看到如下帮助信息:Usage: rostopic list [/namespace]

Options:

-h, --help            show this help message and exit

-b BAGFILE, --bag=BAGFILE

list topics in .bagfile

-v, --verbose         list full details about each topic

-p                    list only publishers

-s                    list only subscribers

--host                group by host name

运行rostopic list -v可以看到如下内容:Published topics:

* /turtle1/color_sensor [turtlesim/Color] 1publisher

* /turtle1/cmd_vel [geometry_msgs/Twist] 1publisher

* /rosout [rosgraph_msgs/Log] 4 publishers

* /rosout_agg [rosgraph_msgs/Log] 1publisher

* /turtle1/pose [turtlesim/Pose] 1 publisher

Subscribed topics:

* /turtle1/cmd_vel [geometry_msgs/Twist] 2subscribers

* /rosout [rosgraph_msgs/Log] 1 subscriber

* /statistics[rosgraph_msgs/TopicStatistics] 1 subscriber

6.ROS Messages

两个通过topic通信的node需要保持相同的消息类型,使用rostopic type可以查看到相应的topic的消息类型,继而通过rosmsg show命令可以查看到该类型的定义:

运行rostopic type /turtle1/cmd_vel命令会返回如下内容:geometry_msgs/Twist

接下来使用rosmsg show geometry_msgs/Twist命令,可以看到如下返回值:geometry_msgs/Vector3 linear

float64 x

float64 y

float64 z

geometry_msgs/Vector3 angular

float64 x

float64 y

float64 z

7.了解了Topic的类型后继续了解如何通过命令发布Topic,运行rostopic pub -l /turtle1/cmd_vel  geometry_msgs/Twist -- '[2.0, 0.0, 0.0]' '[0.0, 0.0, 1.8]'命令,会发布主题为/turtle1/cmd_vel,类型为 geometry_msgs/Twist,参数为'[2.0, 0.0, 0.0]' '[0.0, 0.0, 1.0]'的带参数的主题,其中--是分隔符。

该命令运行后,会出现如下提示:publishing and latching message. Press ctrl-C to terminate

而相应的界面如下:

geometry_msgs/Twist

8.上面发布的主题只是让乌龟移动了1/4个圆,接下来让乌龟以1Hz的频率不停移动转圈,运行如下命令:rostopic pub /turtle1/cmd_vel geometry_msgs/Twist -r 1 -- '[2.0, 0.0, 0.0]' '[0.0, 0.0, -1.8]'

使用到了-r 1参数,表示执行的频率是1Hz,相应的截图如下:

geometry_msgs/Twist

此时刷新rqt_graph会有如下界面:

rqt_graph

9.接下来使用rostopic hz命令可查看指定Topic的发布频率,如下命令:rostopic hz /turtle1/cmd_vel

此时会看到如下信息不停输出:subscribed to [/turtle1/cmd_vel]

no new messages

average rate: 1.001

min: 0.999s max: 0.999sstd dev: 0.00000s window: 2

average rate: 1.000

min: 0.999s max: 1.000s std dev: 0.00062swindow: 3

average rate: 1.000

min: 0.999s max: 1.000sstd dev: 0.00054s window: 4

10.使用rqt_plot可以滚动刷新发布的主题里的数据根据时移绘制情况,执行 rosrun rqt_plot  rqt_plot命令, 有如下界面:

rosrun rqt_plot rqt_plot

此时在上面界面里的Topic框里输入/turtle1/pose/x并按回车或按后面的+号,界面会变为如下:

/turtle1/pose/x

也可以继续添加其他主题时的数据项变量名,让上面界面里显示更多对比数据。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值