0
$\begingroup$

Rosanswers logo

Hi,

I am writing a piece of code which uses the rosbag python API to parse a bag file. It crawls a directory and processes all found bags (searches for *.bag). Basically it looks like this

for filename in *.bag
    bag  = rosbag.Bag(filename)
    for topic, msg, ts in bag.read_messages(...):
        # do something
    # output something

I am having the problem that I encounter splitted bag files.

splitted_2015-02-05-12-24-43_0.bag
splitted_2015-02-05-12-24-45_1.bag
splitted_2015-02-05-12-24-47_2.bag

As the crawling is done automatically (e.g. every night), I do not have the possibility to manually tell the system which bags belong together. I don't like the idea to add this data manually by e.g. adding another description file.

Skipping the once which end with a number different from 0 is easy. But identifying the next part is hard. With rosbag play the user defines all parts to join. A manual solution giving each sequence a different prefix is not suitable as I am working on existing files. Currently I am having a heuristic which looks like this:

1) split the filename into: prefix_dateAndTime_counter.bag
2) get the timestamp of the last message in the current bag
3) check if files exist with name
    3.1) prefix_dateAndTime(last timestamp)_(counter+1).bag
    3.2) add 1 second to "last timestamp" and retry 3.1
4) if 3.1or 3.2 succeed continue with this file otherwise stop parsing

Question 1: Has there been a reason to not include meta information about splitted bags into the bagfile? Some meta data telling e.g. the name of the next bagfile.

For the future I would love to have something like:

  • an entry at the end of a bag "this bag continues in xyz.bag"
  • or an option to tell rosbag record keep the timestamp of the first bag fixed and just change the counter, resulting in something like "date_1.bag date_2.bag ..."

Question 2: Anything planned like that for the future?


Originally posted by anonymous4756 on ROS Answers with karma: 31 on 2015-02-13

Post score: 0

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

There's not really a place in the bag files for adding arbitrary metadata like you want. And I don't think that it is worth extending the bag format that way.

As a simple work around I suggest that you use directories to group bag files. That should take care of your issue correlating bags from a single recording. The other suggestion is to use a slightly more dynamic prefix which encodes your run number or some other element which you can correlate between the bags.


Originally posted by tfoote with karma: 58457 on 2015-02-13

This answer was ACCEPTED on the original site

Post score: 0

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.