In ROSBag, filter header column

asked 2021-07-05 04:01:10 -0500

sandy gravatar image

updated 2021-07-05 08:06:52 -0500

When I parse any ROSBag file, I got both message header (column) and message data. My goal is to dynamically convert selected column data into CSV files.

Code :

bag = Bag("my_ros.bag")
topic_name = '/vehicle/gps/fix'
for topic, msg, t in bag.read_messages(topic_name):
    logging.debug(str(msg))

Output :

   line ['header: ', '  seq: 1879', '  stamp: ', '    secs: 1542667203', '    nsecs: 560826751', "  frame_id: ''", 'status: ', '  status: 0', '  service: 1', 'latitude: 30.6395066667', 'longitude: -96.470272', 'altitude: 54.75', 'position_covariance: [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]', 'position_covariance_type: 0']

How I can avoid system-generated headers and data populating in messages?

Ex: for me system header will be: header,seq, stamp,stamp,position_covariance_type,...., These I want to filter out. I am interested in only core column data: longitude, altitude, latitude.

So my output will be look like :

line [ 'latitude: 30.6395066667', 'longitude: -96.470272', 'altitude: 54.75', 'position_covariance: [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]']

Any suggestion on how I can achieve it?

edit retag flag offensive close merge delete

Comments

Speaking for ros2 since I don't know for ros1, you can just open the sql database and select all the topics you want with their raw data.

highmax1234 gravatar image highmax1234  ( 2021-07-05 15:48:54 -0500 )edit