【问题标题】:Is it possible to time synchronize two topics in ROS of same message type?是否可以时间同步 ROS 中相同消息类型的两个主题?
【发布时间】:2019-09-22 05:20:53
【问题描述】:

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

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

【问题讨论】:

    标签: python python-3.x ros rospy


    【解决方案1】:

    您可以在rospy 中使用TimeSynchronizer

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

    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)  
    

    Reading More

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-03-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-09-28
      • 2021-12-05
      • 2021-11-04
      • 1970-01-01
      相关资源
      最近更新 更多