Best Practice for adding custom MAVLINK command...

Hey All,

I am looking to add a new custom MAVLINK command and wish to do it in the least obtrusive way to ensure future compatibility and easy code merges. Here is my planned procedure:

1) Add command XML

a) Create a new XML called custom_MAVLink.xml

b) Include ardupilotmega.xml

c) Add a new message with an unused id.

d) Call the script targeted at custom_MAVLink.xml

2) Process new command

a) Add a new case to GCS_MAVLINK::handleMessage in GCS_Mavlink.pde

b) Decode packet using generated decoder (step 1)

c) Work magic with the received data

Have I missed anything or done it incorrectly?



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

Join diydrones

Email me when people reply –


  • Hi all, thought I would share my notes on this task:

    - The script doesn't handle nested includes, only one level down. So you need to include both ardupilotmega.xml and common.xml in your custom XML.

    - The reference to the generated v1.0/ardupilotmega/mavlink.h is hardwired in ardupilot/libraries/GCS_MAVLink/GCS_MAVLink.h . You need to replace this with an include of custom/mavlink.h 

    I also went through the process of trying to add the same extension to MAVProxy, which uses the python MAVLink implementation.

    In order to build python support for an extended MAVProxy:

    git clone

    cd mavlink/message-definitions/v1.0

    [Copy your XML file into here]

    cd ../../pymavlink

    python install

    This will re-install the existing pymavlink libraries with your custom definitions included. 

    There is also a bug the XML validator that requires a <messages> block, but doesn't read it correctly for some reason if both these files are included:

    File "/mnt/hgfs/repos/mavlink/pymavlink/generator/lib/minixsv/", line 141, in _raiseXsvalException
    raise XsvalError (output)
    generator.lib.minixsv.xsvalErrorHandler.XsvalError: ERROR: custom.xml: line 4: Missing child tag u'messages' in tag u'mavlink'!

    This was fixed by editing


    and setting 'performValidation = false' after it is initially set.

    To use the new mavlink version, you also need to specify it as the dialect on the command line: --master tcp: --sitl --dialect custom

    Michael if you made any further progress on this would be interested to hear!

    • Hi Francis,

      Thanks for the post! Had the same issue, could not include multiple definition files. Followed your advice:


      and now it seems to be working! Strange though because it should technically not make any difference right?

      Since the reason for it is:

      "Do not perform XML validation. Can speed up code generation if XML files are known to be correct."

      Anyhow, its working now and I will try to figure out why at a later stage.

This reply was deleted.


DIY Robocars via Twitter
RT @gclue_akira: 柏の葉で走行させてるjetracerの中身 #instantNeRF #jetracer
Jul 4
DIY Robocars via Twitter
Cool web-based self-driving simulator. Click save when the AI does the right thing
Jul 4
DIY Robocars via Twitter
RT @donkey_car: Human-scale Donkey Car! Hope this makes it to a @diyrobocars race
Jun 25
DIY Robocars via Twitter
Jun 25
DIY Robocars via Twitter
Jun 16
DIY Robocars via Twitter
RT @GrantEMoe: I won my first @diyrobocars @donkey_car virtual race! Many thanks to @chr1sa @EllerbachMaxime @tawnkramer and everyone who m…
Jun 13
DIY Robocars via Twitter
RT @gclue_akira: JetRacerで自動走行したコースを、InstantNeRFで再構築。データセットは別々に収集 #jetracer #instantNeRT
Jun 13
DIY Robocars via Twitter
RT @SmallpixelCar: SPC 3.0 Now the motor also works. This car is doable. I just need to design a deck to mount my compute and sensors. http…
Jun 13
DIY Robocars via Twitter
RT @SmallpixelCar: My new car SPC 3.0.
Jun 7
DIY Robocars via Twitter
RT @SmallpixelCar: High speed at @diyrobocars thanks @EdwardM26321707 for sharing the video
Jun 7
DIY Robocars via Twitter
RT @SmallpixelCar: Today at @RAMS_RC_Club for @diyrobocars. Used @emlid RTK GPS and @adafruit @BoschGlobal IMU. Lap time 28s…
May 28
DIY Robocars via Twitter
May 15
DIY Robocars via Twitter
May 14
DIY Robocars via Twitter
May 13
DIY Robocars via Twitter
RT @f1tenth: Say hi to our newest #F1TENTH creation for @ieee_ras_icra next week in Philly. It’s going to be huge! 😎 🔥 @AutowareFdn @PennEn…
May 13
DIY Robocars via Twitter
May 11