You are here:-, PX4-PX4 Research Log [9] – Analyzing flight on Ubuntu

PX4 Research Log [9] – Analyzing flight on Ubuntu

There are two ways to analyze your PX4 flight as I know, the “.px4log” file generated by PX4, and the “.mavlink” file generated by QGroundControl.


1. “.px4log” with FlightPlot

The “.px4log” format is the log file format stored onto the SD card by PX4. The application that performs this logging is “sdlog2”. The log files record all UORB topics, so you can review your entire flight.

To download these logs from your controller board SD card, you can connect your controller board to QGroundControl, then under widgets, there is a log download option, choose the log you want to download.

You need a third party log viewer to review your “.px4log” log. The viewer I prefer is FlightPlot. First clone the source code from Github: “https://github.com/DrTon/FlightPlot.git”.Make sure you initialized and update the submodules. Then compile the source code using “ant”. You can get “ant” by “sudo apt-get install ant”. After that you can run the program by “java -jar out/production/flightplot.jar”.


1.1 “.px4log” with LogMuncher

Another easy to use analyzer is the LogMuncher available at http://logs.uaventure.com/

It is completely over the Internet. You upload your “.px4log” onto the website server and wait for a bit, and you will see your flight logs categorized in plots. However, the disadvantages are you cannot scale the plots or extract the exact data points from the plots.


1.2 “.px4log” with PyMAVLink Tools

Official guide: https://pixhawk.org/dev/pymavlink

This tool will dump your “.px4log” into a “.txt” file or a Matlab executable “.m” file. The “.m” file is much more useful as you can pull whatever data you need from the log to plot and format.

On Ubuntu, you need to get the matplotlib package first:
sudo apt-get install python-matplotlib

After that, clone the mavlink repository into your desired location:
cd ~/where/you/want/your/mavlink/repository
mkdir -p src
git clone https://github.com/mavlink/mavlink/
cd mavlink
git submodule update --init --recursive
python setup.py install --user

For some reason the last step failed on my system, but it doesn’t seem like it is preventing me from using the tool. So just leave it.

Now go to any directory, and type “mavlogdump.py”, you should see a message that tell you too few arguments. This means the tools are successfully installed.

If you wish to process a log file called “flight.px4log” now, use the following commands:
mavlogdump.py flight.px4log > flight.txt
This will dump the log into a “.txt” file, which is only useful for small logs, it can be very difficult to make sense of it if your log is longer than a few minutes.
mavtomfile.py flight.px4log
This will process the log into a “.m” file, which can then be run by Matlab to load data into workspace. Notice it is “.m” file not “.mat” file so a very large log will cause problem with less powerful computers. You can chop the log up into smaller percentages using the following command:
mavtomfile.py flight.px4log --condition='MAV.percent>=0 and MAV.percent<25'
This will only convert 25% of your log into “.m” file, and then you can stitch the rest of the data together by “mavtomfile.py” the remaining 3 quarters of the log.


2. “.mavlink”

The “.mavlink” files are automatically generated by QGroundControl every flight. It records everything QGroundControl received and sent during the time between arm and disarm.

Start your flight normally and when you are finished with your flight and disconnect your vehicle, you will be prompted by QGroundControl to save this “.mavlink” file. Choose a convenient location, the next time you want to view this log, launch QGroundControl and don’t connect anything to it. Got to”File” and tick “Show Status Bar”, you will see a new status bar at the bottom of the window. On the lower right corner, click the “Replay Flight Data” button and you will be prompted to choose the “.mavlink” file. Do that and you will see the flight replayed in QGroundControl.

By |2017-05-22T05:52:57+00:00August 31st, 2016|Categories: Flight Control, PX4|2 Comments

About the Author:

2 Comments

  1. Ayesha March 11, 2017 at 7:32 am - Reply

    Hello zihao,

    PX4 has now moved to ulogs. Is there an user friendly tool to analyse .ulgs apart from Flight Plot ?
    Also, I am not very familiar with the plots and having issues interpreting them. Any links/ pointers on how to interpret and understand the logs will be highly useful for me.
    Thanks.

Leave A Comment