ROS学习手记 - 4 理解ROS中的基本概念_ROS_Topics

ROS学习手记 - 4 理解ROS中的基本概念_ROS_Topics

参考步骤:http://wiki.ros.org/ROS/Tutorials/UnderstandingTopics

  1. Understanding ROS’s Topics

This tutorial introduces ROS topics as well as using therostopic andrqt_plot commandline tools.

        复习一下教程里关于Topic的解释:

       

1. 准备工作

    确认运行roscore之后,开始我们的turtlesim之旅

2. 用rosrun开了两个node,

     一个是显示turtlesim窗口的turtlesim turtlesim_node

      $ rosrun turtlesim turtlesim_node

     一个是接收用户keyboard指令的turtlesim turtle_teleop_key

      $ rosrun turtlesim turtle_teleop_key

3. rqt_graph工具

    turtle_teleop_key是publisher,turtlesim_node是listener,用rqt_graph来看当前运行的nodes&topics.
    用rqt_graph工具图形化地查看当前的node和topic运行状态,主从关系等。

     $ rosrun rqt_graph rqt_graph

4. 使用rostopic工具分析topic相关信息

     $rostopic -h //查看说明

     4.1 使用rostopic echo打印发送在topic上的数据
        rostopic echo shows the data published on a topic.
        rostopic echo [topic]
     4.2 使用rostopic list查看当前的topic是从属于谁,又领导谁
        $ rostopic list -h //查看说明
     4.3 使用rostopic hz 显示topic发布的频率         
     Usage: rostopic hz [topic]

5. ROS Messages

5.1 关于Message Type 和 Topic Type 的关系,工具:rostopic & rosmsg
         $ rostopic type /turtle1/cmd_vel  //display topic type 
         $ rosmsg show geometry_msgs/Twist //show msg of ros_topic_type

         联合使用:We can also use rostopic type in conjunction with rosmsg show to get in depth information about a topic:
         For ROS Hydro and later,

           $ rostopic type /turtle1/cmd_vel | rosmsg show

         用了管道,就是把前一个命令的输出作为参数传给后一个命令。

5.2 手动发送msg on topic, 工具: rostopic pub

     rostopic pub [topic] [msg_type] [args]
         有一些解释,比如-1是执行一次,-r 1是以1Hz方式连续发送
         rostopic pub /turtle1/cmd_vel geometry_msgs/Twist -r 1 – ‘[2.0, 0.0, 0.0]’ ‘[0.0, 0.0, 1.2]’

6. 使用rqs_plot工具

rqt_plot displays a scrolling time plot of the data published on topics. Here we’ll userqt_plot to plot the data being published on the /turtle1/pose topic. First, start rqt_plot by typing

$ rosrun rqt_plot rqt_plot

in a new terminal. In the new window that should pop up, a text box in the upper left corner gives you the ability to add any topic to the plot. Typing /turtle1/pose/x will highlight the plus button, previously disabled. Press it and repeat the same procedure with the topic /turtle1/pose/y. You will now see the turtle’s x-y location plotted in the graph.

—- rostopic命令总结 —-

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
       
== 至此,我们完成了对ROS Topic的初步理解,知道了Topic type, message, rate等东东。

Published At
comments powered by Disqus