1 开始
1.1 roscore
首先确保roscore已经运行, 打开一个新的终端:
$ roscore
1.2 turtlesim
在一个新的终端中运行:
$ rosrun turtlesim turtlesim_node
1.3 通过键盘远程控制turtle
在一个新的终端中运行:
$ rosrun turtlesim turtle_teleop_key
使用键盘上的方向键来控制turtle运动
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
2.2 rostopic介绍
可以使用帮助选项查看rostopic的子命令:
$ rostopic -h
2.3 使用 rostopic echo
在一个新终端中看一下turtle_teleop_key节点在/turtle1/command_velocity话题(非hydro版)上发布的数据
$ rostopic echo /turtle1/cmd_vel
现在再看一下rqt_graph(可能需要刷新一下ROS graph)rostopic echo(红色显示部分)现在也订阅了turtle1/cmd_vel话题。
2.4 使用 rostopic list
查看一下list子命令需要的参数,在一个新终端中运行:
$ rostopic list -h
在rostopic list中使用verbose选项:
$ rostopic list -v
3 ROS Messages
3.1 使用 rostopic type
$ rostopic type /turtle1/cmd_vel
$ rosmsg show geometry_msgs/Twist
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]'
turtle需要一个稳定的频率为1Hz的命令流来保持移动状态
可以看一下rqt_graph中的情形,可以看到rostopic发布器节点(红色)正在与rostopic echo节点(绿色)进行通信:
在一个新终端中通过rostopic echo命令来查看turtlesim所发布的数据
4.2 使用 rostopic hz
$ rostopic hz /turtle1/pose
$ 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位置坐标图。
按下减号按钮会显示一组菜单让你隐藏图形中指定的话题。现在隐藏掉你刚才添加的话题并添加/turtle1/pose/theta,你会看到如下图所示的图形:
学习时间 7分钟
操作时间 0分钟
按键次数 0次
实验次数 2次
报告字数 3183字
是否完成 完成