赞
踩
编译ROS程序包(使用catkin_make)
- $ cd ~/catkin_ws/
- $ ls src
beginner_tutorials/ CMakeLists.txt@
$ catkin_make
- Base path: /home/user/catkin_ws
- Source space: /home/user/catkin_ws/src
- Build space: /home/user/catkin_ws/build
- Devel space: /home/user/catkin_ws/devel
- Install space: /home/user/catkin_ws/install
- ####
- #### Running command: "cmake /home/user/catkin_ws/src
- -DCATKIN_DEVEL_PREFIX=/home/user/catkin_ws/devel
- -DCMAKE_INSTALL_PREFIX=/home/user/catkin_ws/install" in "/home/user/catkin_ws/build"
- ####
- -- The C compiler identification is GNU 4.2.1
- -- The CXX compiler identification is Clang 4.0.0
- -- Checking whether C compiler has -isysroot
- -- Checking whether C compiler has -isysroot - yes
- -- Checking whether C compiler supports OSX deployment target flag
- -- Checking whether C compiler supports OSX deployment target flag - yes
- -- Check for working C compiler: /usr/bin/gcc
- -- Check for working C compiler: /usr/bin/gcc -- works
- -- Detecting C compiler ABI info
- -- Detecting C compiler ABI info - done
- -- Check for working CXX compiler: /usr/bin/c++
- -- Check for working CXX compiler: /usr/bin/c++ -- works
- -- Detecting CXX compiler ABI info
- -- Detecting CXX compiler ABI info - done
- -- Using CATKIN_DEVEL_PREFIX: /tmp/catkin_ws/devel
- -- Using CMAKE_PREFIX_PATH: /opt/ros/groovy
- -- This workspace overlays: /opt/ros/groovy
- -- Found PythonInterp: /usr/bin/python (found version "2.7.1")
- -- Found PY_em: /usr/lib/python2.7/dist-packages/em.pyc
- -- Found gtest: gtests will be built
- -- catkin 0.5.51
- -- BUILD_SHARED_LIBS is on
- -- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- -- ~~ traversing packages in topological order:
- -- ~~ - beginner_tutorials
- -- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- -- +++ add_subdirectory(beginner_tutorials)
- -- Configuring done
- -- Generating done
- -- Build files have been written to: /home/user/catkin_ws/build
- ####
- #### Running command: "make -j4" in "/home/user/catkin_ws/build"
- ####
$ ls
- build
- devel
- src
ROS入门教程-理解ROS节点
- sudo apt-get install ros-kinetic-ros-tutorials
-
roscore
$ roscore
- ... logging to ~/.ros/log/9cf88ce4-b14d-11df-8a75-00251148e8cf/roslaunch-
-
- machine_name-13039.log
- Checking log directory for disk usage. This may take awhile.
- Press Ctrl-C to interrupt
- Done checking log file disk usage. Usage is <1GB.
-
- started roslaunch server http://machine_name:33919/
- ros_comm version 1.4.7
-
- SUMMARY
- ========
-
- PARAMETERS
- * /rosversion
- * /rosdistro
- NODES
-
- auto-starting new master
- process[master]: started with pid [13054]
- ROS_MASTER_URI=http://machine_name:11311/
-
- setting /run_id to 9cf88ce4-b14d-11df-8a75-00251148e8cf
- process[rosout-1]: started with pid [13067]
- started core service [/rosout]
使用rosnode(获取节点信息的ROS工具)
$ rosnode list
/rosout
$ rosnode info /rosout
- ------------------------------------------------------------------------
- Node [/rosout]
- Publications:
- * /rosout_agg [rosgraph_msgs/Log]
- Subscriptions:
- * /rosout [unknown type]
- Services:
- * /rosout/set_logger_level
- * /rosout/get_loggers
- contacting node http://machine_name:54614/ ...
使用 rosrun(运行节点工具)
$ rosrun turtlesim turtlesim_node
在一个 新的终端:
$ rosnode list
- /rosout
- /turtlesim
$ rosrun turtlesim turtlesim_node __name:=my_turtle
$ rosnode list
- /rosout
- /my_turtle
使用另外一个rosnode指令,ping来测试:
$ rosnode ping my_turtle
- rosnode: node is [/my_turtle]
- pinging /my_turtle with a timeout of 3.0s
- xmlrpc reply from http://aqy:42235/ time=1.152992ms
- xmlrpc reply from http://aqy:42235/ time=1.120090ms
- xmlrpc reply from http://aqy:42235/ time=1.700878ms
- xmlrpc reply from http://aqy:42235/ time=1.127958ms
理解ROS话题
roscore
$ roscore
turtlesim
$ rosrun turtlesim turtlesim_node
通过键盘远程控制turtle
$ rosrun turtlesim turtle_teleop_key
- [ INFO] 1254264546.878445000: Started node [/teleop_turtle], pid [5528], bound on [aqy], xmlrpc port [43918], tcpros port [55936], logging to [~/ros/ros/log/teleop_turtle_5528.log], using [real] time
- Reading from keyboard
- ---------------------------
- Use arrow keys to move the turtle.
ROS Topics
使用 rqt_graph
- $ sudo apt-get install ros-kinetic-rqt
- $ sudo apt-get install ros-kinetic-rqt-common-plugins
$ rosrun rqt_graph rqt_graph
rostopic介绍
$ rostopic -h
- 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
使用 rostopic echo
$ rostopic echo /turtle1/cmd_vel
你可能看不到任何东西因为现在还没有数据发布到该话题上。
接下来我们通过按下方向键使turtle_teleop_key节点发布数据。
记住如果turtle没有动起来的话就需要你重新选中turtle_teleop_key节点运行时所在的终端窗口。
现在当你按下向上方向键时应该会看到下面的信息:
- linear:
- x: 2.0
- y: 0.0
- z: 0.0
- angular:
- x: 0.0
- y: 0.0
- z: 0.0
- ---
- linear:
- x: 2.0
- y: 0.0
- z: 0.0
- angular:
- x: 0.0
- y: 0.0
- z: 0.0
- ---
现在让我们再看一下rqt_graph(你可能需要刷新一下ROS graph)。
正如你所看到的rostopic echo(红色显示部分)现在也订阅了turtle1/command_velocity话题。
使用 rostopic list
$ rostopic list -v
Published topics:
Subscribed topics:
ROS Messages
$ rostopic type /turtle1/cmd_vel
geometry_msgs/Twist
我们可以使用rosmsg命令来查看消息的详细情况
$ 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
rostopic type /turtle1/cmd_vel | rosmsg show //其实命令还可以这样用
使用 rostopic pub
$ rostopic pub -1 /turtle1/cmd_vel geometry_msgs/Twist -- '[2.0, 0.0, 0.0]' '[0.0, 0.0, 1.8]'
你可能已经注意到turtle已经停止移动了。这是因为turtle需要一个稳定的频率为1Hz的命令流来保持移动状态。
$ rostopic pub /turtle1/cmd_vel geometry_msgs/Twist -r 1 -- '[2.0, 0.0, 0.0]' '[0.0, 0.0, 1.8]'
使用 rostopic hz
$ rostopic hz /turtle1/pose
- subscribed to [/turtle1/pose]
- average rate: 59.354
- min: 0.005s max: 0.027s std dev: 0.00284s window: 58
- average rate: 59.459
- min: 0.005s max: 0.027s std dev: 0.00271s window: 118
- average rate: 59.539
- min: 0.004s max: 0.030s std dev: 0.00339s window: 177
- average rate: 59.492
- min: 0.004s max: 0.030s std dev: 0.00380s window: 237
- average rate: 59.463
- min: 0.004s max: 0.030s std dev: 0.00380s window: 290
rostopic type /turtle1/cmd_vel | rosmsg show
使用 rqt_plot
rqt_plot命令可以实时显示一个发布到某个话题上的数据变化图形。
这里我们将使用rqt_plot命令来绘制正在发布到/turtle1/pose话题上的数据变化图形。
首先,在一个新终端中运行rqt_plot命令:
$ rosrun rqt_plot rqt_plot
本部分教程到此为止,请使用Ctrl-C退出rostopic命令,但要保持turtlesim继续运行。
理解ROS服务和参数
ROS Services
使用rosservice
- rosservice list 输出可用服务的信息
- rosservice call 调用带参数的服务
- rosservice type 输出服务类型
- rosservice find 依据类型寻找服务find services by service type
- rosservice uri 输出服务的ROSRPC uri
rosservice list
$ rosservice list
- /clear
- /kill
- /reset
- /rosout/get_loggers
- /rosout/set_logger_level
- /spawn
- /teleop_turtle/get_loggers
- /teleop_turtle/set_logger_level
- /turtle1/set_pen
- /turtle1/teleport_absolute
- /turtle1/teleport_relative
- /turtlesim/get_loggers
- /turtlesim/set_logger_level
- 重置(reset)
- 清除(clear)
- 再生(spawn)
- 终止(kill)
- turtle1/set_pen
- /turtle1/teleport_absolute
- /turtle1/teleport_relative
- turtlesim/get_loggers
- turtlesim/set_logger_level
- /rosout/get_loggers
- /rosout/set_logger_level
rosservice type 命令更进一步查看clear服务:使用方法:rosservice type [service]
$ rosservice type clear
std_srvs/Empty
rosservice call 调用带参数的服务 使用方法: rosservice call [service] [args]
$ rosservice call clear
$ rosservice type spawn | rossrv show
- float32 x
- float32 y
- float32 theta
- string name // 上部分是发请求的参数
- ---
- string name // 下部分是响应返回的值
$ rosservice call spawn 2 2 0.2 ""
name: turtle2
现在我们的乌龟看起来应该是像这样的:
Using rosparam
1是整型
1.0是浮点型
one是字符串
true是布尔
[1,2,3]是整型列表
{a:b,c:d}是字典
- rosparam set 设置参数
- rosparam get 获取参数
- rosparam load 从文件读取参数
- rosparam dump 向文件中写入参数
- rosparam delete 删除参数
- rosparam list 列出参数名
rosparam list 查看现在参数服务器上都有哪些参数:
$ rosparam list
- /background_b
- /background_g
- /background_r
- /roslaunch/uris/aqy:51932
- /run_id
rosparam set,rosparam get
$ rosparam set background_r 150
$ rosservice call clear
- $ rosparam get background_g
- 86
$ rosparam get /
- background_b: 255
- background_g: 86
- background_r: 150
- roslaunch:
- uris: {'aqy:51932': 'http://aqy:51932/'}
- run_id: e07ea71e-98df-11de-8875-001b21201aa8
$ rosparam dump params.yaml
- $ rosparam load params.yaml copy
- $ rosparam get copy/background_b
255
rqt_console 和 roslaunch
预先安装rqt和turtlesim程序包
$ sudo apt-get install ros-kinetic-rqt ros-kinetic-rqt-common-plugins ros-kinetic-turtlesim
使用rqt_console和rqt_logger_level
- $ rosrun rqt_console rqt_console
- $ rosrun rqt_logger_level rqt_logger_level
你会看到弹出两个窗口:
$ rosrun turtlesim turtlesim_node
· 因为默认日志等级是INFO,所以你会看到turtlesim启动后输出的所有信息,如下图所示:
现在让我们刷新一下rqt_logger_level窗口并选择/turtlesim将日志等级修改为WARN,如下图所示:
现在我们让turtle动起来并观察rqt_console中的输出:
rostopic pub /turtle1/cmd_vel geometry_msgs/Twist -r 1 -- '[2.0, 0.0, 0.0]' '[0.0, 0.0, 0.0]'
效果
日志等级说明
- Fatal
- Error
- Warn
- Info
- Debug
Fatal是最高优先级,Debug是最低优先级。
通过设置日志等级你可以获取该等级及其以上优先等级的所有日志消息。
比如,将日志等级设为Warn时,你会得到Warn、Error和Fatal这三个等级的所有日志消息。
现在让我们按Ctrl-C退出turtlesim节点
使用roslaunch
接下来我们将使用roslaunch来启动多个turtlesim节点和一个模仿节点以让一个turtlesim节点来模仿另一个turtlesim节点。
$ roscd beginner_tutorials
- $ export ROS_PACKAGE_PATH=~/catkin_ws/src:$ROS_PACKAGE_PATH
- $ roscd beginner_tutorials
- $ mkdir launch
- $ cd launch
Launch 文件
新建文件,输入:
gedit turtlemimic.launch
复制的文件内容:
- 1 <launch>
- 2
- 3 <group ns="turtlesim1">
- 4 <node pkg="turtlesim" name="sim" type="turtlesim_node"/>
- 5 </group>
- 6
- 7 <group ns="turtlesim2">
- 8 <node pkg="turtlesim" name="sim" type="turtlesim_node"/>
- 9 </group>
- 10
- 11 <node pkg="turtlesim" name="mimic" type="mimic">
- 12 <remap from="input" to="turtlesim1/turtle1"/>
- 13 <remap from="output" to="turtlesim2/turtle1"/>
- 14 </node>
- 15
- 16 </launch>
Launch 文件解析
<launch>
- 3 <group ns="turtlesim1">
- 4 <node pkg="turtlesim" name="sim" type="turtlesim_node"/>
- 5 </group>
- 6
- 7 <group ns="turtlesim2">
- 8 <node pkg="turtlesim" name="sim" type="turtlesim_node"/>
- 9 </group>
- 11 <node pkg="turtlesim" name="mimic" type="mimic">
- 12 <remap from="input" to="turtlesim1/turtle1"/>
- 13 <remap from="output" to="turtlesim2/turtle1"/>
- 14 </node>
roslaunching
$ roslaunch beginner_tutorials turtlemimic.launch
$ rostopic pub /turtlesim1/turtle1/cmd_vel geometry_msgs/Twist -r 1 -- '[2.0, 0.0, 0.0]' '[0.0, 0.0, -1.8]
$ rqt_graph
ROS入门教程-使用rosed编辑ROS中的文件
使用 rosed
$ rosed roscpp Logger.msg
使用Tab键补全文件名
$ rosed [package_name] <tab>
编辑器
export EDITOR='emacs -nw'
$ echo $EDITOR
emacs -nw
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。