ros的topic:创建消息类型、发布、订阅

1、创建消息

英文网页:http://wiki.ros.org/ROS/Tutorials/CreatingMsgAndSrv

msg是一个文本文档,包括前缀和数据类型,前缀:

 Header header  头,时间戳和所在坐标系
  string child_frame_id  子坐标系(还没搞明白) 
每行一个数据类型,数据类型可以是:
  • int8, int16, int32, int64 (plus uint*) 
  • float32, float64
  • string 字符串
  • time, duration 时间
  • other msg files 其他封装消息
  • variable-length array[] and fixed-length array[C] 动态数组和静态数组

(1)创建消息文件

工程中,创建msg/Student.msg

写入:

[cpp]   view plain copy
  1. string name  
  2. uint8 age  
  3. uint32 score  
(2)制作

CMakelists.txt中添加

rosbuild_genmsg()
用于生成Student.h文件

查看:rosmsg show Student


2、发布消息

(1)初始化ros系统

(2)广播消息

[cpp]   view plain copy
  1.   ros::Publisher chatter_pub = n.advertise<beginner_tutorials::Student>("chatter", 1000);//发布的消息类型,topic名称,缓存的消息数  

(3)填充消息数据,指定频率发布

[cpp]   view plain copy
  1. msg.data = ss.str();//填充消息内容  
[cpp]   view plain copy
  • 0
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值