Is it possible to time synchronize two topics in ROS of same message type?

喜夏-厌秋 提交于 2019-12-31 04:30:09

问题


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)

回答1:


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()

If your problem not resolved, there is ApproximateTimeSynchronizer rather than TimeSynchronizer:

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

Reading More



来源:https://stackoverflow.com/questions/55458218/is-it-possible-to-time-synchronize-two-topics-in-ros-of-same-message-type

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!