【无人水面艇路径跟随控制5】(C++)USV代码阅读: 如何声明消息、服务和动作


请添加图片描述

🌈你好呀!我是 是Yu欸
🌌 2024每日百字篆刻时光,感谢你的陪伴与支持 ~
🚀 欢迎一起踏上探险之旅,挖掘无限可能,共同成长!

写在最前面

阅读代码: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
)

系统依赖

## 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

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>
  • <license>TODO</license>:定义包的许可证信息。每个包至少需要一个许可证标签。这里需要替换为实际的许可证类型,如 BSDMIT 等。

可选的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欸 。如果你喜欢我的文章,欢迎三连给我鼓励和支持:👍点赞 📁 关注 💬评论,我会给大家带来更多有用有趣的文章。
原文链接 👉 ,⚡️更新更及时。

欢迎大家添加好友交流。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

是Yu欸

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值