Note: This tutorial assumes that you have completed the previous tutorials: creating a ROS package. |
Please ask about problems and questions regarding this tutorial on answers.ros.org. Don't forget to include in your question the link to this page, the versions of your OS & ROS, and also add appropriate tags. |
Building a ROS Package
Description: This tutorial covers using rosmake to build a package, and rosdep to install system dependencies.Tutorial Level: BEGINNER
Next Tutorial: Understanding ROS Nodes
Contents
系统依赖文件
ROS packages 有时会需要使用一些由操作系统提供的库文件和命令工具。这些被引用的库文件和命令工具就是系统依赖文件。很多情况下这些系统依赖文件缺省状态没有安装。ROS提供一个简单工具rosdep, 用于下载和安装这些系统依赖文件。
ROS packages 必须在package manifest文件中声明需要使用哪些系统依赖文件。我们来看下turtlesim package中的manifest文件:
$ roscd turtlesim $ cat manifest.xml
<package> ... ... <rosdep name="wxwidgets"/> </package>
可以看到 turtlesim 使用了 wxwidgets.
rosdep
rosdep 是ROS packages 安装系统依赖文件的工具。
用法:
rosdep install [package]
下载和安装turtlesim的系统依赖文件:
$ rosdep install turtlesim
如果安装成功则会看到如下结果:
All required rosdeps installed successfully
否则会看到控制台不同的输出结果。
set -o errexit set -o verbose if [ ! -f /opt/ros/lib/libboost_date_time-gcc42-mt*-1_37.a ] ; then mkdir -p ~/ros/ros-deps cd ~/ros/ros-deps wget --tries=10 http://pr.willowgarage.com/downloads/boost_1_37_0.tar.gz tar xzf boost_1_37_0.tar.gz cd boost_1_37_0 ./configure --prefix=/opt/ros make sudo make install fi if [ ! -f /opt/ros/lib/liblog4cxx.so.10 ] ; then mkdir -p ~/ros/ros-deps cd ~/ros/ros-deps wget --tries=10 http://pr.willowgarage.com/downloads/apache-log4cxx-0.10.0-wg_patched.tar.gz tar xzf apache-log4cxx-0.10.0-wg_patched.tar.gz cd apache-log4cxx-0.10.0 ./configure --prefix=/opt/ros make sudo make install fi if [ ! -f /opt/ros/lib/libboost_date_time-gcc42-mt*-1_37.a ] ; then mkdir -p ~/ros/ros-deps cd ~/ros/ros-deps wget --tries=10 http://pr.willowgarage.com/downloads/boost_1_37_0.tar.gz tar xzf boost_1_37_0.tar.gz cd boost_1_37_0 ./configure --prefix=/opt/ros make sudo make install fi if [ ! -f /opt/ros/lib/liblog4cxx.so.10 ] ; then mkdir -p ~/ros/ros-deps cd ~/ros/ros-deps wget --tries=10 http://pr.willowgarage.com/downloads/apache-log4cxx-0.10.0-wg_patched.tar.gz tar xzf apache-log4cxx-0.10.0-wg_patched.tar.gz cd apache-log4cxx-0.10.0 ./configure --prefix=/opt/ros make sudo make install fi
rosdep 运行上面这段bash脚本直到结束退出.
编译 Packages
当所有系统依赖文件安装完后,我们就可以编译刚刚创建的package了.
使用 rosmake
rosmake 类似 make 命令, 但是针对ROS做了扩展. 当输入命令 rosmake beginner_tutorials时, 会编译 beginner_tutorials package, 同时按顺序编译它所依赖的每个package。 因为我们创建package时使用了rospy, roscpp, 和 std_msgs 这些packages及它们依赖的package也都会被rosmake编译.
用法:
rosmake [package]
举例:
$ rosmake beginner_tutorials
命令执行会持续一会. 运行时得到输出如下结果:
[ rosmake ] No package specified. Building ['beginner_tutorials'] [ rosmake ] Logging to directory [ rosmake ] /home/dbking/.ros/rosmake_output-2009-09-22-03-17-14 [ rosmake ] [ 0 of 18 Completed ] [rosmake-0] >>> genmsg_cpp >>> [ make ] [rosmake-0] <<< genmsg_cpp <<< [PASS] [ 0.39 seconds ] [ rosmake ] [ 1 of 18 Completed ] [rosmake-0] >>> roslib >>> [ make ] ... ... ... [ rosmake ] [ 17 of 18 Completed ] [rosmake-0] >>> beginner_tutorials >>> [ make ] [rosmake-0] <<< beginner_tutorials <<< [PASS] [ 0.79 seconds ]
编译多个 packages
可以使用 rosmake 命令编译同时多个 packages .
用法:
rosmake [package1] [package2] [package3]
现在我们试着编译一些后面教程会用到的package:
$ rosdep install rxtools $ rosmake roscpp_tutorials rospy_tutorials rxtools
review
Lets just list some of the commands we've used so far:
- rosdep = ros+dep(endencies) : a tool to install package dependencies
- rosmake = ros+make : makes (compiles) a ROS package
Now that you have built your ROS package let's more talk about ROS Nodes.