ROS学习总结(4)

编译ROS程序包

介绍ROS程序包的编译方法

针对CATKIN方式

目录

  • 1.编译程序包
  • 2.使用catkin_make
  • 3.开始编译你的程序包

编译程序包

  • 一旦安装了所需的系统依赖项,我们就可以开始编译刚才创建的程序包了。

  • 注意:如果您是通过apt或者其他附件管理工具来安装ROS的,那么系统已经替换安装好所有依赖项。

  • 记得先前来源您的环境配置(setup)文件,在Ubuntu中的操作指令如下:

    $ source /opt/ros/groovy/setup.bash

使用catkin_make

  • catkin_make是一个控制台工具,它简化了catkin的标准工作流程。
  • 您可以认为catkin_make是在CMake标准工作流程中依次调用了cmake和make。
  • 使用方法:
<span style="color:#333333"><code># 在catkin工作空间下
$ catkin_make [make_targets] [-DCMAKE_VARIABLES=...]
</code></span>
  • CMake标准工作流程主要可以分为以下几个步骤:
  • 注意:如果您运行以下命令是无效的,因为它只是一个演示CMake工作流程的例子。
<span style="color:#333333"><code># 在一个CMake项目里
$ mkdir build
$ cd build
$ cmake ..
$ make
$ make install  # (可选)
</code></span>
  • 每个CMake工程在编译时都会执行这个操作过程。
  • 相反,多个catkin项目可以放在工作空间中一起编译,工作流程如下:
<span style="color:#333333"><code># In a catkin workspace
$ catkin_make
$ catkin_make install  # (可选)
</code></span>
  • 上述命令会编译src文件夹下的所有catkin工程。想更深入了解请参考REP128。
  • 如果你的源代码不在默认工作空间中(〜/ catkin_ws / src)
  • 例如说存放在了my_src中,那么你可以这样来使用catkin_make:
  • 注意:运行以下命令时无效的,因为my_src不存在。
<span style="color:#333333"><code># In a catkin workspace
$ catkin_make --source my_src
$ catkin_make install --source my_src  # (optionally)
</code></span>
  • 对于catkin_make更高级的使用方法,请参考catkin / commands / catkin_make

开始编译你的程序包

  • 对于正要马上编译自己的代码的读者,请同时看一下后面的(C ++)/(Python)教程
  • 因为你可能需要修改CMakeLists.txt文件。
  • 按照之前的创建一个ROS程序包教程,你应该已经创建好了一个catkin工作空间和一个称为beginner_tutorials的catkin程序包。
  • 现在切换到catkin工作区并查看src文件夹:
<span style="color:#333333"><code>$ cd ~/catkin_ws/
$ ls src
</code></span>
  • 效果:
<span style="color:#333333"><code>beginner_tutorials/  CMakeLists.txt@  
</code></span>
  • 你可以看到一个称为beginner_tutorials的文件夹,这就是你在之前的catkin_create_pkg教程里创建的。
  • 现在我们可以使用catkin_make来编译它了:
<span style="color:#333333"><code>$ catkin_make
</code></span>
  • 你可以看到很多cmake和make输出的信息:
<span style="color:#333333"><code>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"
####
</code></span>
  • catkin_make首先输出它所使用到的每个空间所在的路径。
  • 更多关于空间的信息,请参考REP128和catkin / workspaces。
  • 需要注意的是由于这些空间存在重组配置的原因,有几个文件夹已经在catkin工作空间自动生成了,使用ls查看:
<span style="color:#333333"><code>$ ls 
</code></span>
  • 效果:
<span style="color:#333333"><code>build
devel
src
</code></span>
  • build目录是build space的所在位置,同时cmake和make也是在这里被调用来配置并编译你的程序包。
  • devel目录是devel space的替换所在位置,同时也是在你安装程序包之前放在放置文件和库文件的地方。
  • 现在我们已成功编译了一个ROS程序包,接下来我们将介绍ROS例程。
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章