文章目录
1. 功能包package
1)package.xml
format 2:
根标签
```xml
<package format="2">
</package>
```
- 必须标签
-
<name>
:包名 -
<version>
:软件包的版本号(必须为3个点分割的证书) -
<description>
:包内容的描述 -
<maintainer>
:负责维护包的开发人员信息 -
<license>
:发布代码的软件许可证 (e.g. GPL, BSD, ASL)
<package format="2"> <name>foo_core</name> <version>1.2.4</version> <description> This package provides foo capability. </description> <maintainer email="ivana@osrf.org">Ivana Bildbotz</maintainer> <license>BSD</license> </package>
-
依赖关系
6种依赖关系使用以下集中标签指定:
<depend>
:指定依赖关系为构建、导出和执行依赖关系,最常用,只需要提及每个ROS包依赖项就行了,比较简单。对于博主这种懒人,就适合使用它!!!<build_depend>
:指定构建此功能包所需要的包,仅使用某些特定的依赖关系来构建程序包,而不是在执行时使用,可编译来自依赖包的头文件(尤其CMake中使用find_package()
时)<build_export_depend>
:指定针对该包构建所需要的功能包(尤其CMake中catkin_package()
声明为(CATKIN_)DEPENDS
时)<exec_depend>
:声明运行程序包时所需的共享库、可执行文件、Python模块、启动脚本和其他文件的依赖关系,指定运行该功能包中代码所需要的功能包(尤其CMake中catkin_package()
声明为(CATKIN_)DEPENDS
时)<test_depend>
:指定单元测试的其他依赖项,他们不应该复制已经提到的任何以来<buildtool_depend>
:指定软件包自行构建所需要的构建系统工具,一般是catkin
,这也是必须的标签<doc_depend>
:指定生成文档所需要的文档工具
<package format="2">
<name>foo_core</name>
<version>1.2.4</version>
<description>
This package provides foo capability.
</description>
<maintainer email="ivana@willowgarage.com">Ivana Bildbotz</maintainer>
<license>BSD</license>
<url>http://ros.org/wiki/foo_core</url>
<author>Ivana Bildbotz</author>
<buildtool_depend>catkin</buildtool_depend>
<depend>roscpp</depend>
<depend>std_msgs</depend>
<build_depend>message_generation</build_depend>
<exec_depend>message_runtime</exec_depend>
<exec_depend>rospy</exec_depend>
<test_depend>python-mock</test_depend>
<doc_depend>doxygen</doc_depend>
</package>
format 1(老版本):
如果<package>
标签没有format属性,那么就是format1的包
根标签
<package>
</package>
必需标签:与上相同
<package>
<name>foo_core</name>
<version>1.2.4</version>
<description>
This package provides foo capability.
</description>
<maintainer email="ivana@willowgarage.com">Ivana Bildbotz</maintainer>
<license>BSD</license>
</package>
依赖关系
-
<buildtool_depend>
:指定构建工具,一般为catkin -
<build_depend>
:指定需要的依赖包 -
<run_depend>
:指定运行代码时需要的依赖包 -
<test_depend>
:与format2中相同,不能是已经提到的,必须是仅用于测试的
<package>
<name>foo_core</name>
<version>1.2.4</version>
<description>
This package provides foo capability.
</description>
<maintainer email="ivana@willowgarage.com">Ivana Bildbotz</maintainer>
<license>BSD</license>
<url>http://ros.org/wiki/foo_core</url>
<author>Ivana Bildbotz</author>
<buildtool_depend>catkin</buildtool_depend>
<build_depend>message_generation</build_depend>
<build_depend>roscpp</build_depend>
<build_depend>std_msgs</build_depend>
<run_depend>message_runtime</run_depend>
<run_depend>roscpp</run_depend>
<run_depend>rospy</run_depend>
<run_depend>std_msgs</run_depend>
<test_depend>python-mock</test_depend>
</package>
2)CMakeLists.txt
CMake不知道package.xml依赖关系,尽管catkin 知道。为了编译代码,CMakeLists.txt必须显式声明如何解析所有标头和库引用。
查找库
find_package(catkin REQUIRED COMPONENTS roscpp)
#对于catkin的多个依赖项的情况
find_package(catkin REQUIRED COMPONENTS angles roscpp std_msgs)
注意:必须确保 package.xml 中已经<depend>
或者<build_depend>
了所需要的依赖包
包含头文件目录
编译之前,需要先收集头文件目录
include_directories(include ${catkin_INCLUDE_DIRS})
include仅当软件包的子目录包含用于编译程序的头文件时,才需要该参数。
导出接口
必须声明导出到其他ROS包的所有接口所需要的库和头文件包
catkin_package(CATKIN_DEPENDS angles roscpp std_msgs)
注意:必须确保 package.xml 中已经<depend>
或者<build_depend>
了所需要的依赖包
catkin_package()仅被调用一次,需要根据具体情况添加其他参数。
cmake_minimum_required(VERSION 2.8.3)
project(lwr_description)
## Compile as C++11, supported in ROS Kinetic and newer
# add_compile_options(-std=c++11)
## Find catkin macros and libraries
## if COMPONENTS list like find_package(catkin REQUIRED COMPONENTS xyz)
## is used, also find other catkin packages
find_package(catkin REQUIRED)
## System dependencies are found with CMake's conventions
# find_package(Boost REQUIRED COMPONENTS system)
## Uncomment this if the package has a setup.py. This macro ensures
## modules and global scripts declared therein get installed
## See http://ros.org/doc/api/catkin/html/user_guide/setup_dot_py.html
# catkin_python_setup()
################################################
## Declare ROS messages, services and actions ##
################################################
## To declare and build messages, services or actions from within this
## package, follow these steps:
## * Let MSG_DEP_SET be the set of packages whose message types you use in
## your messages/services/actions (e.g. std_msgs, actionlib_msgs, ...).
## * In the file package.xml:
## * add a build_depend tag for "message_generation"
## * add a build_depend and a exec_depend tag for each package in MSG_DEP_SET
## * If MSG_DEP_SET isn't empty the following dependency has been pulled in
## but can be declared for certainty nonetheless:
## * add a exec_depend tag for "message_runtime"
## * In this file (CMakeLists.txt):
## * add "message_generation" and every package in MSG_DEP_SET to
## find_package(catkin REQUIRED COMPONENTS ...)
## * add "message_runtime" and every package in MSG_DEP_SET to
## catkin_package(CATKIN_DEPENDS ...)
## * uncomment the add_*_files sections below as needed
## and list every .msg/.srv/.action file to be processed
## * uncomment the generate_messages entry below
## * add every package in MSG_DEP_SET to generate_messages(DEPENDENCIES ...)
## Generate messages in the 'msg' folder
# add_message_files(
# FILES
# Message1.msg
# Message2.msg
# )
## Generate services in the 'srv' folder
# add_service_files(
# FILES
# Service1.srv
# Service2.srv
# )
## Generate actions in the 'action' folder
# add_action_files(
# FILES
# Action1.action
# Action2.action
# )
## Generate added messages and services with any dependencies listed here
# generate_messages(
# DEPENDENCIES
# std_msgs # Or other packages containing msgs
# )
################################################
## Declare ROS dynamic reconfigure parameters ##
################################################
## To declare and build dynamic reconfigure parameters within this
## package, follow these steps:
## * In the file package.xml:
## * add a build_depend and a exec_depend tag for "dynamic_reconfigure"
## * In this file (CMakeLists.txt):
## * add "dynamic_reconfigure" to
## find_package(catkin REQUIRED COMPONENTS ...)
## * uncomment the "generate_dynamic_reconfigure_options" section below
## and list every .cfg file to be processed
## Generate dynamic reconfigure parameters in the 'cfg' folder
# generate_dynamic_reconfigure_options(
# cfg/DynReconf1.cfg
# cfg/DynReconf2.cfg
# )
###################################
## catkin specific configuration ##
###################################
## The catkin_package macro generates cmake config files for your package
## Declare things to be passed to dependent projects
## INCLUDE_DIRS: uncomment this if your package contains header files
## LIBRARIES: libraries you create in this project that dependent projects also need
## CATKIN_DEPENDS: catkin_packages dependent projects also need
## DEPENDS: system dependencies of this project that dependent projects also need
catkin_package(
# INCLUDE_DIRS include
# LIBRARIES lwr_description
# CATKIN_DEPENDS other_catkin_pkg
# DEPENDS system_lib
)
###########
## Build ##
###########
## Specify additional locations of header files
## Your package locations should be listed before other locations
include_directories(
# include
# ${catkin_INCLUDE_DIRS}
)
## Declare a C++ library
# add_library(${PROJECT_NAME}
# src/${PROJECT_NAME}/lwr_description.cpp
# )
## Add cmake target dependencies of the library
## as an example, code may need to be generated before libraries
## either from message generation or dynamic reconfigure
# add_dependencies(${PROJECT_NAME} ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS})
## Declare a C++ executable
## With catkin_make all packages are built within a single CMake context
## The recommended prefix ensures that target names across packages don't collide
# add_executable(${PROJECT_NAME}_node src/lwr_description_node.cpp)
## Rename C++ executable without prefix
## The above recommended prefix causes long target names, the following renames the
## target back to the shorter version for ease of user use
## e.g. "rosrun someones_pkg node" instead of "rosrun someones_pkg someones_pkg_node"
# set_target_properties(${PROJECT_NAME}_node PROPERTIES OUTPUT_NAME node PREFIX "")
## Add cmake target dependencies of the executable
## same as for the library above
# add_dependencies(${PROJECT_NAME}_node ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS})
## Specify libraries to link a library or executable target against
# target_link_libraries(${PROJECT_NAME}_node
# ${catkin_LIBRARIES}
# )
#############
## Install ##
#############
# all install targets should use catkin DESTINATION variables
# See http://ros.org/doc/api/catkin/html/adv_user_guide/variables.html
## Mark executable scripts (Python etc.) for installation
## in contrast to setup.py, you can choose the destination
# install(PROGRAMS
# scripts/my_python_script
# DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
# )
## Mark executables for installation
## See http://docs.ros.org/melodic/api/catkin/html/howto/format1/building_executables.html
# install(TARGETS ${PROJECT_NAME}_node
# RUNTIME DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
# )
## Mark libraries for installation
## See http://docs.ros.org/melodic/api/catkin/html/howto/format1/building_libraries.html
# install(TARGETS ${PROJECT_NAME}
# ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
# LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
# RUNTIME DESTINATION ${CATKIN_GLOBAL_BIN_DESTINATION}
# )
## Mark cpp header files for installation
# install(DIRECTORY include/${PROJECT_NAME}/
# DESTINATION ${CATKIN_PACKAGE_INCLUDE_DESTINATION}
# FILES_MATCHING PATTERN "*.h"
# PATTERN ".svn" EXCLUDE
# )
## Mark other files for installation (e.g. launch and bag files, etc.)
# install(FILES
# # myfile1
# # myfile2
# DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION}
# )
#############
## Testing ##
#############
## Add gtest based cpp test target and link libraries
# catkin_add_gtest(${PROJECT_NAME}-test test/test_lwr_description.cpp)
# if(TARGET ${PROJECT_NAME}-test)
# target_link_libraries(${PROJECT_NAME}-test ${PROJECT_NAME})
# endif()
## Add folders to be run by python nosetests
# catkin_add_nosetests(test)
2. 元功能包metapackage
Metapackage:即多个功能包的集合,方便管理
以前实现这个功能的叫stack,现已废弃
CMakeLists.txt
用于声明本软件包Metapackage
:
cmake_minimum_required(VERSION 2.8.3)
# 将project中改为自己的包名
project(ros_test_metapackage)
find_package(catkin REQUIRED)
#声明本软件包是一个metapacakge
catkin_metapackage()
pacakge.xml
附加标签:
<url>
:有关包装信息的URL,通常是ros.org上的Wiki页面<author>
:软件包的作者
用于添加所含功能包,通过将子功能包设置为依赖项实现:
<package>
<!--将ros_test_metapackage改为自己的包名-->
<name>ros_test_metapackage</name>
<version>0.1.1</version>
<description>
--------------------------------------------------------------------------
描述语言
--------------------------------------------------------------------------
</description>
<maintainer email="a@a.com">aaa</maintainer>
<author>aaa</author>
<url>http://http://www.droid.ac.cn</url>
<license>BSD</license>
<buildtool_depend>catkin</buildtool_depend>
<!--注意这里的run_depend标签, 将其他软件
包都设为依赖项-->
<run_depend>package1</run_depend>
<run_depend>package2</run_depend>
<run_depend>package3</run_depend>
<!--这里需要有export和metapacakge标签, 注意这种固定写法-->
<export>
<metapackage/>
</export>
</package>
参考文献: