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

Delay incoming messages

asked 2016-11-18 12:58:35 -0500

piraka9011 gravatar image

Is there a way in Rospy to delay incoming messages? Specifically, I wish to delay incoming velocity commands for teleop.

I can't use a sleep because I still need my program/node to run other processes. I was wondering whether the queue size would have something to do with it?


edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2016-11-18 19:18:25 -0500

lucasw gravatar image

According to there is a TimeSequencer that does this, but only for C++ (and not much activity here about it, some example code is on ).

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


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

def delayed_callback(msg, event):

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

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

edit flag offensive delete link more


This is an interesting way of going about you reminded me how to pass two arguments to a callback (did it before but forgot how!) I will test this out when I get to work, thanks.

piraka9011 gravatar image piraka9011  ( 2016-11-18 22:54:43 -0500 )edit

So this actually worked! Very much appreciated. My implementation had an if/else statement that would decide if we wanted to have a delay or not in the original callback. Either way, good use of timers.

piraka9011 gravatar image piraka9011  ( 2016-11-21 15:11:41 -0500 )edit

Question Tools



Asked: 2016-11-18 12:58:35 -0500

Seen: 2,433 times

Last updated: Nov 18 '16