是否可以在相同消息类型的 ROS 中对两个主题进行时间同步? [英] Is it possible to time synchronize two topics in ROS of same message type?

查看:122
本文介绍了是否可以在相同消息类型的 ROS 中对两个主题进行时间同步?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试将机器人抓手的位置映射到抓手所持物体所施加的阻力.我订阅了一个主题的夹具位置和另一个主题的阻力值,因为我想确保夹具位置对应于该位置的确切阻力值.鉴于两者都是浮动消息,我该如何同步它们?

I try to map robot gripper position to the resistance exerted by the object held by the gripper. I subscribed the gripper position from one topic and resistance value from another topic, since I want to ensure that the gripper position corresponds to the exact resistance value at that position. Given that both are float messages, how can I synchronize them?

self.sub1 = rospy.Subscriber("resistance", Float64, self.ard_callback)
self.sub2 = rospy.Subscriber("gripperpos", Float64, self.grip_callback)

推荐答案

您可以在 rospy 中使用 TimeSynchronizer.

You could use TimeSynchronizer in rospy.

这是一个订阅多个主题同时获取数据的例子:

This is an example to subscribe to multiple topics to get data at the same time:

import message_filters
from sensor_msgs.msg import Image, CameraInfo

def callback(image, camera_info):
  # Solve all of perception here...

image_sub = message_filters.Subscriber('image', Image)
info_sub = message_filters.Subscriber('camera_info', CameraInfo)

ts = message_filters.TimeSynchronizer([image_sub, info_sub], 10)
ts.registerCallback(callback)
rospy.spin()

<小时>

如果您的问题没有解决,则使用 ApproximateTimeSynchronizer 而不是 TimeSynchronizer:

ts = message_filters.ApproximateTimeSynchronizer([image_sub, info_sub], 1, 1)  

<小时>

阅读更多

这篇关于是否可以在相同消息类型的 ROS 中对两个主题进行时间同步?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆