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?



Views: 3210

Reply to This

Replies to This Discussion

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.

Reply to Discussion



Season Two of the Trust Time Trial (T3) Contest 
A list of all T3 contests is here. The current round, the Vertical Horizontal one, is here

© 2019   Created by Chris Anderson.   Powered by

Badges  |  Report an Issue  |  Terms of Service