ROS (一) ----消息服务的创建与使用

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

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

ROS(一)

Messages & Services Generation

Any .msg file 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>/.srv will generate header files in the same directory as the message header files.

service 与 message 创建步骤类似。

  1. 修改 CMakeLists.txtpackage.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>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值