DroneKit-Python Documentation
repository·master·Indexed 23 days ago
https://github.com/dronekit/dronekit-pythonA 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.
What's inside DroneKit-Python
- 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.
Overview of DroneKit-Python capabilities
masterDroneKit-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:
- 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.
- 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.
Overview of DroneKit-Python development environments
masterDroneKit-Python is designed for two primary deployment scenarios:
- Companion Computers: Running on Linux-based hardware attached to a vehicle, communicating with the autopilot via a serial port.
- 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.
Overview of DroneKit-Python
masterDroneKit-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.
License information for DroneKit-Python
masterDroneKit-Python is licensed under the Apache License Version 2.0, January 2004. You can find the full license text in theLICENSEfile within the source repository.Use asynchronous movement commands correctly
masterCommands likeVehicle.simple_goto()andVehicle.simple_takeoff()are asynchronous. If a new command is sent before the previous one is completed, the previous command will be interrupted. Always block the calling code or check for completion before issuing the next movement command.Compatibility and supported platforms
masterDroneKit-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.
Differences between DroneKit-SITL and Native SITL builds
masterIf you build SITL from source (on Linux, Windows, or Mac) instead of using the
dronekit-sitlpackage, 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:14550instead of TCP on5760. - 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.
Use attribute observers to monitor vehicle state
masterThe 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_attributedecorator 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_frameHow GUIDED mode works for Copter
masterGUIDED 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.
Access vehicle state and parameters
masterIn DroneKit, vehicle information is split into two categories:
- State Information: Real-time data such as position, speed, and orientation are exposed as Python attributes on the
Vehicleclass. - Parameters (Settings): Configuration settings and flight modes are accessed through the
Vehicle.parametersobject using named elements.
You can interact with these values by reading them directly as attributes or by accessing specific keys within the
parameterscollection.- State Information: Real-time data such as position, speed, and orientation are exposed as Python attributes on the
Use DroneKit with companion computers
masterA 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:
- Python
- Installation of Python packages from the Internet.
Commonly supported platforms include Raspberry Pi, Intel Edison, BeagleBoneBlack, and Odroid.