十七步学习ROS Toptics -ubuntu 18.04 melodic- ROS/教程/理解主题的概念:ROS/Tutorials/Understanding ROS Toptics

1,打开一个终端运行内核:

$ roscore

2,再打开一个终端运行仿真节点:

$ rosrun turtlesim turtlesim_node

3,再打开一个终端运行键盘:

$ rosrun turtlesim turtle_teleop_key

4,安装rqt-graph工具包和通讯插件

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

5,再打开一个终端运行rqt-graph:

$ rosrun rqt_graph rqt_graph

6,鼠标放在/turtle1/cmd_vel上观察节点通信路径颜色变化:

7,查看ROS topics 的help信息:

$ rostopic -h

***************************************

uu@uu-HP-EliteBook-6930P-Notebook-PC:~$ rostopic -h
rostopic is a command-line tool for printing information about ROS Topics.

Commands:
    rostopic bw    display bandwidth used by topic
    rostopic delay    display delay of topic from timestamp in header
    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 or field type

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

****************************************

8,再打开一个终端使用 rostopic echo:

$ rostopic echo /turtle1/cmd_vel

9,上面一步我们看不到任何变化信息,下面我们通过按键盘操作从而通过turtle_teleop_key 发布数据;也就是说

这时候再次用键盘控制机器人运动,可以发现终端显示了长度和角度的空间坐标系数值。

10,此时我们再回到rqt_graph窗口,点击左上方的刷新按钮,可以发现新增了一组命令会话路径:

11,学习使用ROS主题(话题,会话)列表查看命令:

Using rostopic list:

$ rostopic list -h
$ rostopic list -v

**********************************************

uu@uu-HP-EliteBook-6930P-Notebook-PC:~$  rostopic list -h
Usage: rostopic list [/namespace]

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
  --host                group by host name
uu@uu-HP-EliteBook-6930P-Notebook-PC:~$ rostopic list -v

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

Subscribed topics:
 * /turtle1/cmd_vel [geometry_msgs/Twist] 2 subscribers
 * /rosout [rosgraph_msgs/Log] 1 subscriber
 * /statistics [rosgraph_msgs/TopicStatistics] 1 subscriber

***********************************************

12,学习理解ROS消息:ROS Messages

ROS主题类型消息命令格式:
rostopic type [topic]

比如输入命令:

$ rostopic type /turtle1/cmd_vel

返回消息:geometry_msgs/Twist

我的具体信息如下:

*********************************************

uu@uu-HP-EliteBook-6930P-Notebook-PC:~$ rostopic type /turtle1/cmd_vel
geometry_msgs/Twist
uu@uu-HP-EliteBook-6930P-Notebook-PC:~$  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

uu@uu-HP-EliteBook-6930P-Notebook-PC:~$

*********************************************

现在紧接着我们进一步学习使用发布一个消息,控制机器人运动如下:

发布如下消息命令:

$ rostopic pub -1 /turtle1/cmd_vel geometry_msgs/Twist -- '[2.0, 0.0, 0.0]' '[0.0, 0.0, 1.8]'

此时发现机器人自己移动了一个圆弧路径。

13,再尝试发布一条消息让机器人一直转圈:

$ rostopic pub /turtle1/cmd_vel geometry_msgs/Twist -r 1 -- '[2.0, 0.0, 0.0]' '[0.0, 0.0, -1.8]'

14,再查看下rqt_graph,刷新后如图:

15,打开一个新终端查看机器人实时运动和对应坐标变化:

$ rostopic echo /turtle1/pose

16,学习使用rostopic hz命令查看信息报告和发布数据。

命令格式如下:
rostopic hz [topic]

比如查看pose:

$ rostopic hz /turtle1/pose

17,学习使用rqt_plot实时图形曲线:

先输入命令启动实时同步曲线运行窗口:

$ rosrun rqt_plot rqt_plot

窗口打开后,再路径栏里输入要查看曲线项目,然后点击后面加号添加进去,我这里分别添加了实时x,y曲线。

   当然也可以删掉几条曲线,另外单独添加(官方例子);我这里使用继续添加其他曲线。

猜你喜欢

转载自blog.csdn.net/uunubt/article/details/81807186