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