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 a
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