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

Inserting into a Rosbag

asked 2012-05-04 19:32:04 -0500

David Lu gravatar image

updated 2014-01-28 17:12:12 -0500

ngrennan gravatar image

Is there any way to add to a message to a rosbag at the beginning? I know you can append to a rosbag, but I want the message at the beginning.

Inserting all the other messages in afterward screws up the timing.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2012-05-05 07:28:28 -0500

Dustin gravatar image

I think rosbag Cookbook can do what you want.

By section 1.2 of that link you do the following

import rosbag

with rosbag.Bag('input.bag', 'a') as bag:
    from std_msgs.msg import String
    metadata = String(data='my metadata')

    for _, _, t in bag.read_messages():
    bag.write('/metadata', metadata, t - roslib.rostime.Duration(0, 1))

Of course this does require post processing the data which may not be desirable.

edit flag offensive delete link more


bag.write appends to a bagfile, but your code gets the emit time of the first message and substracts one usec, so that the metadata is the first message being emitted which results in a mess. To get a proper bag you'll need to add subprocess.Popen(['rosbag', 'fix', 'input.bag', 'output.bag'])

tik0 gravatar image tik0  ( 2016-08-29 02:16:25 -0500 )edit

Question Tools

1 follower


Asked: 2012-05-04 19:32:04 -0500

Seen: 1,231 times

Last updated: May 05 '12