ros / ros_comm

ROS communications-related packages, including core client libraries (roscpp, rospy, roslisp) and graph introspection tools (rostopic, rosnode, rosservice, rosparam).
http://wiki.ros.org/ros_comm
752 stars 913 forks source link

Add option to not immediately start message_filters subscriber #2190

Open heuristicus opened 2 years ago

heuristicus commented 2 years ago

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()