PyMAVLink Tools

PyMAVLink provides a number of command-line and visual tools for real-time and offline data analysis and plotting. It supports MAVLink stream logs as well as the self-describing log formats from PX4 and APM.

Installation

Archlinux

python2-mavlink-git is available from the AUR.

yaourt -Sy python2-mavlink-git

Ubuntu

sudo apt-get install python-matplotlib

After installing matplotlib, continue with pymavlink:

cd ~
mkdir -p src
cd src
git clone https://github.com/mavlink/mavlink/
cd mavlink/pymavlink
python setup.py install --user

Now it installed to COPY THIS PATH FROM THE STATUS MESSAGES, IT MAY VARY: $HOME/.local/lib/python2.6/site-packages/

Edit ~/.bash_profile or ~/.bashrc and add this line:

export PYTHONPATH="$HOME/.local/lib/python2.6/site-packages/:$PYTHONPATH"
export PATH="$HOME/.local/lib/python2.6/bin/:$PATH"

Now source the file:

source ~/.bash_profile

MacOS

Install the required libraries using Homebrew.

brew update
brew install gcc # gfortran compiler
brew install homebrew/python/matplotlib

After installing matplotlib, continue with pymavlink:

cd ~
mkdir -p src
cd src
git clone https://github.com/mavlink/mavlink/
cd mavlink/pymavlink
python setup.py install --user

Now it installed to: $HOME/Library/Python/2.7/lib/python/site-packages/

Edit ~/.bash_profile or ~/.bashrc and add this line:

export PYTHONPATH="$HOME/Library/Python/2.7/lib/python/site-packages/:$PYTHONPATH"
export PATH="$HOME/Library/Python/2.7/bin/:$PATH"

Now source the file:

source ~/.bash_profile

Troubleshooting

Test with:

 mavlogdump.py log001.bin 

If the result is not a dump of the packages, but a similar error message:

Traceback (most recent call last):
  File "/Users/user/Library/Python/2.7/bin/mavlogdump.py", line 36, in <module>
    dialect=opts.dialect)
TypeError: mavlink_connection() got an unexpected keyword argument ‚dialect'

Use this command to get the site-packages path:

  python -c "from distutils.sysconfig import get_python_lib; print(get_python_lib())“

and then a ls in this dir:

  ls /Library/Python/2.7/site-packages/

If the command returns something, delete the old entry:

  sudo rm -rf /Library/Python/2.7/site-packages/pymavlink-1.0.10-py2.7.egg/
  

ImportError: cannot import name ardupilotmega

Re-run the setup but leaving off NOGEN=1 as follows:

python setup.py install --user

Analyzing Logfiles

Dumping to Screen

mavlogdump.py log001.bin

This dumps this (and more) data to the screen. Redirect to a file to look at it:

mavlogdump.py log001.bin > dump.txt
2013-12-01 00:32:28.01: IMU {AccX : -0.0461373627186, AccY : -0.139223739505, AccZ : -9.83524513245, GyroX : -0.00255563622341, GyroY : 0.00514737004414, GyroZ : 0.000739033857826, MagX : 0.0717520192266, MagY : -0.239621385932, MagZ : -0.538776278496}
2013-12-01 00:32:28.01: SENS {BaroPres : 958.08996582, BaroAlt : 469.624786377, BaroTemp : 40.6899986267, DiffPres : 1.94448852539}
2013-12-01 00:32:28.01: ATT {Roll : 0.00514317676425, Pitch : -0.00589724583551, Yaw : 1.25613701344, RollRate : 0.000589099829085, PitchRate : 0.00539944786578, YawRate : -0.000444599427283}
2013-12-01 00:32:28.01: OUT0 {Out0 : 0.0, Out1 : 0.0, Out2 : 1015.0, Out3 : 0.0, Out4 : 0.0, Out5 : 0.0, Out6 : 0.0, Out7 : 0.0}
2013-12-01 00:32:28.01: ATTC {Roll : 0.00145985407289, Pitch : 0.00139534892514, Yaw : 1.99584197998, Thrust : 0.0457380451262}
2013-12-01 00:32:28.01: LPOS {X : -0.0644039362669, Y : 0.0744694247842, Z : 140.008117676, VX : 0.0198747199029, VY : 0.114666625857, VZ : -0.594419419765, RefLat : -35.3625417, RefLon : 149.1654766, RefAlt : 0.0, XYFlags : 11, ZFlags : 11, Landed : 1}
2013-12-01 00:32:28.01: GPOS {Lat : -35.3625417, Lon : 149.1654766, Alt : 470.04486084, VelN : 0.0198747199029, VelE : 0.114666625857, VelD : -0.594419419765}

Dump to Matlab File

  mavtomfile.py log001.bin

Will create the file log001.m. Note: This is a .m, not a .mat file and hence Matlab will struggle with large log files. If just a part of a flight is relevant, just this part can be exported:

mavtomfile.py log001.bin --condition='MAV.percent>10 and MAV.percent<12'

If the log001.m file is loaded in Matlab, the workspace is populated as shown in the screenshot below. To do so, just 'run' the .m file:

>> log001.m

After this step, the workspace is populated with data.

And can then be normally accessed (and stored as .mat file).

Create Plot

Download the file to a local folder and then run mavgraph:

mavgraph.py log001.bin RC.Ch1 'degrees(ATT.Pitch):2' 'lowpass(AIRS.IndSpeed,"a",0.9):2' --marker=. --condition='MAV.percent>10 and MAV.percent<18' 'degrees(PX4_update(IMU,ATT).pitch):2'

This will bring up this plot:

in which the user interface allows to save this PNG:

Troubleshooting

Edit the file '~/.matplotlib/matplotlibrc' and edit / put this line in:

backend: MacOSX
Translations of this page:


Quick Links

QR Code: URL of current page