Ask Your Question
0

How to invoke a subscriber's callback periodically?

asked 2018-06-05 07:46:24 -0500

kolner gravatar image

updated 2018-06-07 02:53:30 -0500

Hello everyone,

I would like to sample messages from my sensors' topics every 15 seconds (mostly) synchronically, using message_filters.ApproximateTimeSynchronizer. Is that any possible way to register a callback, that will be invoked, for example, every 15 seconds? I've already check out rospy.Timer, but it seems to be not an appropriate way in my case.

My basic code:

def callback(sensor1, sensor2):
     #write messages into csv


def listener():

    sensor0 = message_filters.Subscriber("/sensor0/topic", Int32)
    sensor1 = message_filters.Subscriber("/sensor1/topic", Int32)

    ts = message_filters.ApproximateTimeSynchronizer([sensor0,sensor1], 10, 0.1)
    ts.registerCallback(callback)
    rospy.spin()
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2018-06-07 03:02:21 -0500

mgruhler gravatar image

A callback is an event driven routine. As such, by design, you cannot call it periodically. Just store the latest value in a class member and use a rospy.Timer to periodically take the latests values from those.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

2 followers

Stats

Asked: 2018-06-05 07:46:24 -0500

Seen: 65 times

Last updated: Jun 07 '18