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

How to use ApproximateTime in python

asked 2013-09-19 04:43:28 -0500

whiterose gravatar image

updated 2014-01-28 17:18:00 -0500

ngrennan gravatar image

Hi all,

I'm trying to synchronize (approximately since the stamps of the topics are different) 4 topics.

I have looked at the ApproximateTime example here:

But how to do it in python? I have looked at the Python API ( for message filters, but it says nothing about approximatetime.

Thanks in advance.

edit retag flag offensive close merge delete


Here 10 is the size of queue and 1 is the time in sec to consider for aprox:

one = message_filters.Subscriber('robot0/sonar_0', Range)
two = message_filters.Subscriber('robot0/sonar_1', Range)
ts = message_filters.ApproximateTimeSynchronizer([one, two],10,1)
Ananthakrishnan gravatar image Ananthakrishnan  ( 2015-10-18 12:51:15 -0500 )edit

2 Answers

Sort by ยป oldest newest most voted

answered 2015-04-05 12:17:33 -0500

ApproximateTime was added for python in indigo, and is documented in the indigo version of the api docs.

edit flag offensive delete link more


It seems that this kind of subscriber cannot be unregistered, can you confirm?

Mehdi. gravatar image Mehdi.  ( 2018-12-03 06:37:19 -0500 )edit

you can unsubscribe by iterating over each message_filter's subscription

Assuming you subscribed like this:

self.subs = [message_filters.Subscriber(topic, mtype) for topic, mtype in zip(self.topics, self.types)]
self.ts = message_filters.ApproximateTimeSynchronizer(
            5,  # queue size

You can unsubscribe like this:

for sub in self.subs:
ljburtz gravatar image ljburtz  ( 2021-05-28 21:34:31 -0500 )edit

answered 2017-11-25 17:04:39 -0500

jayess gravatar image

Just in case someone has some trouble getting going with this, here's an example:

from message_filters import ApproximateTimeSynchronizer, Subscriber

def gotimage(image, camerainfo):
    assert image.header.stamp == camerainfo.header.stamp
    print "got an Image and CameraInfo"

image_sub = Subscriber("/wide_stereo/left/image_rect_color", sensor_msgs.msg.Image)
camera_sub = Subscriber("/wide_stereo/left/camera_info", sensor_msgs.msg.CameraInfo)

ats = ApproximateTimeSynchronizer([image_sub, camera_sub], queue_size=5, slop=0.1))

I adapted this from the docs.

edit flag offensive delete link more

Question Tools

1 follower


Asked: 2013-09-19 04:43:28 -0500

Seen: 12,999 times

Last updated: Nov 25 '17