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

  • @Andrew 

    I'm planning to control the Hexacopter with the mavlink using PC. Can you give me some pointers on how to do this?

    Thanks!

  • 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!

  • I'm practically a stranger to mavproxy and this new system so a wiki would be great!
  • Can you guys please set up a wiki?
    Who's with me!!!
  • 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.

     

  • Developer

    Tridge, Serial Auto Detection is working OK. I'm still checking out the rest of the Windows code in windows. Pete

    In the following output, a single FTDI USB serial connection is attached to my laptop:-

    C:\Users\phollands\Desktop\MAVProxy>mavproxy.py
    Logging to mav.log
    MAV> ^D
    exiting
    Exception in thread Thread-1 (most likely raised during interpreter shutdown):
    C:\Users\phollands\Desktop\MAVProxy>

     

    In the following scenario, no FTDI USB connections are connected to the PC

     

    C:\Users\phollands\Desktop\MAVProxy>mavproxy.py

    Please choose a MAVLink master with --master
    For example:
        --master=com14
        --master=/dev/ttyUSB0
        --master=127.0.0.1:14550

    Auto-detected serial ports are:

     

    C:\Users\phollands\Desktop\MAVProxy>

     

    In the following scenario there are two FTDI USB serial cables connected:-

        C:\Users\phollands\Desktop\MAVProxy>mavproxy.py

    Please choose a MAVLink master with --master
    For example:
        --master=com14
        --master=/dev/ttyUSB0
        --master=127.0.0.1:14550

    Auto-detected serial ports are:

    COM4 : USB Serial Port (COM4) : FTDIBUS\COMPORT&VID_0403&PID_6001
    COM5 : USB Serial Port (COM5) : FTDIBUS\COMPORT&VID_0403&PID_6001

    C:\Users\phollands\Desktop\MAVProxy>

     

This reply was deleted.