ROS速查(第3讲) 创建一个ROS软件包

3.1 Catkin 软件包的构成

(1) a package.xml –- to provides meta information about the package.

(2) a CMakeLists.txt --- the boilerplate

3.2 Catkin工作空间的构成

A trivial workspace might look like this:

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.3 创建一个Catkin工作空间(如果之前已经创建,此处可略过。)

(1) Source your ros environment before using catkin workspace

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

(2) make directory “~/catkin_ws/src”, change directory to it and execute  catkin_make command to make a catkin workspace.

$ mkdir -p ~/catkin_ws/src

$ cd ~/catkin_ws/

$ catkin_make

(3) Source your catkin environment

$ source devel/setup.bash

(4) To make sure your workspace is properly overlayed by the setup script, make sure ROS_PACKAGE_PATH environment variable includes the directory you're in.

$ echo $ROS_PACKAGE_PATH

/home/youruser/catkin_ws/src:/opt/ros/kinetic/share

3.4 创建一个Catkin软件包

(1) change to the source space directory of your catkin workspace

$ cd ~/catkin_ws/src

(2) use the catkin_create_pkg script to create a new package called 'beginner_tutorials' which depends on std_msgs, roscpp, and rospy:

catkin_create_pkg requires that you give it a package_name and optionally a list of dependencies on which that package depends:

# This is an example, do not try to run this

$ catkin_create_pkg <package_name> [depend1] [depend2] ...

Exemple:

$ catkin_create_pkg beginner_tutorials std_msgs rospy roscpp

This will create a beginner_tutorials folder which contains a package.xml and a CMakeLists.txt, which have been partially filled out with the information you gave catkin_create_pkg.

3.5 编译Catkin工作空间并Source setup.bash文件

Now you need to build the packages in the catkin workspace, and source the setup file to add the catkin workspace to your ROS environment.

$ cd ~/catkin_ws

$ catkin_make

$ source devel/setup.bash

3.6 ROS软件包的依赖(Package dependencies)

3.6.1 第一层依赖项(First-order dependencies)

(1) Use “rospack depends1” command to review the first-order dependencies of a package.

$ rospack depends1 beginner_tutorials

roscpp

rospy

std_msgs

(2) To see the package.xml file of a package

As you can see, rospack lists the dependencies that used in the package. These dependencies for a package are stored in the package.xml file:

$ roscd beginner_tutorials

$ cat package.xml

·<package format="2">

...

  <buildtool_depend>catkin</buildtool_depend>

  <build_depend>roscpp</build_depend>

  <build_depend>rospy</build_depend>

  <build_depend>std_msgs</build_depend>

...

</package>

3.6.2 依赖项的子依赖项(Indirect dependencies)

(1) use “roapack depends1” command to see the dependencies of a dependency

$ rospack depends1 rospy

genpy

roscpp

rosgraph

rosgraph_msgs

roslib

std_msgs

 

(2) Use “rospack depends” to review all the direct and subdirect dependencies of a package.

$ rospack depends beginner_tutorials

 

3.7 自定义你的软件包(Customize your package)

3.7.1 Customize the package.xml

3.7.1.1 description tag

The first sentence should be short and cover the scope of the package.

3.7.1.2 maintainer tags

(1) At least one maintainer is required.

(2) The name of the maintainer goes into the body of the tag, but there is also an email attribute that should be filled out:

<maintainer email="[email protected]">Your Name</maintainer>

3.7.1.3 License tags

(1) At least one license tag is required.

(2)Some common open source licenses are BSD, MIT, Boost Software License, GPLv2, GPLv3, LGPLv2.1, and LGPLv3. You can read about several of these at the Open Source Initiative.

For this tutorial we'll use the BSD license because the rest of the core ROS components use it already:

<license>License Name</license>

<license>BSD</license>

 

3.7.1.4 Dependencies Tags

The dependencies tags describe the dependencies of your package. The dependencies are split into build_depend, buildtool_depend, exec_depend, test_depend.

The uses of these dependency types are as follows:

Use buildtool_depend for build tool packages;

Use build_depend for packages you need at compile time;

Use exec_depend for packages you need at runtime;

Use test_depend for packages you need only for testing.

All of our listed dependencies have been added as a build_depend for us, in addition to the default buildtool_depend on catkin.

In this case we want all of our specified dependencies to be available at build and run time, so we'll add a exec_depend tag for each of them as well:

<buildtool_depend>catkin</buildtool_depend>

<build_depend>roscpp</build_depend>

<build_depend>rospy</build_depend>

<build_depend>std_msgs</build_depend>

<exec_depend>roscpp</exec_depend>

<exec_depend>rospy</exec_depend>

<exec_depend>std_msgs</exec_depend>

 

3.7.1.5 Final package.xml

As you can see the final package.xml, without comments and unused tags, is much more concise:

Toggle line numbers 

   1 <?xml version="1.0"?>

   <package format="2">

     <name>beginner_tutorials</name>

     <version>0.1.0</version>

     <description>The beginner_tutorials package</description>

   6 

     <maintainer email="[email protected]">Your Name</maintainer>

     <license>BSD</license>

     <url type="website">http://wiki.ros.org/beginner_tutorials</url>

  10   <author email="[email protected]">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   <exec_depend>roscpp</exec_depend>

  19   <exec_depend>rospy</exec_depend>

  20   <exec_depend>std_msgs</exec_depend>

  21 

  22 </package>

 

3.7.2 Customizing the CmakeLists.txt

Now that the package.xml, which contains meta information, has been tailored to your package, you are ready to move on in the tutorials. The CMakeLists.txt file created by catkin_create_pkg will be covered in the later tutorials about building ROS code.

猜你喜欢

转载自blog.csdn.net/Spacegene/article/details/84823734