带有header的自定义ros meaasge

8 篇文章 0 订阅
5 篇文章 0 订阅

主要参考链接:
http://wiki.ros.org/msg

最近由于需求,需要自定义一些topic格式进行数据的处理。基于常见的数据类型:int32 flosat32 bool 等可以定义出需要的消息格式。
如:example.msg

int32  a
float32  b
bool  c

则在终端查看消息类型为example.msg定义的example_topic时

rostopic echo /example_topic

有类似如下显示:

a: 1
b: 1.0
c: true
---
a: 1
b: 1.0
c: true
---
a: 1
b: 1.0
c: true
---
a: 1
b: 1.0
c: true
---

当显示的频率较大时,由于数据刷新很快,对于数据的可读性、分析和把握提出很高的要求。为了改善上述问题,可以在消息前添加Header格式数据。
std_msgs/Header message :

# Standard metadata for higher-level stamped data types.
# This is generally used to communicate timestamped data 
# in a particular coordinate frame.
# 
# sequence ID: consecutively increasing ID 
uint32 seq
#Two-integer timestamp that is expressed as:
# * stamp.sec: seconds (stamp_secs) since epoch (in Python the variable is called 'secs')
# * stamp.nsec: nanoseconds since stamp_secs (in Python the variable is called 'nsecs')
# time-handling sugar is provided by the client library
time stamp
#Frame this data is associated with
# 0: no frame
# 1: global frame
string frame_id

原example.msg可以修改为:

Header header
int32  a
float32  b
bool  c

此时再次输出example_topic时,得到类似下述显示:

header:
  seq: 1
  stamp:
    secs: 1538813853
    nsecs: 968391761
  frame_id: frame_test
a: 1
b: 1.0
c: true
---
header:
  seq: 2
  stamp:
    secs: 1538813854
    nsecs:  67791173
  frame_id: frame_test
a: 1
b: 1.0
c: true
---
header:
  seq: 3
  stamp:
    secs: 1538813854
    nsecs: 168768708
  frame_id: frame_test
a: 1
b: 1.0
c: true
---

此时可以根据seq、secs和nsecs值可以更好的观测和分析终端显示的数据。
seq:topic当前发布的次数
secs:topic发布的系统时间 unit:秒
nsecs:topic发布的系统时间 unit:纳秒

  • 12
    点赞
  • 26
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值