本帖最后由 蒜泥小猫 于 2014-8-21 16:18 编辑
一个catkin程序包由什么组成?一个程序包要想称为catkin程序包必须符合以下要求: o 这个package.xml文件提供有关程序包的元信息。 · 每个目录下只能有一个程序包。 o 这意味着在同一个目录下不能有嵌套的或者多个程序包存在。 最简单的程序包也许看起来就像这样: - my_package/
- CMakeLists.txt
- package.xml
复制代码
在catkin工作空间中的程序包- workspace_folder/ -- WORKSPACE
- src/ -- SOURCE SPACE
- CMakeLists.txt -- 'Toplevel' CMake file, provided by catkin
- package_1/
- CMakeLists.txt -- CMakeLists.txt file for package_1
- package.xml -- Package manifest for package_1
- ...
- package_n/
- CMakeLists.txt -- CMakeLists.txt file for package_n
- package.xml -- Package manifest for package_n
复制代码
创建一个catkin程序包- You should have created this in the Creating a Workspace Tutorial
- $ cd ~/catkin_ws/src
复制代码
现在使用catkin_create_pkg命令来创建一个名为'beginner_tutorials'的新程序包,这个程序包依赖于std_msgs、roscpp和rospy:
- $ catkin_create_pkg beginner_tutorials std_msgs rospy roscpp
复制代码
Catkin_create_pkg命令会要求你输入package_name,如果有需要你还可以在后面添加一些需要依赖的其它程序包: - # This is an example, do not try to run this
- # catkin_create_pkg <package_name> [depend1] [depend2] [depend3]
复制代码
程序包依赖关系一级依赖(Jan 9, 2013) There is a bug reported and already fixed in rospack in groovy, which takes sometime until the change gets reflected on your computer. If you see a similar issue like this with the next command, you can skip to the next command. - $ rospack depends1 beginner_tutorials
- std_msgs
- rospy
- roscpp
复制代码
就像你看到的,rospack列出了在运行catkin_create_pkg命令时作为参数的依赖包,这些依赖包随后保存在package.xml文件中。 - $ roscd beginner_tutorials
- $ cat package.xml
复制代码- <package>
- ...
- <buildtool_depend>catkin</buildtool_depend>
- <build_depend>roscpp</build_depend>
- <build_depend>rospy</build_depend>
- <build_depend>std_msgs</build_depend>
- ...
- </package>
复制代码
间接依赖在很多情况中,一个依赖包还会有它自己的依赖包,比如,rospy还有其它依赖包。 (Jan 9, 2013) There is a bug reported and already fixed in rospack in groovy, which takes sometime until the change gets reflected on your computer. If you see a similar issue like this with the next command, you can skip to the next command. - $ rospack depends1 rospy
- genpy
- rosgraph
- rosgraph_msgs
- roslib
- std_msgs
复制代码
一个程序包还可以有好几个间接的依赖包,幸运的是使用rospack可以递归检测出所有的依赖包。 - $ rospack depends beginner_tutorials
- cpp_common
- rostime
- roscpp_traits
- roscpp_serialization
- genmsg
- genpy
- message_runtime
- rosconsole
- std_msgs
- rosgraph_msgs
- xmlrpcpp
- roscpp
- rosgraph
- catkin
- rospack
- roslib
- rospy
复制代码
自定义你的程序包自定义 package.xml描述标签首先更新描述标签: - <description>The beginner_tutorials package</description>
复制代码
将描述信息修改为任何你喜欢的内容,但是按照约定第一句话应该简短一些,因为它覆盖了程序包的范围。如果用一句话难以描述完全那就需要换行了。 维护者标签接下来是维护者标签: - 7 <!-- One maintainer tag required, multiple allowed, one person per tag -->
- 8 <!-- Example: -->
- 9 <!-- <maintainer email="jane.doe@example.com">Jane Doe</maintainer> -->
- 10 <maintainer email="user@todo.todo">user</maintainer>
复制代码
这是 package.xml中要求填写的一个重要标签,因为它能够让其他人联系到程序包的相关人员。至少需要填写一个维护者名称,但如果有需要的话你可以添加多个。除了在标签里面填写维护者的名称外,还应该在标签的 email属性中填写邮箱地址:
- 7 <maintainer email="you@yourdomain.tld">Your Name</maintainer>
复制代码
许可标签
再接下来是许可标签,同样的也需要: - 12 <!-- One license tag required, multiple allowed, one license per tag -->
- 13 <!-- Commonly used license strings: -->
- 14 <!-- BSD, MIT, Boost Software License, GPLv2, GPLv3, LGPLv2.1, LGPLv3 -->
- 15 <license>TODO</license>
复制代码
你应该选择一种许可协议并将它填写到这里。一些常见的开源许可协议有BSD、MIT、Boost Software License、GPLv2、GPLv3、LGPLv2.1和LGPLv3。你可以在 Open Source Initiative中阅读其中的若干个许可协议的相关信息。对于本教程我们将使用BSD协议,因为ROS核心组件的剩余部分已经使用了该协议: 依赖项标签接下来的标签用来描述程序包的各种依赖项,这些依赖项分为build_depend、buildtool_depend、run_depend、test_depend。关于这些标签的更详细介绍请参考 Catkin Dependencies相关的文档。在之前的操作中,因为我们将 std_msgs、 roscpp、 和 rospy作为 catkin_create_pkg命令的参数,所以生成的依赖项看起来如下: - 27 <!-- The *_depend tags are used to specify dependencies -->
- 28 <!-- Dependencies can be catkin packages or system dependencies -->
- 29 <!-- Examples: -->
- 30 <!-- Use build_depend for packages you need at compile time: -->
- 31 <!-- <build_depend>genmsg</build_depend> -->
- 32 <!-- Use buildtool_depend for build tool packages: -->
- 33 <!-- <buildtool_depend>catkin</buildtool_depend> -->
- 34 <!-- Use run_depend for packages you need at runtime: -->
- 35 <!-- <run_depend>python-yaml</run_depend> -->
- 36 <!-- Use test_depend for packages you need only for testing: -->
- 37 <!-- <test_depend>gtest</test_depend> -->
- 38 <buildtool_depend>catkin</buildtool_depend>
- 39 <build_depend>roscpp</build_depend>
- 40 <build_depend>rospy</build_depend>
- 41 <build_depend>std_msgs</build_depend>
复制代码
除了catkin中默认提供的buildtool_depend,所有我们列出的依赖包都已经被添加到build_depend标签中。在本例中,因为在编译和运行时我们需要用到所有指定的依赖包,因此还需要将每一个依赖包分别添加到run_depend标签中: - 12 <buildtool_depend>catkin</buildtool_depend>
- 13
- 14 <build_depend>roscpp</build_depend>
- 15 <build_depend>rospy</build_depend>
- 16 <build_depend>std_msgs</build_depend>
- 17
- 18 <run_depend>roscpp</run_depend>
- 19 <run_depend>rospy</run_depend>
- 20 <run_depend>std_msgs</run_depend>
复制代码
最后完成的 package.xml- 1 <?xml version="1.0"?>
- 2 <package>
- 3 <name>beginner_tutorials</name>
- 4 <version>0.1.0</version>
- 5 <description>The beginner_tutorials package</description>
- 6
- 7 <maintainer email="you@yourdomain.tld">Your Name</maintainer>
- 8 <license>BSD</license>
- 9 <url type="website">http://wiki.ros.org/beginner_tutorials</url>
- 10 <author email="you@yourdomain.tld">Jane Doe</author>
- 11
- 12 <buildtool_depend>catkin</buildtool_depend>
- 13
- 14 <build_depend>roscpp</build_depend>
- 15 <build_depend>rospy</build_depend>
- 16 <build_depend>std_msgs</build_depend>
- 17
- 18 <run_depend>roscpp</run_depend>
- 19 <run_depend>rospy</run_depend>
- 20 <run_depend>std_msgs</run_depend>
- 21
- 22 </package>
复制代码
自定义 CMakeLists.txt
|