ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | Q&A
Ask Your Question

Playback of rosbag file at the same rate that messages are stored in rospy

asked 2015-01-24 16:20:42 -0500

vkee gravatar image


I am trying to playback data that I have stored using rosbag in rospy. Is it possible to playback the rosbag file in rospy at the same rate that it is recorded? I know that I can do this from the command line, but I would like to be able to do this all in rospy if possible.

Thank you!

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted

answered 2015-01-27 04:25:11 -0500

updated 2015-02-04 07:21:57 -0500

The function read_messages() returns the time that the message was recorded (see the rosbag Python API), so you could wait for that and publish the message then. Something like this:

import rosbag
import time

bag = rosbag.Bag('test.bag')
offset = bag.get_start_time() - time.time()
for topic, msg, t in bag.read_messages():
    # sleep until `time.time() > t + offset`
    # publish `msg` on `topic`

The function get_start_time() seems to have been added in indigo. On earlier distros, you'll need to copy it from here.

In order for this to work properly, you'll also need to set the parameter use_sim_time = true, and in your rospy node you need to publish the /clock topic (while waiting for the time to publish the next message).

Update: For some of the other stuff (creating publishers for all necessary topics etc.), have a look at rosbaglive.

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

1 follower


Asked: 2015-01-24 16:20:42 -0500

Seen: 1,038 times

Last updated: Feb 04 '15