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

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

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

vkee gravatar image

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!

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
2

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

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

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

Question Tools

1 follower

Stats

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

Seen: 1,158 times

Last updated: Feb 04 '15