【无人水面艇路径跟随控制5】(C++)USV代码阅读: 如何声明消息、服务和动作
这个CMake构建脚本配置了一个名为 publish_waypoints的ROS包,定义了包的依赖关系、编译选项和如何声明消息、服务和动作。通过这些配置,可以确保项目在编译时正确地找到所需的头文件和库文件,并生成所需的目标文件。这个 package.xml文件定义了 publish_waypoints包的基本信息、维护者、许可证和依赖关系。需要注意的是,某些占位符(如许可证信息)需要替换为实际内容
【无人水面艇路径跟随控制5】(C++)USV代码阅读: 如何声明消息、服务和动作
写在最前面
阅读代码:https://github.com/USE-jx/USV_path_follow/tree/main
usv path follow:无人水面艇路径跟随
trajectory tracking:轨迹跟踪
CMakeLists.txt
motion_control\guidance\publish_waypoints\CMakeLists.txt
这个文件 CMakeLists.txt
是一个CMake构建脚本,定义了如何构建和配置名为 publish_waypoints
的ROS包。
总结
这个CMake构建脚本配置了一个名为 publish_waypoints
的ROS包,定义了包的依赖关系、编译选项和如何声明消息、服务和动作。通过这些配置,可以确保项目在编译时正确地找到所需的头文件和库文件,并生成所需的目标文件。
代码解释
以下是代码的详细解释:
CMake最低版本和项目名称
cmake_minimum_required(VERSION 3.0.2)
project(publish_waypoints)
cmake_minimum_required(VERSION 3.0.2)
:指定CMake的最低版本要求为3.0.2。project(publish_waypoints)
:定义项目名称为publish_waypoints
。
编译选项
## Compile as C++11, supported in ROS Kinetic and newer
# add_compile_options(-std=c++11)
add_compile_options(-std=c++11)
:添加编译选项,指定使用C++11标准进行编译(目前被注释掉)。
查找catkin包
## 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 COMPONENTS
geometry_msgs
nav_msgs
roscpp
std_msgs
visualization_msgs
)
find_package(catkin REQUIRED COMPONENTS ...)
:查找并加载catkin包及其依赖的组件,包括geometry_msgs
、nav_msgs
、roscpp
、std_msgs
和visualization_msgs
。
系统依赖
## System dependencies are found with CMake's conventions
# find_package(Boost REQUIRED COMPONENTS system)
find_package(Boost REQUIRED COMPONENTS system)
:查找并加载Boost库及其系统组件(目前被注释掉)。
Python设置
## 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()
catkin_python_setup()
:如果包中包含setup.py
文件,取消注释此行以确保模块和全局脚本被安装(目前被注释掉)。
声明ROS消息、服务和动作
################################################
## 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
- 这部分注释提供了如何在包中声明和构建消息、服务和动作的步骤:
- 在
package.xml
文件中添加message_generation
的build_depend
标签。 - 在
package.xml
文件中为每个消息/服务/动作依赖包添加build_depend
和exec_depend
标签。 - 如果
MSG_DEP_SET
不为空,可以添加message_runtime
的exec_depend
标签。 - 在
CMakeLists.txt
文件中,将message_generation
和每个消息/服务/动作依赖包添加到find_package(catkin REQUIRED COMPONENTS ...)
中。 - 在
CMakeLists.txt
文件中,将message_runtime
和每个消息/服务/动作依赖包添加到catkin_package(CATKIN_DEPENDS ...)
中。 - 取消注释
add_*_files
部分,并列出每个.msg
/.srv
/.action
文件。 - 取消注释
generate_messages
条目。
- 在
package.xml
motion_control\guidance\publish_waypoints\package.xml
这个文件 package.xml
是一个ROS包的描述文件,定义了包的元数据和依赖关系。
总结
这个 package.xml
文件定义了 publish_waypoints
包的基本信息、维护者、许可证和依赖关系。需要注意的是,某些占位符(如许可证信息)需要替换为实际内容。这个文件对于ROS包的构建和管理至关重要。
代码解释
以下是代码的详细解释:
XML声明
<?xml version="1.0"?>
- 声明XML版本为1.0。
包格式和基本信息
<package format="2">
<name>publish_waypoints</name>
<version>0.0.0</version>
<description>The publish_waypoints package</description>
<package format="2">
:指定包的格式版本为2。<name>publish_waypoints</name>
:定义包的名称为publish_waypoints
。<version>0.0.0</version>
:定义包的版本为0.0.0
。<description>The publish_waypoints package</description>
:提供包的描述信息。
维护者信息
<!-- One maintainer tag required, multiple allowed, one person per tag -->
<!-- Example: -->
<!-- <maintainer email="jane.doe@example.com">Jane Doe</maintainer> -->
<maintainer email="jiaxier@todo.todo">jiaxier</maintainer>
<maintainer email="jiaxier@todo.todo">jiaxier</maintainer>
:定义包的维护者及其电子邮件地址。每个包至少需要一个维护者标签。
许可证信息
<!-- One license tag required, multiple allowed, one license per tag -->
<!-- Commonly used license strings: -->
<!-- BSD, MIT, Boost Software License, GPLv2, GPLv3, LGPLv2.1, LGPLv3 -->
<license>TODO</license>
可选的URL标签
<!-- Url tags are optional, but multiple are allowed, one per tag -->
<!-- Optional attribute type can be: website, bugtracker, or repository -->
<!-- Example: -->
<!-- <url type="website">http://wiki.ros.org/publish_waypoints</url> -->
<url>
标签是可选的,可以包含包的相关链接,如网站、问题跟踪器或代码仓库。
可选的作者标签
<!-- Author tags are optional, multiple are allowed, one per tag -->
<!-- Authors do not have to be maintainers, but could be -->
<!-- Example: -->
<!-- <author email="jane.doe@example.com">Jane Doe</author> -->
<author>
标签是可选的,可以包含包的作者信息。作者不一定是维护者。
依赖关系
<!-- The *depend tags are used to specify dependencies -->
<!-- Dependencies can be catkin packages or system dependencies -->
<!-- Examples: -->
<!-- Use depend as a shortcut for packages that are both build and exec dependencies -->
<!-- <depend>roscpp</depend> -->
<!-- Note that this is equivalent to the following: -->
<!-- <build_depend>roscpp</build_depend> -->
<!-- <exec_depend>roscpp</exec_depend> -->
<!-- Use build_depend for packages you need at compile time: -->
<!-- <build_depend>message_generation</build_depend> -->
<!-- Use build_export_depend for packages you need in order to build against this package: -->
<!-- <build_export_depend>message_generation</build_export_depend> -->
<!-- Use buildtool_depend for build tool packages: -->
<!-- <buildtool_depend>catkin</buildtool_depend> -->
<!-- Use exec_depend for packages you need at runtime: -->
<!-- <exec_depend>message_runtime</exec_depend> -->
<!-- Use test_depend for packages you need only for testing: -->
<!-- <test_depend>gtest</test_depend> -->
<depend>
:用于指定既是构建依赖又是运行依赖的包。<build_depend>
:用于指定编译时需要的包。<build_export_depend>
:用于指定构建时需要导出的包。<buildtool_depend>
:用于指定构建工具包。<exec_depend>
:用于指定运行时需要的包。<test_depend>
:用于指定仅在测试时需要的包。
hello,我是 是Yu欸 。如果你喜欢我的文章,欢迎三连给我鼓励和支持:👍点赞 📁 关注 💬评论,我会给大家带来更多有用有趣的文章。
原文链接 👉 ,⚡️更新更及时。
欢迎大家添加好友交流。
更多推荐
所有评论(0)