在pcDuino上学习ROS系统初级开发(三)创建ROS软件包

雨后的彩虹桥 发布于 2014/03/09 15:04
阅读 1K+
收藏 0

groovygalapagos-320w

这一节教程主要包括使用roscreate-pkg 或者 catkin 来建立一个新的软件包, rospack 会列出所有的依赖。

1,构建一个catkin Package需要的文件

  • package.xm,提供一些软件包的信息
  • CMakeLists.txt 编译的规规则

一个简单软件包就像这样

  • my_package/
      CMakeLists.txt
      package.xml

2,Packages在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

在继续这个教程之前,你需要建立这个模板

3,建立一个catkin包

这里跟你演示一下怎么使用 catkin_create_pkg来创建一个新的 catkin 。

首先进入你创建的工作空间

# You should have created this in the Creating a Workspace Tutorial
$ cd ~/catkin_ws/src

现在使用catkin_create_pkg新的package名字叫做beginner_tutorials,它依赖于std_msgs,roscp和rospy:

$ catkin_create_pkg beginner_tutorials std_msgs rospy roscpp

这个会创建 beginner_tutorials包括package.xml和 CMakeLists.txt

catkin_create_pkg需要你给出软件的名字和依赖。

# This is an example, do not try to run this
# catkin_create_pkg <package_name> [depend1] [depend2] [depend3]

catkin_create_pkg还有很多高级的功能,你可以查看 catkin/commands/catkin_create_pkg.

4,package依赖

可以使用命令查看软件的依赖

$ 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>

有时候package还包含了直接依赖,例如rospy.

$ 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

5,定制package

这部分的教程会浏览刚才 catkin_create_pkg的每一个文件。

5.1定制package.xml

1,更新描述

?
1
   5 <description>The beginner_tutorialspackage</description>

2,更新维护者信息

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>

3,更新license

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>

4, 更新依赖

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>

我们也可以给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>

4,最终的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>

5.2定制CMakeLists.txt

具体的请看一节教程。


liksprite学习中心

加载中
返回顶部
顶部