Package: pymavlink
PymavlinkThis is a Python implementation of the MAVLink protocol.
It includes a source code generator (generator/mavgen.py) to create MAVLink protocol implementations for other programming languages as well.
Also contains tools for analyzing flight logs.DocumentationPlease seehttp://ardupilot.org/dev/docs/mavlink-commands.htmlfor mavlink command reference.For realtime discussion please see the pymavlinkGitter channelExamples can be foundin the repositoryor in theArduSub bookInstallationPymavlink supports both Python 2 and Python 3.The following instructions assume you are using Python 3 and a Debian-based (like Ubuntu) installation... note::pymavlink assumes the command "python" is in your path.  Your distribution may provide a package such as "python-is-python3" to ensure that "python" is in your path.DependenciesPymavlink has several dependencies :- [future](http://python-future.org/) : for Python 2 and Python 3 interoperability
- [lxml](http://lxml.de/installation.html) : for checking and parsing xml fileOptional :- numpy : for FFT
- pytest : for testsOn Linuxlxml has some additional dependencies that can be installed with your package manager (here withapt-get) :.. note::If you continue to use Python 2 you may need to change package names here (e.g. python3-numpy => python-numpy)sudoapt-getinstalllibxml2-devlibxslt-devOptional for FFT scripts and tests:sudoapt-getinstallpython3-numpypython3-pytestUsing pip you can install the required dependencies for pymavlink :sudopython-mpipinstall--upgradefuturelxmlOn WindowsUse pip to install future as for Linux.
Lxml can be installed with a Windows installer from here :https://pypi.org/project/lxmlInstallationFor usersIt is recommended to install pymavlink from PyPI with pip, that way dependencies should be auto installed by pip.sudopython-mpipinstall--upgradepymavlinkMavnativeStarting from September 2022, mavnative, a C extension for parsing mavlink, was deprecated and removed. Mavnative developpement was stalled for long time, it only supports MAVLink1 and doesn't get any fix on the protocol.For developersFrom the pymavlink directory, you can use :sudoMDEF=PATH_TO_message_definitionspython-mpipinstall.-vSince pip installation is executed from /tmp, it is necessary to point to the directory containing message definitions with MDEF. MDEF should not be set to any particular message version directory but the parent folder instead. If you have cloned from mavlink/mavlink then this is/mavlink/message_definitions. Using pip should auto install dependencies and allow you to keep them up-to-date.Or:sudopythonsetup.pyinstallArdupilot Custom ModesBy default,pymavlinkwill map the Ardupilot mode names to mode numbers per the definitions in theardupilotmega.xmlfile. However, during development, it can be useful to add to or update the default mode mappings.To do this:create a folder named.pymavlinkin your home directory (i.e.$HOMEon Linux,$USERPROFILEon Windows); andadd a JSON file calledcustom_mode_map.jsonto this new.pymavlinkfolder.The JSON file is a dictionary that maps vehicleMAV_TYPEvalue to a dictionary of mode numbers to mode names. An example that duplicates the existing mapping forMAV_TYPE_FIXED_WING(enumvalue of1) vehicles is as follows:{"1":{"0":"MANUAL","1":"CIRCLE","2":"STABILIZE","3":"TRAINING","4":"ACRO","5":"FBWA","6":"FBWB","7":"CRUISE","8":"AUTOTUNE","10":"AUTO","11":"RTL","12":"LOITER","13":"TAKEOFF","14":"AVOID_ADSB","15":"GUIDED","16":"INITIALISING","17":"QSTABILIZE","18":"QHOVER","19":"QLOITER","20":"QLAND","21":"QRTL","22":"QAUTOTUNE","23":"QACRO","24":"THERMAL"}}Thiscustom_mode_map.jsonfile can be used to:change the display name of an existing mode (e.g. change"TAKEOFF"to"LAUNCH");add a new mode (e.g. add"25": "NEW_MODE"); andadd a mapping for an unsupported vehicle type (e.g. add a mapping forMAV_TYPE_AIRSHIP(enumvalue of7) vehicles).Notes:Whilst theMAV_TYPEand mode numbers are integers, they need to be defined asstrings in the JSON file, as raw integers can't be used as dictionary keys in JSON.This featureupdatesthe default definitions. You can use it to change the name-to-number mapping for a mode, but you completely can't remove an existing mapping.Licensepymavlink is released under the GNU Lesser General Public License v3 or later.The source code generated by generator/mavgen.py is available under the permissive MIT License.