0
$\begingroup$

Rosanswers logo

Hi,

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!


Originally posted by vkee on ROS Answers with karma: 127 on 2015-01-24

Post score: 1

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

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.


Originally posted by Martin Günther with karma: 11816 on 2015-01-27

This answer was ACCEPTED on the original site

Post score: 2

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.