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 mrtautopilot

Usage

Example usage:

#!/usr/bin/env python3

import logging
import selectors

import mrtautopilot

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


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

    proto = autopilot_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 == 6:
                m = mrtautopilot.mission
                mavlink.send_mission(
                    m.Mission(
                        fault_config=m.FaultConfig(
                            fault_responses={},
                            loiter_radius_m=30,
                            loiter_duration_s=365 * 24 * 60 * 60,
                            response_speed_mps=3,
                        ),
                        rally_points=[],
                        fence=[],
                        mission_items=[
                            m.Waypoint(lat_deg=38.31, lon_deg=-77.02, speed_mps=6),
                            m.Waypoint(lat_deg=38.31, lon_deg=-77.00, speed_mps=6),
                            m.Waypoint(lat_deg=38.34, lon_deg=-77.00, speed_mps=7),
                            m.DriftLoiter(
                                lat_deg=38.34, lon_deg=-77.00, speed_mps=3, radius_m=50
                            ),
                        ],
                    )
                )

            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 | %(threadName)s | %(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-10.tar.gz (15.5 kB view details)

Uploaded Source

Built Distribution

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

mrtautopilot-10-py3-none-any.whl (13.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: mrtautopilot-10.tar.gz
  • Upload date:
  • Size: 15.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for mrtautopilot-10.tar.gz
Algorithm Hash digest
SHA256 07423be5e353960155f2ee83019d183d9fb16ec83843fe0eb47d07d1c181585b
MD5 316d00d713e8d2e57fb8073bd22e221c
BLAKE2b-256 ca55015db147188354b9aae8033920493b0a5ddf8353384dbd720daaa9628ec9

See more details on using hashes here.

Provenance

The following attestation bundles were made for mrtautopilot-10.tar.gz:

Publisher: pypi.yml on magothy/mrtautopilot-py3

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

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

File metadata

  • Download URL: mrtautopilot-10-py3-none-any.whl
  • Upload date:
  • Size: 13.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for mrtautopilot-10-py3-none-any.whl
Algorithm Hash digest
SHA256 428389be3bb8bf2a67680ebe2af8a2358adc57bd21621a779608c86ebb402dca
MD5 8aec18964e340b16d068115952f69956
BLAKE2b-256 a3ed859949ec8ec2257871241dd6a59830e6e05f520f13407821eb12a447d625

See more details on using hashes here.

Provenance

The following attestation bundles were made for mrtautopilot-10-py3-none-any.whl:

Publisher: pypi.yml on magothy/mrtautopilot-py3

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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