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

前端 未结 1 932
野性不改
野性不改 2020-12-22 04:34

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

1条回答
  •  时光说笑
    2020-12-22 05:19

    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

    0 讨论(0)
提交回复
热议问题