LOU3237570262 L1 2020-05-16 12:08:15 理解ROS话题
346 0

“ROS 机器人操作系统初级教程”实验报告

理解ROS话题

1 开始

1.1 roscore

首先确保roscore已经运行, 打开一个新的终端:

$ roscore

1.2 turtlesim

在一个新的终端中运行:

$ rosrun turtlesim turtlesim_node

1.3 通过键盘远程控制turtle

在一个新的终端中运行:

$ rosrun turtlesim turtle_teleop_key image.png 使用键盘上的方向键来控制turtle运动 image.png 2 ROS Topics

2.1 使用 rqt_graph

$ sudo apt-get install ros-indigo-rqt

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

在一个新终端中运行:

$ rosrun rqt_graph rqt_graph image.png 2.2 rostopic介绍

可以使用帮助选项查看rostopic的子命令:

$ rostopic -h image.png 2.3 使用 rostopic echo

在一个新终端中看一下turtle_teleop_key节点在/turtle1/command_velocity话题(非hydro版)上发布的数据

$ rostopic echo /turtle1/cmd_vel image.png 现在再看一下rqt_graph(可能需要刷新一下ROS graph)rostopic echo(红色显示部分)现在也订阅了turtle1/cmd_vel话题。 image.png 2.4 使用 rostopic list

查看一下list子命令需要的参数,在一个新终端中运行:

$ rostopic list -h image.png 在rostopic list中使用verbose选项:

$ rostopic list -v image.png 3 ROS Messages

3.1 使用 rostopic type

$ rostopic type /turtle1/cmd_vel image.png $ rosmsg show geometry_msgs/Twist image.png 4 继续学习 rostopic

4.1 使用 rostopic pub

$ rostopic pub -1 /turtle1/cmd_vel geometry_msgs/Twist -- '[2.0, 0.0, 0.0]' '[0.0, 0.0, 1.8]' image.png turtle需要一个稳定的频率为1Hz的命令流来保持移动状态 image.png 可以看一下rqt_graph中的情形,可以看到rostopic发布器节点(红色)正在与rostopic echo节点(绿色)进行通信: image.png 在一个新终端中通过rostopic echo命令来查看turtlesim所发布的数据 image.png 4.2 使用 rostopic hz

$ rostopic hz /turtle1/pose image.png $ rostopic type /turtle1/cmd_vel | rosmsg show

5 使用 rqt_plot

在一个新终端中运行rqt_plot命令:

$ rosrun rqt_plot rqt_plot

这会弹出一个新窗口,在窗口左上角的一个文本框里面可以添加需要绘制的话题。在里面输入/turtle1/pose/x后之前处于禁用状态的加号按钮将会被使能变亮。按一下该按钮,并对/turtle1/pose/y重复相同的过程。会在图形中看到turtle的x-y位置坐标图。 image.png 按下减号按钮会显示一组菜单让你隐藏图形中指定的话题。现在隐藏掉你刚才添加的话题并添加/turtle1/pose/theta,你会看到如下图所示的图形: image.png image.png

最新评论
暂无评论~