Skip to main content

A library for the MAVLink protocol

Project description

Libmav Python

Native python bindings for the libmav library. libmav-python is a runtime defined low-level MAVLink library.

In comparison to other python MAVLink libaries, it has certain advantages:

  • Runtime defined message set. No need to recompile on message set change or custom messages
  • Implemented in C++. Much faster than pure python
  • Simple, pythonic API. No need to learn a new API or asyncio, just use python

Installation

pip install libmav

Example usage

import libmav

# Create a message set from a mavlink xml file
message_set = libmav.MessageSet('<PATH TO common.xml>')
# You can also add additional messages here with inline xml
message_set.add_from_xml_string('''
<mavlink>
    <messages>
        <message>
            ...
        </message>
    </messages>
</mavlink>''')

# Create a message from the message set
message = message_set.create('MY_PROTOCOL_MESSAGE')

# Set fields of the message individually
message['my_numeric_field'] = 1
message['my_char_array_field'] = 'Hello world'
message['my_float_array_field'] = [1.0, 2.0, 3.0]
message['my_int_array_field'] = [4, 5, 6]

# Get fields individually
my_num = message['my_numeric_field']
my_string = message['my_char_array_field']
my_float_array_field = message['my_float_array_field']

# You can also use pythonic things like list comprehensions
    # This creates a list of all the values in my_float_array_field multiplied by 2
my_float_array_field = [x * 2 for x in message['my_float_array_field']]

# Set fields from a dict
message.set_from_dict({
            'my_numeric_field': 1,
            'my_char_array_field': 'Hello world',
            'my_float_array_field': [1.0, 2.0, 3.0],
            'my_int_array_field': [4, 5, 6]
        })


# Get fields as python dict
message_dict = message.to_dict()


# Connect to a TCP server
conn_physical = libmav.TCPClient('192.168.1.12', 14550)
conn_runtime = libmav.NetworkRuntime(self.message_set, heartbeat, conn_physical)

connection = conn_runtime.await_connection(2000)

# Check if connection is still alive
if not connection.alive():
    print('Connection lost, waiting for reconnect...')
    connection = conn_runtime.await_connection(2000)

# Send a message
connection.send(message)

# Receive a message, timeout 1s
received_message = connection.receive("HEARTBEAT", 1000)

# Receive a message, no timeout
received_message = connection.receive("HEARTBEAT")

# Receive a message as the result of a message we send
# This avoids the race condition between us sending and then waiting for reception
expectation = connection.expect("PARAM_VALUE")
connection.send(our_param_request_message)
received_message = connection.receive(expectation, 1000)


# Connect to a Serial port
conn_physical = libmav.Serial('/dev/ttyUSB0')
conn_runtime = libmav.NetworkRuntime(self.message_set, heartbeat, conn_physical)

⚠️ Note: The network runtime object and the physical interface object must be kept scope for the duration of the connection. Otherwise, the connection will not have a valid underlying network and will crash.

Install from source

Prerequisites

  • A compiler with C++11 support
  • Pip 10+ or CMake >= 3.4 (or 3.14+ on Windows, which was the first version to support VS 2019)
  • Ninja or Pip 10+

Just clone this repository and pip install. Note the --recursive option which is needed for the pybind11 submodule:

git clone --recursive https://github.com/Auterion/libmav-python.git
pip install ./libmav-python

With the setup.py file included in this project, the pip install command will invoke CMake and build the pybind11 module as specified in CMakeLists.txt.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

libmav-0.0.6.tar.gz (335.2 kB view hashes)

Uploaded Source

Built Distributions

libmav-0.0.6-cp312-cp312-musllinux_1_1_x86_64.whl (783.6 kB view hashes)

Uploaded CPython 3.12 musllinux: musl 1.1+ x86-64

libmav-0.0.6-cp312-cp312-musllinux_1_1_i686.whl (858.6 kB view hashes)

Uploaded CPython 3.12 musllinux: musl 1.1+ i686

libmav-0.0.6-cp312-cp312-musllinux_1_1_aarch64.whl (753.6 kB view hashes)

Uploaded CPython 3.12 musllinux: musl 1.1+ ARM64

libmav-0.0.6-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (297.2 kB view hashes)

Uploaded CPython 3.12 manylinux: glibc 2.17+ x86-64

libmav-0.0.6-cp312-cp312-manylinux_2_17_i686.manylinux2014_i686.whl (319.6 kB view hashes)

Uploaded CPython 3.12 manylinux: glibc 2.17+ i686

libmav-0.0.6-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (277.4 kB view hashes)

Uploaded CPython 3.12 manylinux: glibc 2.17+ ARM64

libmav-0.0.6-cp312-cp312-macosx_11_0_arm64.whl (190.2 kB view hashes)

Uploaded CPython 3.12 macOS 11.0+ ARM64

libmav-0.0.6-cp312-cp312-macosx_10_15_universal2.whl (403.0 kB view hashes)

Uploaded CPython 3.12 macOS 10.15+ universal2 (ARM64, x86-64)

libmav-0.0.6-cp311-cp311-musllinux_1_1_x86_64.whl (783.2 kB view hashes)

Uploaded CPython 3.11 musllinux: musl 1.1+ x86-64

libmav-0.0.6-cp311-cp311-musllinux_1_1_i686.whl (857.7 kB view hashes)

Uploaded CPython 3.11 musllinux: musl 1.1+ i686

libmav-0.0.6-cp311-cp311-musllinux_1_1_aarch64.whl (755.0 kB view hashes)

Uploaded CPython 3.11 musllinux: musl 1.1+ ARM64

libmav-0.0.6-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (297.9 kB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64

libmav-0.0.6-cp311-cp311-manylinux_2_17_i686.manylinux2014_i686.whl (320.1 kB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ i686

libmav-0.0.6-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (278.5 kB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ ARM64

libmav-0.0.6-cp311-cp311-macosx_11_0_arm64.whl (188.4 kB view hashes)

Uploaded CPython 3.11 macOS 11.0+ ARM64

libmav-0.0.6-cp311-cp311-macosx_10_15_universal2.whl (397.7 kB view hashes)

Uploaded CPython 3.11 macOS 10.15+ universal2 (ARM64, x86-64)

libmav-0.0.6-cp310-cp310-musllinux_1_1_x86_64.whl (783.0 kB view hashes)

Uploaded CPython 3.10 musllinux: musl 1.1+ x86-64

libmav-0.0.6-cp310-cp310-musllinux_1_1_i686.whl (857.7 kB view hashes)

Uploaded CPython 3.10 musllinux: musl 1.1+ i686

libmav-0.0.6-cp310-cp310-musllinux_1_1_aarch64.whl (755.0 kB view hashes)

Uploaded CPython 3.10 musllinux: musl 1.1+ ARM64

libmav-0.0.6-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (297.9 kB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

libmav-0.0.6-cp310-cp310-manylinux_2_17_i686.manylinux2014_i686.whl (320.1 kB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ i686

libmav-0.0.6-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (278.4 kB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ ARM64

libmav-0.0.6-cp310-cp310-macosx_11_0_arm64.whl (188.4 kB view hashes)

Uploaded CPython 3.10 macOS 11.0+ ARM64

libmav-0.0.6-cp310-cp310-macosx_10_15_universal2.whl (397.7 kB view hashes)

Uploaded CPython 3.10 macOS 10.15+ universal2 (ARM64, x86-64)

libmav-0.0.6-cp39-cp39-musllinux_1_1_x86_64.whl (783.3 kB view hashes)

Uploaded CPython 3.9 musllinux: musl 1.1+ x86-64

libmav-0.0.6-cp39-cp39-musllinux_1_1_i686.whl (858.1 kB view hashes)

Uploaded CPython 3.9 musllinux: musl 1.1+ i686

libmav-0.0.6-cp39-cp39-musllinux_1_1_aarch64.whl (755.1 kB view hashes)

Uploaded CPython 3.9 musllinux: musl 1.1+ ARM64

libmav-0.0.6-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (298.4 kB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

libmav-0.0.6-cp39-cp39-manylinux_2_17_i686.manylinux2014_i686.whl (319.8 kB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ i686

libmav-0.0.6-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (277.9 kB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ ARM64

libmav-0.0.6-cp39-cp39-macosx_11_0_arm64.whl (188.6 kB view hashes)

Uploaded CPython 3.9 macOS 11.0+ ARM64

libmav-0.0.6-cp39-cp39-macosx_10_15_universal2.whl (398.0 kB view hashes)

Uploaded CPython 3.9 macOS 10.15+ universal2 (ARM64, x86-64)

libmav-0.0.6-cp38-cp38-musllinux_1_1_x86_64.whl (782.9 kB view hashes)

Uploaded CPython 3.8 musllinux: musl 1.1+ x86-64

libmav-0.0.6-cp38-cp38-musllinux_1_1_i686.whl (856.7 kB view hashes)

Uploaded CPython 3.8 musllinux: musl 1.1+ i686

libmav-0.0.6-cp38-cp38-musllinux_1_1_aarch64.whl (754.7 kB view hashes)

Uploaded CPython 3.8 musllinux: musl 1.1+ ARM64

libmav-0.0.6-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (297.4 kB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64

libmav-0.0.6-cp38-cp38-manylinux_2_17_i686.manylinux2014_i686.whl (319.3 kB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ i686

libmav-0.0.6-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (278.2 kB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ ARM64

libmav-0.0.6-cp38-cp38-macosx_11_0_arm64.whl (188.4 kB view hashes)

Uploaded CPython 3.8 macOS 11.0+ ARM64

libmav-0.0.6-cp38-cp38-macosx_10_15_universal2.whl (397.5 kB view hashes)

Uploaded CPython 3.8 macOS 10.15+ universal2 (ARM64, x86-64)

libmav-0.0.6-cp37-cp37m-musllinux_1_1_x86_64.whl (793.6 kB view hashes)

Uploaded CPython 3.7m musllinux: musl 1.1+ x86-64

libmav-0.0.6-cp37-cp37m-musllinux_1_1_i686.whl (866.2 kB view hashes)

Uploaded CPython 3.7m musllinux: musl 1.1+ i686

libmav-0.0.6-cp37-cp37m-musllinux_1_1_aarch64.whl (764.1 kB view hashes)

Uploaded CPython 3.7m musllinux: musl 1.1+ ARM64

libmav-0.0.6-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (305.2 kB view hashes)

Uploaded CPython 3.7m manylinux: glibc 2.17+ x86-64

libmav-0.0.6-cp37-cp37m-manylinux_2_17_i686.manylinux2014_i686.whl (329.5 kB view hashes)

Uploaded CPython 3.7m manylinux: glibc 2.17+ i686

libmav-0.0.6-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (287.2 kB view hashes)

Uploaded CPython 3.7m manylinux: glibc 2.17+ ARM64

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page