ros_comm
ros_comm copied to clipboard
Add option to not immediately start message_filters subscriber
Solution for #2189.
This fixes an issue where sometimes caches do not receive the first message on the subscribed topic, if the message arrives immediately after initialising the subscriber. This can happen when the topic is latched, and is problematic if the latched topic never updates as the cache will never receive a message.
Example of starting a cache with delayed initialisation:
sub = message_filters.Subscriber(test_topic, PoseStamped, auto_start=False)
cache = message_filters.Cache(sub)
cache.registerCallback(callback)
# Both the internal cache callback and our custom callback are now in place, so we can start
# the subscriber and guarantee that even if a message arrives instantly both callbacks are called
sub.start()