ROS主题理解

来源:互联网 发布:软件仓库 编辑:程序博客网 时间:2024/05/16 05:33

http://blog.sina.com.cn/s/blog_661159d50100od99.html

参考网址:
http://www.ros.org/wiki/ROS/Tutorials/UnderstandingTopics

1,小海龟例子

注意:请确定是否是在新的终端(重新打开一个终端)运行。
(1) 在新的终端打开roscore
$ roscore---如果出错,请确定关闭所有ROS命令或者路径,重试。

(2) 在新的终端打开运行小海龟界面
$ rosrun turtlesimturtlesim_node 
得到结果:
[ INFO] [1294665184.346950426]: Starting turtlesim with nodename /turtlesim
[ INFO] [1294665184.358498715]: Spawning turtle [turtle1] atx=[5.555555], y=[5.555555], theta=[0.000000]
此后小海龟运行的路径都记录在此终端

(3) 在新的终端打开鼠标控制终端
rosrun turtle_teleopturtle_teleop_key 
将鼠标放在此终端界面,然后用键盘上的“上,下,左,右”控制小海龟移动,以下是我运行的界面,是不是有点像SIAT?
(五)ROS主题理解

2,ROS 主题
就像小海龟这个例子,turtlesim_node和turtle_teleop_key 节点在ROS主题上进行通信,turtle_teleop_key在该主题上发送key strokes, turtlesim在相同主题上,预定该keystrokes。我们可以用rxgraph来显示该节点和主题间的交流。

(1) 主题显示
$ rxgraph --在新终端输入该命令
得到结果如图:
(五)ROS主题理解

下面的图诠释了,节点,主题:
(五)ROS主题理解


(2) rostopic 介绍

I,rostopic -h
$ rostopic -h
得到结果:
rostopic is a command-line tool for printing information aboutROS Topics.

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

Type rostopic <command> -h formore detailed usage, e.g. 'rostopic echo -h'

II,rostopic echo [topic]
我们查看/turtel/command_velocity主题通过turtle_teleop_key节点发布的数据,在新终端输入:
$ rostopic echo/turtle1/command_velocity
当我们把鼠标放在turtle_teleop_key 终端页面,运行小海龟时,得到结果:
---
linear: 2.0
angular: 0.0
---
linear: 0.0
angular: -2.0
---
linear: 0.0
angular: 2.0
---
linear: -2.0
angular: 0.0
---
linear: 2.0
angular: 0.0
---
linear: 2.0
angular: 0.0
这样我们再看rxgraph显示的终端,如下,在INFO栏,显示了信息
(五)ROS主题理解


III, rostopic list -h
返回所有主题当前预定和发布的数据,子命令如下:
Usage: rostopic list [/namespace]

Options:
  -h, --help          show thishelp message and exit
  -b BAGFILE,--bag=BAGFILE
                    list topics in .bag file
  -v, --verbose       list full details about each topic
  -p                 list onlypublishers
  -s                 list onlysubscribers
例如,查询当前主题的预定和发布数据:
$ rostopic  list-v
得到结果:
Published topics:
 * /turtle1/color_sensor [turtlesim/Color] 1publisher
 * /turtle1/command_velocity[turtlesim/Velocity] 1 publisher
 * /rosout [roslib/Log] 3 publishers
 * /rosout_agg [roslib/Log] 1 publisher
 * /turtle1/pose [turtlesim/Pose] 1publisher

Subscribed topics:
 * /turtle1/command_velocity[turtlesim/Velocity] 2 subscribers
 * /rosout [roslib/Log] 1 subscriber

3,ROS消息
在ROS主题上,是通过消息进行通信的。发布者(turtle_teleop_key)和预定者(turtlesim_node)之间的通信,发布者和预定者发送和接受的同一类型的消息,这就决定了发布者决定主题类型。

I, rostopic type [topic]
返回当前运行主题的消息类型,例如小海龟例子:
$ rostopic type/turtle1/command_velocity
得到结果:
turtlesim/Velocity
rosmsgshow turtlesim/Velocity --查询消息类型细节
得到结果:
float32linear float32 angular

4,将消息应用到主题上

I,rostopic pub [topic] [msg_type] [args]
将数据发布到当前主题上,例如小海龟例子:
$rostopic pub -1 /turtle1/command_velocity turtlesim/Velocity --2.0 1.8
命令诠释:
rostopicpub ---在给定主题上发布消息
-1---此选项表示rostopic只发布一个消息,然后退出
/turtle1/command_velocity---给定的主题名
turtlesim/Velocity---在给定主题上发布的消息类型
-----双负号,表示词法选择器在此后的参数都不可用。这种情况发生在错误参数比如负数
2.01.8 ---当前主题消息的类型的数据值

得到的结果:
终端显示:
publishingand latching message for 3.0 seconds
图运行的结果是:
(五)ROS主题理解

另外,如果要保持小海龟一直移动,可以采用-r,例如:
$ rostopic pub /turtle1/command_velocity turtlesim/Velocity -r 1 --2.0 -1.8
运行结果:

(五)ROS主题理解
我们查看下rxgraph图显示:
(五)ROS主题理解
我们可以看到小海龟运行一个圈的轨迹。

II,rostopic hz [topic]
是用来报告哪个数据发布率,比如小海龟的例子:
$ rostopic hz /turtle1/pose
得到结果:
subscribed to [/turtle1/pose]
average rate: 44.767
min: 0.000s max: 0.053s std dev: 0.02014s window: 43
average rate: 44.994
min: 0.000s max: 0.054s std dev: 0.02016s window: 87
average rate: 45.382
min: 0.000s max: 0.054s std dev: 0.01993s window: 134
average rate: 45.032
min: 0.000s max: 0.063s std dev: 0.02003s window: 177
average rate: 45.165
min: 0.000s max: 0.063s std dev: 0.01999s window: 224

III,rxplot
是展示画出该主题上发布的数据,比如我们对小海龟转圈,这个例子
(五)ROS主题理解

rxplot/turtle1/pose/x,/turtle1/pose/y /turtle1/pose/theta---针对上面图得到:
(五)ROS主题理解


原创粉丝点击