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="ivana@osrf.org">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="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>

参考文献:

  • 3
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
ROS Noetic中,常用的强化学习功能是rl-texplore-rosros_gym。下面是这两个的安装和使用方法: 1. 安装rl-texplore-ros功能 ``` sudo apt-get install ros-noetic-rl-texplore-ros ``` 2. 安装ros_gym功能 ``` sudo apt-get install ros-noetic-ros-gym ``` 3. 使用rl-texplore-ros进行强化学习 rl-texplore-ros是一个用于强化学习ROS功能,它提供了一个通用的框架,可以用于快速开发和测试各种强化学习算法。使用rl-texplore-ros进行强化学习的步骤如下: - 创建一个新的ROS,例如"my_rl_package",并进入该的目录。 ``` mkdir my_rl_package && cd my_rl_package ``` - 创建一个新的强化学习任务,例如"my_rl_task"。 ``` rosrun rl_texplore_ros rl_texplore_node.py -e my_rl_task ``` - 编写一个强化学习算法,并使用rl-texplore-ros进行测试和评估。 4. 使用ros_gym进行强化学习 ros_gym是一个ROS接口,可以将ROS机器人和环境集成到OpenAI Gym中,从而可以使用OpenAI Gym中的各种强化学习算法。使用ros_gym进行强化学习的步骤如下: - 创建一个新的ROS,例如"my_gym_package",并进入该的目录。 ``` mkdir my_gym_package && cd my_gym_package ``` - 创建一个新的Gym环境,例如"my_gym_env"。在这个环境中,需要实现reset、step和render等函数,以控制机器人的行为并返回环境的状态和奖励。 ``` roscd ros_gym && python scripts/create_gym_env.py my_gym_env ``` - 在OpenAI Gym中使用自己的环境和强化学习算法进行测试和评估。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值