Reading the PX4 data log into python 3.5

I have been trying to write my own code to take the px4 log file and read it into python 3.5. Then be able to generate graphs I need from it. I know you can convert it to CSV file using the sdlog2_dump.py code and go from there which is easy. However, as a learning experience, I would like to learn how would I take this binary data and parse it myself. Unfortunately, I am very new to python so I couldn’t figure out how the person who wrote the CSV python code converter (sdlog2_dump.py) worked.

If anyone knows of any newbie friendly source where I can start to learn on how to write such a code that would be great.

Thank you.

Hi Mike

Reading binary data in python is a very specific and low-level topic. The standard library provides struct to do so. There are some other ways, you can google for the topic. It might be easier to learn python in more general at first.

We are currently working on a replacement which uses a different format and there is a python library for parsing the files: https://github.com/PX4/pyulog

If you are interested more generally in learning python for data science, you might find A Whirlwind Tour of Python useful, which is a free eBook.

Hi bkueng,

Thanks for getting back to me. I have tried running params.py to try and figure out how I can collect the data and plot it. I noticed that I needed the module you have mentioned. I tried installing using pip install ulog_parser. However, it says that module doesn’t exist. Is there another method I need to use to try and download that module?

It’s not on pip (yet), but if you clone the repo and run ./params.py <file> it should just work.

So here is what I did so far. I cloned the repo using
git clone https://github.com/PX4/pyulog.git
I know now I use import pyulog, however, I am a bit confused on how to call the script params.py and have it run on a binary file called log001.bin.

Thanks for your help btw, you don’t understand how much time I have tried to get this to work.

You need to make sure you use the correct files, they have the extension .ulg. You need the new logger, in SITL, to start it use logger start -e -t, and on the vehicle, see http://dev.px4.io/advanced-logging.html