ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Rather than using TimeSynchronizer I used ApproximateTimeSynchronizer and it worked. So, I changed the code to-

class sync_listener:
    def __init__(self):
        self.image_sub = message_filters.Subscriber('camera/rgb/image_color', Image)
        self.info_sub = message_filters.Subscriber('camera/projector/camera_info', CameraInfo)
        self.ts = message_filters.ApproximateTimeSynchronizer([self.image_sub, self.info_sub], 1, 1) # Changed code
        self.ts.registerCallback(self.callback)

    def callback(self, image, camera_info):
        print("done")

def main(args):
    ls = sync_listener()
    rospy.init_node('sample_message_filters', anonymous=True)
    try:
        rospy.spin()
    except KeyboardInterrupt:
        print("Shutting down")

if __name__ == '__main__':
    main(sys.argv)

Before finding this solution, I just used global variables to access the message of the first topic by assigning the message to the global variable in the callback and used it on the callback of the second, and that's how I was able to work with both. It's not clean but saves hours of frustration.

Rather than using TimeSynchronizer I used ApproximateTimeSynchronizer and it worked. So, I changed the code to-

class sync_listener:
    def __init__(self):
        self.image_sub = message_filters.Subscriber('camera/rgb/image_color', Image)
        self.info_sub = message_filters.Subscriber('camera/projector/camera_info', message_filters.Subscriber('camera/rgb/camera_info', CameraInfo)
        self.ts = message_filters.ApproximateTimeSynchronizer([self.image_sub, self.info_sub], 1, 1) # Changed code
        self.ts.registerCallback(self.callback)

    def callback(self, image, camera_info):
        print("done")

def main(args):
    ls = sync_listener()
    rospy.init_node('sample_message_filters', anonymous=True)
    try:
        rospy.spin()
    except KeyboardInterrupt:
        print("Shutting down")

if __name__ == '__main__':
    main(sys.argv)

Before finding this solution, I just used global variables to access the message of the first topic by assigning the message to the global variable in the callback and used it on the callback of the second, and that's how I was able to work with both. It's not clean but saves hours of frustration.