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

Revision history [back]

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(topics=['chatter', 'numbers']):
    # 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).

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(topics=['chatter', 'numbers']):
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).

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.