4.建成一个ROS package

创建一个ROS package(rawmeat:wiki.ros.org/ROS/Tutorials/BuildingPackages)

描述:这个教程包含使用toolchain来构建一个package
教程等级:初学者
下一个教程理解ROS节点

(只介绍catkin)

内容:

  1. 建成package
    1. 使用catkin_make
    2. 建成你的package

1.建成packages

只要你安装了packages的所有系统依赖文件,我们可以构建你的新的package。

注意:如果你使用apt或者其他package管理器安装了ROS,你应该有了所有你的依赖文件

在继续之前,记得source你的环境setup文件,在Ubuntu下,将会是这样的:

# source /opt/ros/%YOUR_ROS_DISTRO%/setup.bash
$ source /opt/ros/kinetic/setup.bash           # For Kinetic for instance

1.1使用 catkin_make

catkin_make是命令行工具,在标准的catkin_make工作流中增加便利性。你可以想象catkin_make结合了在标准CMake 工作流中的对cmake和make的调用。

用法:

# In a catkin workspace
$ catkin_make [make_targets] [-DCMAKE_VARIABLES=…]

对于不熟悉标准CMake工作流的人,它分解如下:

注意:如果你运行下面的命令将不会工作,因为这只是CMake如何工作的一个实例。
# In a CMake project
$ mkdir build
$ cd build
$ cmake ..
$ make
$ make install    # (optionally)

这个过程对于每个CMake工程都会运行,相比之下catkin工程们可以在workspace中被建立。在一个工作从0建立catkin package遵循这个工作流:

# In a catkin workspace
$ catkin_make
$ catkin_make install    # (optionally)

以上的命令将会建立任何在src文件夹中找到的catkin工程。这遵循REP128提出的建议。如果你的源代码在不同的位置,比如说my_src,那么你将会这样召唤catkin_make:

注意:如果你运行以下的命令,将不会运行,因为目录my_src并不存在。
# In a catkin workspace
$ catkin_make –source my_src
$ catkin_make install –source my_src # (optionally)

对于更多关于catkin_make的先进用法,请看文件:catkin/commands/catkin_make

1.2建立你的package

如果你在使用这个页面建立你的代码,请注意接下来的教程(C++)/(Python),因为你可能会修改CMakeList.txt。

在先前的教程Creating a Package
你应该已经有一个catkin workspace和一个新的catkin package叫做beginner_tutorials。如果你不在,进入catkin workspace,并且查看src文件夹:

$ cd ~/catkin_ws/
$ ls src
  beginner_tutorials/   CMakeLists.txt@

你应该可以看见这儿有一个文件夹被称作beginner_tutorials,是你在先前教程通过catkin_create_pkg创建的。我们现在可以使用catkin_make建立那个package:

$ catkin_make

你应该可以看见许多从cmake和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/kinetic
– This workspace overlays: /opt/ros/kinetic
– 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”
####

注意到catkin_make首先展示了它为了每个“空间”所要使用的路径。这些路径在REP128中有描述以及wiki上和catkin workspaces有关的文件。重要的是注意因为默认值有一些文件夹已经在catkin_workspace中被创建了,用ls看一看:

$ ls
  build
  devel
  src

build文件夹是build space默认的位置,也是cmake和make被召唤配置并建立package的地方。devel文件夹是devel space默认的位置,在安装package之前可执行文件和库在那里。

现在你建立了你的ROSpackage,现在让我们讨论ROS nodes

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值