Ask Your Question

Export topic from bag at different rate

asked 2017-12-31 13:21:25 -0500

Marcus Barnet gravatar image

Hi to all,

i have recorded several bag files which contain different topics recorded at different rates. For example:

topics:    /sensor/FilterStatus        11514 msgs    : diagnostic_msgs/DiagnosticStatus
             /sensor/Imu               11497 msgs    : sensor_msgs/Imu                 
             /sensor/NavSatFix         11514 msgs    : sensor_msgs/NavSatFix           
             /sensor/SystemStatus      11498 msgs    : diagnostic_msgs/DiagnosticStatus
             /sensor/Twist             11514 msgs    : geometry_msgs/Twist             
             /robodyne/enc               718 msgs    : std_msgs/String                 
             /robodyne/io                719 msgs    : std_msgs/String                 
             /robodyne/sys               719 msgs    : std_msgs/String                 
             /robodyne/velocity          719 msgs    : std_msgs/String                 
             /rosout                       9 msgs    : rosgraph_msgs/Log

As you can see, messages related to sensor are sampled at a very higher rate than the robodyne messages. I need to have all the topics with the same amount of messages and so I would like to find a way to filter the sensor messages and extract only 10 samples per second.

Can you suggest me a solution, please?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2018-01-01 10:17:11 -0500

gvdhoorn gravatar image

updated 2018-01-01 10:25:59 -0500

I don't believe there is any built-in support in rosbag for this directly, but it should be trivial using the rosbag C++/Python API (some further examples here).

You could also take a look at rosbag filter and the Python expression that can be used with it, but I'm unsure as to whether there is any state persisted between evaluations of the expression (which would make counting or inter-msg-relationships difficult).

edit flag offensive delete link more


Thank you for your tip! I never coded in Python so it is hard for me to figure out how to write the code to extract only 10 sample from my BAG files. I was thinking to do this with Matlab, but it should be difficult, too. :(

Marcus Barnet gravatar image Marcus Barnet  ( 2018-01-01 10:21:42 -0500 )edit

Take a look at the examples I linked. They aren't very difficult. There is a C++ API as well, but if you don't have any coding experience, they might throw up some more hurdless.

Matlab has a rosbag API as well, but I have no experience with it. Seems a bit overkill to me as well.

gvdhoorn gravatar image gvdhoorn  ( 2018-01-01 10:25:15 -0500 )edit

The second Python example on the "rosbag API" page (under Python: "Example usage for read") is almost what you'd need. Just filter by topic name/msg type and add counters.

gvdhoorn gravatar image gvdhoorn  ( 2018-01-01 10:27:19 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2017-12-31 13:21:25 -0500

Seen: 496 times

Last updated: Jan 01 '18