創建ROS的Package(功能包)
本文講如何用catkin創建一個ROS的package
1. catkin package的組成:一定要包含CMakeLists.txt及package.xml文件
my_package/ CMakeLists.txt package.xml
此外,每個package必須要有他自己的文件夾。
2. 推薦使用catkin workspace來處理catkin package
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 package
使用catkin_create_pkg腳本來創建新的catkin package:
(1)切換source space目錄至之前創建的catkin workspace
$ cd ~/catkin_ws/src
(2)用catkin_create_pkg創建一個catkin package,名字是beginner_tutorials,且依賴於已有的功能包std_msgs,roscpp,rospy,後者稱為dependency
$ catkin_create_pkg beginner_tutorials std_msgs rospy roscpp
4. build 這個catkin workspace, source 這個setup文件
build方法:
$ cd ~/catkin_ws $ catkin_make
source方法:
$ . ~/catkin_ws/devel/setup.bash
5. package dependencies
(1)用rospack查看1階dependencies:
$ rospack depends1 beginner_tutorials
package.xml中儲存了package的dependencies信息
$ roscd beginner_tutorials $ cat package.xml
(2)用rospack查看間接(高階)的dependencies:
$ rospack depends beginner_tutorials
6. customize(自定義、定制) package
6.1 自定義package.xml
(1) 描述標簽(description tag):盡可能短
5 <description>The beginner_tutorials package</description>
(2)Maintainer 標簽:必須有,而且非常重要,至少要有一條。作用是讓別人知道有關這個package該聯系誰。
Toggle line numbers 7 <!-- One maintainer tag required, multiple allowed, one person per tag --> 8 <!-- Example: --> 9 <!-- <maintainer email="[email protected]">Jane Doe</maintainer> --> 10 <maintainer email="[email protected]">user</maintainer>
(3)許可證標簽(license tag):有很多開源許可證,我們這裏使用BSD,因為許多ROS核心部件都是用的它。
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)dependencies標簽: dependencies標簽可分為build_depend, buildtool_depend, exec_depend, test_depend。因為我們使用了std_msgs, roscpp, and rospy,所以該標簽應為:
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 exec_depend for packages you need at runtime: --> 35 <!-- <exec_depend>python-yaml</exec_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>
我們希望在build和run的時候使用所有特定的dependencies,因此我們還要增加exec_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 <exec_depend>roscpp</exec_depend> 19 <exec_depend>rospy</exec_depend> 20 <exec_depend>std_msgs</exec_depend>
(5) 最終的package.xml:下面是不含有評論和未使用tag的package.xml文件,非常concise(簡明)
<?xml version="1.0"?> <package format="2"> <name>beginner_tutorials</name> <version>0.1.0</version> <description>The beginner_tutorials package</description> <maintainer email="[email protected]">Your Name</maintainer> <license>BSD</license> <url type="website">http://wiki.ros.org/beginner_tutorials</url> <author email="[email protected]">Jane Doe</author> <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> </package>
6.2 自定義CMakeLists.txt
創建ROS的Package(功能包)