0
$\begingroup$

Rosanswers logo

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?


Originally posted by Marcus Barnet on ROS Answers with karma: 287 on 2017-12-31

Post score: 0

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

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).


Originally posted by gvdhoorn with karma: 86574 on 2018-01-01

This answer was ACCEPTED on the original site

Post score: 1


Original comments

Comment by Marcus Barnet on 2018-01-01:
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. :(

Comment by gvdhoorn on 2018-01-01:
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.

Comment by gvdhoorn on 2018-01-01:
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.

$\endgroup$

Your Answer

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