Developer

Python MAVLink interface (version 0.2)

mavlink-logo.png?w=400

 

For those of you who prefer a scripting language for your MAVLink needs, you may like to have a look at pymavlink, a Python implementation of the MAVLink protocol.I've just released version 0.2, which fixes some bugs, and adds support for the latest changes in the upstream mavlink git repository.

I initially wrote pymavlink to make it easier to develop MAVProxy, a little command line tool which provides a proxy between a MAVLink master and some number of slaves. I use this for a HIL setup between FlightGear, APM and qgroundcontrol. I'm releasing it more widely as I'm hoping it will be more generally useful to the diydrones community. It can be used to write little scripts that manipulate and display MAVLink messages in interesting ways.

The way pymavlink works is that you generate a custom mavlink python module using mavgen.py, which reads a set of MAVLink message definition files in their XML format, and spits out a ready to use python module that implements all the messages in the XML files.

A good example of what can be done with a short script is mavlogdump.py, which formats a qgroundcontrol MAVLink log file in a human readable manner. This really shows the advantage of using a scripting language for MAVLink, as it can easily display structures without having to write a lot of formatting code for each of the messaging types.

For our UAV project we are planning on using sets of python scripts with pymavlink to do things like mission planning, log analysis, camera control, image processing etc.

If you want to ask questions about pymavlink, it is probably best to join the mavlink mailing list.

 

E-mail me when people leave their comments –

You need to be a member of diydrones to add comments!

Join diydrones

Comments

  • Developer

    @Tobias, another possibility is to generate some cython code.

  • Developer

    @Tobias, nice work!

    Do you think we could use the SWIG backend with a wrapper to give the pymavlink API? There is a lot of code using the pymavlink API already, and it would be really nice to get the speedup without rewriting the apps.

    Cheers, Tridge

  • Developer

    unless your mavlink and MAVProxy folders are *in the same folder*, it won't work.    ie  /somefolder/mavlink   and /somefolder/MAVProxy  need to be in the same /somefolder.     PATH is not used.

  • Developer

    I hate to say the obvious, but it means it couldn't find your pymavlink installation.  ( either you don't have one, or its in the wrong place) .   do you at least *have* a pymavlink folder somewhere nearby ( it should be inside the mavlink folder). 

  • Developer

    homepage for mavproxy ( and friends is here)

    http://www.qgroundcontrol.org/mavlink/mavproxy_startpage

  • Where can I find more information on using mavlogdump.py and the log fields? I am using mavtogpx to parse some Ardu logs and confused about the heading (hdg) field. Is this the same as compass? How can I access the compass output? Thanks a million!

  • Developer

    @Andre, you are welcome to ask here if you prefer

     

  • Andrew, great to hear about those updates. I'm currently trying to get mavproxy running for HIL sim with flightgear and qgroundcontrol. I have a couple of questions but I guess I better ask these in the mailinglist. Running this stuff on a Mac.

  • Developer

    @Pete, I'm glad its working for you in a DOS window. I hadn't tested with IDLE before. It looks like IDLE has problems with multi-threaded programs. Other people have reported this problem with IDLE for other programs.

    The way mavproxy works is that the main program runs the command input (a raw_input() loop) and a separate thread handles all the communications. The funny thing is that I ended up doing it this was because that was the only way I could get it to run on Windows! The first version just added stdin to the select loop and ran everything in a single non-threaded program, but windows can't select on stdin and doesn't have the type of async readline support that is possible on Linux, so I changed things to keep input separated.

     

  • Developer

    Tridge, My general impression is that the windows version of mavlink works fine when run from a DOS command window. However,  commands like "param set ROLLKD 0.2", when running with mavproxy that has been executed from the IDLE editor in windows, will often fail. And quite often I am getting strange characters appearing in the python shell window (the window where the MAV> prompt is happening.  So I will need to do some more investigation over the next few days. In the meantime, the mavproxy running from a DOS window seems to work just fine.  That is super for our current project, thanks, Pete

     

    Sample output from typical (good) session when mavproxy run from  IDLE GUI:-

    Mode(2,0)> param show
    ROLLKD          0.099999
    ROLLKP          0.299988
    YAWKDAIL        0.299997
    YAWKPAIL        0.299988
    Mode(2,0)> param set ROLLKP 0.1
    Mode(2,0)> param fetch
    Requested parameter list
    Mode(2,0)> param show
    ROLLKD          0.099999
    ROLLKP          0.099976
    YAWKDAIL        0.299997
    YAWKPAIL        0.299988
    Mode(2,0)> param set 0.2
    Usage: param set PARMNAME VALUE
    Mode(2,0)> param set YAWKDAIL 0.1
    Mode(2,0)> param fetch
    Requested parameter list
    Mode(2,0)> param show
    ROLLKD          0.099999
    ROLLKP          0.099976
    YAWKDAIL        0.099999
    YAWKPAIL        0.299988
    Mode(2,0)>

     

    sample output from session that is going wrong (when pavproxy run from within IDLE):

    MAV> param show
    Mode(2,0)> Mode Mode(2,0)
    Mode(2,0)> param fetch
     Requested parameter list
    $Mode(2,0)> param show
    ?$Mode(2,0)> param fetch
    QRequested parameter list
    ?#Mode(2,0)> @param show
    :=Mode(2,0)>

     

    I had no errors like the above when running mavproxy from a DOS command window.

     

This reply was deleted.