rosbag Documentation

rosbag: ROS Bag Tools

This is a set of tools for recording from and playing back to ROS topics. It is intended to be high performance and avoids deserialization and reserialization of the messages.

rosbag is a set of tools and API's for recording/writing messages to bag files and playing/reading them back.


The C++ and Python API's are provided for serializing bag files. The C++ API consists of the following classes:

Here's a simple example of writing to a bag file:

#include "rosbag/bag.h"
rosbag::Bag bag("test.bag", rosbag::bagmode::Write);
std_msgs::Int32 i; = 42;
bag.write("numbers", ros::Time::now(), i);

Likewise, to read from that bag file:

#include "rosbag/bag.h"
rosbag::Bag bag("test.bag");
rosbag::View view(bag, rosbag::TopicQuery("numbers"));
BOOST_FOREACH(rosbag::MessageInstance const m, view)
    std_msgs::Int32::ConstPtr i = m.instantiate<std_msgs::Int32>();
    if (i != NULL)
    	std::cout << i->data << std::endl;

The Python API is similar. Writing to a bag file:

import rosbag
from std_msgs.msg import Int32, String
bag = rosbag.Bag('test.bag', 'w')
i = Int32() = 42
bag.write('numbers', i);

Example usage for read:

import rosbag
bag = rosbag.Bag('test.bag')
for topic, msg, t in bag.read_messages('numbers'):

Author(s): Tim Field (, Jeremy Leibs (, and James Bowman (
autogenerated on Sat Dec 28 2013 17:43:05