DroneKit-Python Documentation

repository·master·Indexed 23 days ago

https://github.com/dronekit/dronekit-python

A Python library for creating UAV applications that communicate with vehicles via the MAVLink protocol. It provides programmatic access to vehicle telemetry, state, and parameters, enabling mission management, direct flight control, and RC overrides. Designed for use on onboard companion computers or ground station applications, it is highly validated against the ArduPilot UAV Platform and supports Linux, Mac OS X, and Windows.

Tokens
29.7K
Snippets
75
Records
131
Agent score
83%

What's inside DroneKit-Python

  1. Introduction to DroneKit-Python

    master
    DroneKit-Python 2.x is a library used to create applications for Unmanned Aerial Vehicles (UAVs). These applications are designed to run on a UAV's Companion Computer to augment the autopilot. They are particularly useful for tasks that are computationally intensive or require a low-latency link to the autopilot, such as computer vision.
  2. Overview of DroneKit-Python capabilities

    master

    DroneKit-Python is a library used to create applications that communicate with flight controllers (like ArduPilot) via the MAVLink protocol. It is designed for two primary use cases:

    1. Onboard Companion Computers: Running on hardware physically connected to the vehicle via a low-latency link to perform computationally intensive tasks like computer vision, path planning, or 3D modelling.
    2. Ground Station Apps: Communicating with vehicles over higher-latency RF links.

    The API provides programmatic access to telemetry, state, and parameters, allowing for mission management and direct vehicle control.

  3. Overview of DroneKit-Python development environments

    master

    DroneKit-Python is designed for two primary deployment scenarios:

    1. Companion Computers: Running on Linux-based hardware attached to a vehicle, communicating with the autopilot via a serial port.
    2. Ground Stations: Running on Linux, Windows, or macOS, communicating with the vehicle via WiFi or a telemetry radio.

    Development Workflow: During development, the recommended pattern is to run DroneKit-Python on a development computer and connect it to a Simulated Vehicle (SITL) running on the same machine via a UDP connection.

  4. Overview of DroneKit-Python

    master

    DroneKit-Python is a Python implementation of DroneKit that allows developers to create applications for Unmanned Aerial Vehicles (UAVs). It communicates with vehicles using the MAVLink protocol.

    Key capabilities include:

    • Programmatic access to vehicle telemetry, state, and parameter information.
    • Mission management.
    • Direct control over vehicle movement and operations.

    It is designed for use on onboard companion computers (supporting computer vision, path planning, etc.) or for ground station applications communicating via RF-links.

  5. Compatibility and supported platforms

    master

    DroneKit-Python is compatible with vehicles using the MAVLink protocol.

    • Autopilots: While compatible with various MAVLink-based systems, it is most highly validated against the ArduPilot UAV Platform. Other autopilots may exhibit compatibility issues due to different MAVLink specification interpretations.
    • Operating Systems: Runs on Linux, Mac OS X, and Windows.
  6. Differences between DroneKit-SITL and Native SITL builds

    master

    If you build SITL from source (on Linux, Windows, or Mac) instead of using the dronekit-sitl package, note the following differences:

    • MAVProxy: Included and started by default. You can use the MAVProxy terminal to control the autopilot.
    • Connection: You connect via UDP on 127.0.0.1:14550 instead of TCP on 5760.
    • Configuration: You may need to manually disable arming checks or load autotest parameters.
    • Features: It is easier to add virtual rangefinders or virtual gimbals for testing.
  7. Use attribute observers to monitor vehicle state

    master

    The primary mechanism for being notified of changes in vehicle state in DroneKit is through attribute observers. You can register a callback function that is triggered whenever a specific attribute (e.g., location) changes.

    Alternatively, you can use the Vehicle.on_attribute decorator for a more elegant implementation.

    # Registering a listener for the 'location' attribute
    self.vehicle.add_attribute_listener('location', self.location_callback)
    
    # The callback function signature
    def location_callback(self, vehicle, name, location):
        if location.global_relative_frame.alt is not None:
            self.altitude = location.global_relative_frame.alt
    
        self.current_location = location.global_relative_frame
  8. How GUIDED mode works for Copter

    master

    GUIDED mode is the recommended mode for controlling a Copter autonomously without a predefined mission. It allows a Ground Control Station (GCS) or a Companion Computer to control the vehicle "on the fly," enabling real-time reactions to new events or situations.

    Note: This functionality is Copter-specific. While Plane supports GUIDED mode, it is less feature-complete than on Copter, where AUTO mode is typically preferred for autonomous flight.

  9. Access vehicle state and parameters

    master

    In DroneKit, vehicle information is split into two categories:

    1. State Information: Real-time data such as position, speed, and orientation are exposed as Python attributes on the Vehicle class.
    2. Parameters (Settings): Configuration settings and flight modes are accessed through the Vehicle.parameters object using named elements.

    You can interact with these values by reading them directly as attributes or by accessing specific keys within the parameters collection.

  10. Use DroneKit with companion computers

    master

    A companion computer is an onboard device that communicates with the autopilot over a low-latency link to perform computationally intensive or time-sensitive tasks.

    DroneKit is compatible with onboard computers running Linux variants that support:

    1. Python
    2. Installation of Python packages from the Internet.

    Commonly supported platforms include Raspberry Pi, Intel Edison, BeagleBoneBlack, and Odroid.