From bag file (.db3) to csv

Hello guys

I am using ros2 to record a bag file. The bag is saved in a folder with a metadata.yaml adn a bag.db3 contain the messages that then I can play back.

Since here all good, but I want to see the data in bag.db3 visually. I would like to translate the .db3 to a .csv file.

Can someone direct me on the right path? I am bit lost, all the document online deal with ROS1.

Thank you

Hi @GRINGOLOCO ,

You can use a Database Viewer Program like the SQLite Browser to visualize the .db3 file data. You don’t have to convert it to a .csv file.

I hope this helps.

Regards,
Girish

Hi,
Thank you for your help and time.
I appriciate your advice, but still I have a problem seeing the data.
I downloaded the .db3 bag, and imported it in SQLlite, but still, in the messages table I dont see the data… it can also be that the structure of the topic is not visible (like I can’t see for example vel.vel_x, vel.vel_y, etc…)

I would appriciate if you can help me debug it.

Hi @GRINGOLOCO ,

The hidden data shown as BLOB is what you see in the right side panel that says “Edit Database Cell”. The mode is selected by default, which in your case is Binary.

Since it is not possible to display that data blob in the table itself, SQLite Browser displays the contents in the right panel.

I hope this clarifies your problem.

Regards,
Girish

Hi Girish, thank you for the support again.
Is there a way I can see the BLOB hiden data? that actualy are the messages I published to diffrent topics… the data I really need.
Thank you
Kind regards
GO

because the content in binary, is not what I really have in the message I published to the node… Also that binary number is the same for each row

Hi @GRINGOLOCO ,

Did you try exploring the options on the right panel in the “Edit Database Cell” section? I am assuming that you did not try doing that.

There are several modes that you can choose from: Text, RTL Text, Binary, Image, JSON, and XML.
The options are quite self-explanatory, so I am not going to explain what each option does.

As with the Binary mode, your can use the horizontal scroll bar to move to the right side of the Binary byte-data to see the text string.

I hope this helps!

Regards,
Girish


Also if I change the Mode to Text or something else an error shows up saying: ‘Data can’t be viewed in this mde, try to switch to binary mode’

Hi @GRINGOLOCO ,

The output from your image just makes it clear that the byte-data or the blob-data is encoded/encrypted and cannot be directly seen as text and needs to be decoded.
If you have the information of the encoding then you can decode it yourself!
The message is seemingly quite small at 24 bytes, so you should not have problems probing and decoding the data.

Regards,
Girish

thnk you, how do you advice to decode it? I know the structure of the message sendet to the topic, I can just retrive it by doing:

ros2 interface proto <topic_name>

such as:

"
linear:
x: 0.0
y: 0.0
z: 0.0
angular:
x: 0.0
y: 0.0
z: 0.0
"

Then? how do you advice to procede?

Hi @GRINGOLOCO ,

You can just run (or play) the ros2 bag in a loop and use a python program to read the speed values.
That will be the easiest way. You can also get the headers for each specific message.

Regards,
Girish

Can you davice me any code/repo/link/source/direction where I can start doing that?

Using this simple code:

import sqlite3

import pandas as pd

‘’’ Connect to the SQLite database’‘’

conn = sqlite3.connect(‘my_bag2_0.db3’) # Replace ‘your_database.db3’ with the actual name of your .db3 file

‘’‘Query to select all data from a specific table (replace ‘your_table’ with the actual table name)’‘’

‘’‘query = “SELECT * FROM sqlite_master WHERE type=‘table’;” ‘’’

query = “SELECT * FROM messages;”

‘’’ Load data into a DataFrame ‘’’

df = pd.read_sql_query(query, conn)

‘’’ Save the DataFrame to a .csv file ‘’’

df.to_csv(‘output_file2.csv’, index=False) # Replace ‘output_file.csv’ with the desired name for the .csv file

‘’’ Close the connection ‘’’

conn.close()

I was able to transform the .db3 to .csv, but the messgaes data are still encoded:

Hi @GRINGOLOCO ,

I am afraid that there is no immediate shortcut to doing that.

You should have a working installation of a ROS2 Version [Foxy or Humble] on your computer.
Then you should install ROS2 Bag to run ros2 bag files.
Once you have ROS2 installed along with ROS2 Bag, you can start and run the bag file in a loop and use a simple python program to decode the messages.

On the other hand, if you have an un-encoded message and an encoded message, you can decode all other messages using the same decode logic. But I am assuming this will be a harder task for you since I understand that you have not previously worked with ROS2.

Regards,
Girish

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.