Top Related Projects
PX4 Autopilot Software
MAVLink to ROS gateway with proxy for Ground Control Station
Quick Overview
DroneKit-Python is an open-source Python library that allows developers to create powerful drone applications. It provides a high-level API for communication with vehicles over MAVLink, enabling the creation of apps that can control and monitor drones, both on-board companion computers and ground station apps.
Pros
- Easy to use and well-documented API for drone control and monitoring
- Supports both on-board companion computers and ground station applications
- Compatible with a wide range of vehicles using the MAVLink protocol
- Active community and ongoing development
Cons
- Limited to MAVLink-based vehicles, not compatible with all drone types
- Requires some knowledge of drone systems and protocols
- May have performance limitations for high-frequency control loops
- Dependent on the underlying MAVLink implementation
Code Examples
- Connecting to a vehicle:
from dronekit import connect
# Connect to the Vehicle (in this case a simulator running on the same computer)
vehicle = connect('tcp:127.0.0.1:5760', wait_ready=True)
# Get some vehicle attributes (state)
print(f"GPS: {vehicle.gps_0}")
print(f"Battery: {vehicle.battery}")
print(f"Last Heartbeat: {vehicle.last_heartbeat}")
print(f"Is Armable?: {vehicle.is_armable}")
print(f"System status: {vehicle.system_status.state}")
print(f"Mode: {vehicle.mode.name}")
# Close vehicle object before exiting script
vehicle.close()
- Arming and taking off:
from dronekit import connect, VehicleMode
import time
vehicle = connect('tcp:127.0.0.1:5760', wait_ready=True)
def arm_and_takeoff(aTargetAltitude):
print("Basic pre-arm checks")
while not vehicle.is_armable:
print(" Waiting for vehicle to initialise...")
time.sleep(1)
print("Arming motors")
vehicle.mode = VehicleMode("GUIDED")
vehicle.armed = True
while not vehicle.armed:
print(" Waiting for arming...")
time.sleep(1)
print("Taking off!")
vehicle.simple_takeoff(aTargetAltitude)
while True:
print(f" Altitude: {vehicle.location.global_relative_frame.alt}")
if vehicle.location.global_relative_frame.alt >= aTargetAltitude * 0.95:
print("Reached target altitude")
break
time.sleep(1)
arm_and_takeoff(10)
- Setting a simple mission:
from dronekit import connect, Command, LocationGlobal
from pymavlink import mavutil
vehicle = connect('tcp:127.0.0.1:5760', wait_ready=True)
cmds = vehicle.commands
cmds.clear()
# Define waypoints
waypoint1 = LocationGlobal(-35.361354, 149.165218, 20)
waypoint2 = LocationGlobal(-35.363244, 149.168801, 20)
# Add takeoff command
cmds.add(Command(0, 0, 0, mavutil.mavlink.MAV_FRAME_GLOBAL_RELATIVE_ALT, mavutil.mavlink.MAV_CMD_NAV_TAKEOFF, 0, 0, 0, 0, 0, 0, 0, 0, 10))
# Add waypoint commands
cmds.add(Command(0, 0, 0, mavutil.mavlink.MAV_FRAME_GLOBAL_RELATIVE_ALT, mavutil.mavlink.MAV_CMD_NAV_WAYPOINT, 0, 0, 0, 0, 0, 0, waypoint1.lat, waypoint1.lon, waypoint1.alt))
cmds.add(Command(0, 0, 0, mavutil.mavlink.MAV_FRAME_GLOBAL_RELATIVE_ALT, mavutil.mavlink.MAV_CMD_NAV_WAYPOINT,
Competitor Comparisons
PX4 Autopilot Software
Pros of PX4-Autopilot
- More comprehensive flight control system with support for various vehicle types
- Active development and larger community support
- Integrated simulation environment for testing
Cons of PX4-Autopilot
- Steeper learning curve due to complexity
- Requires more hardware resources to run
Code Comparison
DroneKit-Python example:
from dronekit import connect, VehicleMode
vehicle = connect('udp:127.0.0.1:14550', wait_ready=True)
vehicle.mode = VehicleMode("GUIDED")
vehicle.armed = True
PX4-Autopilot example (using MAVSDK-Python):
from mavsdk import System
import asyncio
async def run():
drone = System()
await drone.connect(system_address="udp://:14540")
await drone.action.arm()
await drone.action.set_takeoff_altitude(10.0)
await drone.action.takeoff()
asyncio.run(run())
Both repositories provide tools for drone control, but PX4-Autopilot offers a more comprehensive solution with wider vehicle support and an integrated simulation environment. However, it comes with a steeper learning curve and higher resource requirements. DroneKit-Python is simpler to use but has more limited functionality and vehicle support.
MAVLink to ROS gateway with proxy for Ground Control Station
Pros of MAVROS
- More comprehensive and lower-level access to MAVLink protocol
- Better integration with ROS ecosystem
- Supports a wider range of flight controllers and vehicles
Cons of MAVROS
- Steeper learning curve due to complexity
- Requires ROS knowledge and setup
- Less abstraction, which can lead to more verbose code
Code Comparison
MAVROS example (C++):
#include <ros/ros.h>
#include <mavros_msgs/CommandBool.h>
#include <mavros_msgs/SetMode.h>
#include <mavros_msgs/State.h>
// ... (additional setup code)
mavros_msgs::CommandBool arm_cmd;
arm_cmd.request.value = true;
arming_client.call(arm_cmd);
DroneKit-Python example:
from dronekit import connect, VehicleMode
vehicle = connect('udp:127.0.0.1:14550', wait_ready=True)
vehicle.mode = VehicleMode("GUIDED")
vehicle.armed = True
MAVROS provides more granular control but requires more setup, while DroneKit-Python offers a higher-level abstraction for easier development. MAVROS is better suited for complex robotic systems integrated with ROS, while DroneKit-Python is ideal for quick prototyping and simpler drone applications.
Convert
designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
DroneKit Python
DroneKit-Python helps you create powerful apps for UAVs.
â ï¸ ATTENTION: MAINTAINERS NEEDED â ï¸
Hey it's true this project is not very active, but it could be with your help. We are looking for maintainers interested in keeping the project alive by keep up with CI and PRs. If you are interested in helping please apply by creating an issue and listing the reasons why you would like to help, in return we will be granting committer access to folks who are truly interested in helping.
Overview
DroneKit-Python (formerly DroneAPI-Python) contains the python language implementation of DroneKit.
The API allows developers to create Python apps that communicate with vehicles over MAVLink. It provides programmatic access to a connected vehicle's telemetry, state and parameter information, and enables both mission management and direct control over vehicle movement and operations.
The API is primarily intended for use in onboard companion computers (to support advanced use cases including computer vision, path planning, 3D modelling etc). It can also be used for ground station apps, communicating with vehicles over a higher latency RF-link.
Getting Started
The Quick Start guide explains how to set up DroneKit on each of the supported platforms (Linux, Mac OSX, Windows) and how to write a script to connect to a vehicle (real or simulated).
A basic script looks like this:
from dronekit import connect
# Connect to UDP endpoint.
vehicle = connect('127.0.0.1:14550', wait_ready=True)
# Use returned Vehicle object to query device state - e.g. to get the mode:
print("Mode: %s" % vehicle.mode.name)
Once you've got DroneKit set up, the guide explains how to perform operations like taking off and flying the vehicle. You can also try out most of the tasks by running the examples.
Resources
The project documentation is available at https://readthedocs.org/projects/dronekit-python/. This includes guide, example and API Reference material.
The example source code is hosted here on Github as sub-folders of /dronekit-python/examples.
The DroneKit Forums are the best place to ask for technical support on how to use the library. You can also check out our Gitter channel though we prefer posts on the forums where possible.
- Documentation: https://dronekit-python.readthedocs.io/en/latest/about/index.html
- Guides: [https://dronekit-python.readthedocs.io/en/latest/guide/index.html)
- API Reference: [https://dronekit-python.readthedocs.io/en/latest/automodule.html)
- Examples: /dronekit-python/examples
- Forums: http://discuss.dronekit.io/
- Gitter: https://gitter.im/dronekit/dronekit-python though we prefer posts on the forums where possible.
Users and contributors wanted!
We'd love your feedback and suggestions about this API and are eager to evolve it to meet your needs, please feel free to create an issue to report bugs or feature requests.
If you've created some awesome software that uses this project, let us know on the forums here!
If you want to contribute, see our Contributing guidelines, we welcome all types of contributions but mostly contributions that would help us shrink our issues list.
Licence
DroneKit-Python is made available under the permissive open source Apache 2.0 License.
Copyright 2015 3D Robotics, Inc.
Top Related Projects
PX4 Autopilot Software
MAVLink to ROS gateway with proxy for Ground Control Station
Convert
designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot