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

Best way to add a topic to an existing rosbag?

asked 2017-08-28 08:45:00 -0500

vkee gravatar image

updated 2017-08-28 08:45:28 -0500

What would be the best way to add a topic to an existing rosbag?

Play the bag and publish the topic while doing a rosbag record -a?

Thanks!

edit retag flag offensive close merge delete

Comments

Add to an bag you just created in w mode or add to a file by opening and appending? The latter is not possible

jwhendy gravatar image jwhendy  ( 2018-10-15 10:55:16 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
1

answered 2017-08-28 09:18:54 -0500

gvdhoorn gravatar image

updated 2017-08-28 09:21:31 -0500

Use the rosbag API to open the bag, and write it out while adding the new messages for the topic.


Edit: if you already have a bag that has the other topic(s) (or can easily create one), you could attempt a merge instead. No official tools afaik, but there have been some people that implemented similar things. See #q122761 fi.

edit flag offensive delete link more

Comments

Based on the rosbag API link (which only provides the 'w' option for writing, and this erases an existing bag) and the merge code, which reads the old bag and re-writes to a new one... the answer is actually "you can't add a topic to an existing bag," right?

jwhendy gravatar image jwhendy  ( 2018-10-15 10:51:55 -0500 )edit
1

In other words, the first sentence is misleading and I think should be "You can't do this in place. You have to create a new bag in w mode, open the existing bag in r mode, re-write all old messages to the new bag, adding what you want on top."

jwhendy gravatar image jwhendy  ( 2018-10-15 10:53:21 -0500 )edit

I believe "misleading" is a bit strong: only very few storage formats that support streaming interfaces / infrastructure will allow you to append data to the end and still have everything work correctly (ie: stream the contents in chronological order). It's simply not something that ..

gvdhoorn gravatar image gvdhoorn  ( 2018-10-15 10:55:27 -0500 )edit

.. works that way. And rosbag is no exception.

What you write in your comment ("read, write while adding") is at least implied by the "open [..], and write it out while adding the new messages for the topic".

gvdhoorn gravatar image gvdhoorn  ( 2018-10-15 10:56:28 -0500 )edit

I interpreted the question to be about modifying a file. I haven't tried, and wouldn't recommend, but foo = bag(file.bag, 'r') and bar = bag(file.bag, 'w') and then writing foo into bar + extra could be possible. You'd lose the original forever.

jwhendy gravatar image jwhendy  ( 2018-10-15 11:38:19 -0500 )edit

For the answer, it seems simpler to write the details of the method in addition to linking vs. just linking with ambiguous phrasing. This suggests the links could hold the answer. I know how to re-write... and I was hoping to append, so I expected to be enlightened.

jwhendy gravatar image jwhendy  ( 2018-10-15 11:39:46 -0500 )edit

So that's what I meant by misleading. The answer isn't wrong, it just dangled hope before me but when I looked at the links I realized it's what I've already been doing (and could have been spared time reading). Python can append to files, so it's reasonable to think bags might allow it, too.

jwhendy gravatar image jwhendy  ( 2018-10-15 11:41:45 -0500 )edit

The question posted by the OP did not ask for code, it only asked for "the best way". There is no point in repeatedly posting code for the same thing so a hint about where to look for information seems much more appropriate.

gvdhoorn gravatar image gvdhoorn  ( 2018-10-15 11:42:24 -0500 )edit

Question Tools

1 follower

Stats

Asked: 2017-08-28 08:45:00 -0500

Seen: 5,358 times

Last updated: Aug 28 '17