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

Revision history [back]

According to http://wiki.ros.org/message_filters there is a TimeSequencer that does this, but only for C++ (and not much activity here about it, some example code is on http://stackoverflow.com/questions/34322075/ros-message-filterstimesequencer).

I tried this rospy.Timer based method and it looks like it is working, I don't know if it is robust- a bunch of Timers must be created behind the scenes and hopefully are taken care of properly:

#!/usr/bin/env python

import functools
import rospy

from std_msgs.msg import Float64

rospy.init_node("delay")

pub = rospy.Publisher("delayed", Float64, queue_size=4)

def delayed_callback(msg, event):
    pub.publish(msg)

def callback(msg):
    timer = rospy.Timer(rospy.Duration(2.0),
                        functools.partial(delayed_callback, msg),
                        oneshot=True)

sub = rospy.Subscriber("input", Float64, callback, queue_size=4)

rospy.spin()