Skip to main content

Communicate with the MRT Autopilot Mavlink API

Project description

MRT Autopilot Python3 API

This repository contains the Python3 API for the MRT Autopilot.

Installation

pip3 install git+https://github.com/magothy/mrtautopilot-py3@v5

Usage

Example usage:

#!/usr/bin/env python3

import logging
import selectors

import mrtautopilot

# example for send_protobuf_proxy
from mrtproto import Magothy_pb2
PROTO_ID = 0x5433  # defined by protocol


def main():
    mavlink = mrtautopilot.MavlinkThread()

    proto = Magothy_pb2.VehicleData()
    proto.position.latitude_deg = 38.3
    proto.position.longitude_deg = -77.1

    def got_low_bandwidth():
        d: mrtautopilot.LowBandwidth = mavlink.low_bandwidth_queue.get_nowait()
        logging.info(f"Got Vehicle Data: {d.latitude_deg}, {d.longitude_deg}")

    try:
        sel = selectors.DefaultSelector()
        sel.register(
            mavlink.low_bandwidth_queue_fileobj,
            selectors.EVENT_READ,
            got_low_bandwidth,
        )

        count = 0
        mavlink.start()
        while True:
            mavlink.send_heartbeat()

            count += 1

            if count == 5:
                mavlink.send_protobuf_proxy(PROTO_ID, proto.SerializeToString())

            if count == 10:
                mavlink.set_motor_enablement(True)
                mavlink.send_waypoint(38.3, -77.1, 3.0)

            if count == 20:
                mavlink.set_motor_enablement(False)
                mavlink.send_autopilot_stop()

            for key, mask in sel.select():
                key.data()

    finally:
        mavlink.stop()


def setup_logging():
    logging.basicConfig(
        format="%(asctime)s.%(msecs)03d | %(levelname)8s | %(message)s",
        datefmt="%Y-%m-%d %H:%M:%S",
    )
    logger = logging.getLogger()
    logger.setLevel(logging.INFO)


if __name__ == "__main__":
    setup_logging()
    try:
        main()
    except KeyboardInterrupt:
        pass

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

mrtautopilot-5.tar.gz (6.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mrtautopilot-5-py3-none-any.whl (6.4 kB view details)

Uploaded Python 3

File details

Details for the file mrtautopilot-5.tar.gz.

File metadata

  • Download URL: mrtautopilot-5.tar.gz
  • Upload date:
  • Size: 6.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.0 CPython/3.12.5

File hashes

Hashes for mrtautopilot-5.tar.gz
Algorithm Hash digest
SHA256 54580f514da35d4bc9937748b4d6c880f0161d0c01debb35b05180ebbf3f19f1
MD5 80cc850814fbe41f7ddf4ad2ad268ad2
BLAKE2b-256 c7dbd281afc6ffe0812e775123c76af1973c54d5c7c348d3f394914a7691518a

See more details on using hashes here.

File details

Details for the file mrtautopilot-5-py3-none-any.whl.

File metadata

  • Download URL: mrtautopilot-5-py3-none-any.whl
  • Upload date:
  • Size: 6.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.0 CPython/3.12.5

File hashes

Hashes for mrtautopilot-5-py3-none-any.whl
Algorithm Hash digest
SHA256 c42d3be1aed3d429d21c75bb3df600dfdf862270d8b882a303426b6e1c841567
MD5 74c3239fc3897b384ca20268ca467508
BLAKE2b-256 9b3aa08745af1bcd4fb2d8d3c0d17226c275e96dab69ad0a0db8d70df278e8a3

See more details on using hashes here.

Supported by

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