ROS(一)
Messages & Services Generation
Any
.msgfile in the msg directory will generate code for use in all supported languages. The C++ message header file will be generated in~/catkin_ws/devel/include/<package_name>/。.srvwill generate header files in the same directory as the message header files.
service 与 message 创建步骤类似。
- 修改
CMakeLists.txt与package.xml
# `CMakeLists.txt` 添加 `message_generation` 包
find_package(catkin REQUIRED COMPONENTS
roscpp
rospy
std_msgs
message_generation
)
# 依赖 message_runtime
catkin_package(
...
CATKIN_DEPENDS message_runtime std_msgs # std_msgs 是依赖的消息
...)
# 添加相关文件
add_message_files(
DIRECTORY msg # 指定文件夹,默认是 msg
FILES
Num.msg
)
# 消息依赖
generate_messages(
DEPENDENCIES
std_msgs
)
生成消息时,修改 package.xml。
</-- Build 时只需要 message_generation --/>
<build_depend>message_generation</build_depend>

本文介绍了ROS中的消息和服务生成,强调将相关消息、服务集中到独立包中的良好实践。详细讲解了如何创建和修改msg及srv文件,以及如何处理依赖关系。此外,还探讨了ROS中的订阅与发布过程,包括boost::bind的使用,以及subscribe和advertise函数的参数说明。
最低0.47元/天 解锁文章
2万+

被折叠的 条评论
为什么被折叠?



