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 generate.sh 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?

Thanks,

Michael

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

Join diydrones

Email me when people reply –

Replies

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

    - The mavgen.py 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 github.com/mavlink/mavlink

    cd mavlink/message-definitions/v1.0

    [Copy your XML file into here]

    cd ../../pymavlink

    python setup.py 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/xsvalErrorHandler.py", 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

    mavlink/pymavlink/generator/mavgen.py

    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 mavproxy.py command line:

    mavproxy.py --master tcp:127.0.0.1:5760 --sitl 127.0.0.1:5501 --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:

      DEFAULT_VALIDATE = False

      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.

Activity

Neville Rodrigues liked Neville Rodrigues's profile
Jun 30
Santiago Perez liked Santiago Perez's profile
Jun 21
More…