ROS學習筆記17 —— 功能包(package)與元功能包(Metapackage)的使用

1. 功能包package

1)package.xml

format 2:

根標籤
```xml
<package format="2">

</package>
```
  • 必須標籤
    1. <name> :包名

    2. <version> :軟件包的版本號(必須爲3個點分割的證書)

    3. <description> :包內容的描述

    4. <maintainer> :負責維護包的開發人員信息

    5. <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="[email protected]">Ivana Bildbotz</maintainer>
      <license>BSD</license>
    </package>
    
依賴關係

6種依賴關係使用以下集中標籤指定:

  1. <depend>:指定依賴關係爲構建、導出和執行依賴關係,最常用,只需要提及每個ROS包依賴項就行了,比較簡單。對於博主這種懶人,就適合使用它!!!
  2. <build_depend>:指定構建此功能包所需要的包,僅使用某些特定的依賴關係來構建程序包,而不是在執行時使用,可編譯來自依賴包的頭文件(尤其CMake中使用find_package()時)
  3. <build_export_depend>:指定針對該包構建所需要的功能包(尤其CMake中catkin_package()聲明爲(CATKIN_)DEPENDS時)
  4. <exec_depend>:聲明運行程序包時所需的共享庫、可執行文件、Python模塊、啓動腳本和其他文件的依賴關係,指定運行該功能包中代碼所需要的功能包(尤其CMake中catkin_package()聲明爲(CATKIN_)DEPENDS時)
  5. <test_depend>:指定單元測試的其他依賴項,他們不應該複製已經提到的任何以來
  6. <buildtool_depend>:指定軟件包自行構建所需要的構建系統工具,一般是catkin,這也是必須的標籤
  7. <doc_depend>:指定生成文檔所需要的文檔工具
<package format="2">
  <name>foo_core</name>
  <version>1.2.4</version>
  <description>
    This package provides foo capability.
  </description>
  <maintainer email="[email protected]">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="[email protected]">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="[email protected]">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="[email protected]">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>

參考文獻:

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章