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

Publishing .bag file for different nodes

asked 2013-12-19 00:58:58 -0600

Phorce gravatar image

updated 2014-01-28 17:06:36 -0600

ngrennan gravatar image

Let's say I have two topics publishing data:



These two topics are currently saving to a rosbag file as they publish the data. I'm creating another node which extracts the features. I therefore need to create a node that subscribes to the .bag file and then writes these to an array which I can then use for extracting the features from.

Is this possible in ros? And can anyone offer any tutorials on this?


edit retag flag offensive close merge delete

3 Answers

Sort by ยป oldest newest most voted

answered 2013-12-19 01:24:12 -0600

David Galdeano gravatar image

updated 2013-12-19 01:24:28 -0600

Hello, you can subscribe to /chatter1 and /chatter1 with a node while rosbag is running. You can have many subscriber to one publisher.

edit flag offensive delete link more


@galdeano Hey thanks. How would I open (or get access) to the data inside the rosbag file that is recording to `/chatter1` and `/chatter2` whilst it is running though?

Phorce gravatar image Phorce  ( 2013-12-19 01:33:39 -0600 )edit

I do not understand, why would you access the data on the rosbag file, while you have the real time data published? If you still need to manipulate bag files, use: but as said in the begin of the document: 'Note that the rosbag API's are not thread-safe for reading and writing any given bag file. Users of the APIs must ensure no concurrent input/output operations are performed on different threads.' So you can't read and write at the same time.

David Galdeano gravatar image David Galdeano  ( 2013-12-19 03:37:06 -0600 )edit

@galdeano - Very valid point. I've misunderstood. But, I do not know of a way to subscribe to multiple topics in Python and being able to store this data inside a numpy array? The problem is that, using rosbag it takes both data of the nodes and combines them. I need a way to do this

Phorce gravatar image Phorce  ( 2013-12-19 03:41:11 -0600 )edit

answered 2013-12-19 23:39:23 -0600

demmeln gravatar image

Are you asking how to subscribe to two topics with one node?

You can simply create multiple Subscribers, so in the tutorial

ros::Subscriber sub1 = n.subscribe("chatter1", 1000, chatterCallback1);
ros::Subscriber sub2 = n.subscribe("chatter2", 1000, chatterCallback2);

and similarly in python.

edit flag offensive delete link more

answered 2013-12-19 01:55:24 -0600

VC gravatar image

There are 2 ways you can access the data in the bag file

  1. Play back the bag file using rosbag play <bagfile>; your processing node can then subscribe to the topics and collect the data as it is published.
  2. Access the data in the bag file programmatically using the rosbag C++ API.
edit flag offensive delete link more


@VC thanks for your reply. Are there any tutorials on the carrying out the 1st one? For example, I'm currently trying to subscribe to both the `/camera/depth_registered/points` and another topic which outputs the data?

Phorce gravatar image Phorce  ( 2013-12-19 02:27:33 -0600 )edit

Question Tools

1 follower


Asked: 2013-12-19 00:58:58 -0600

Seen: 2,997 times

Last updated: Dec 19 '13