A professional, event-driven drone control framework.
Project description
DroneBlock
DroneBlock is an enterprise-grade, event-driven Python framework engineered for advanced drone control. It provides a standardized, high-level interface for MAVLink communication designed specifically for PX4 and ArduPilot autonomous systems. DroneBlock abstracts away low-level bitstreams, enabling developers to build complex, reliable flight logic rapidly.
Table of Contents
- Core Features
- System Architecture
- Prerequisites
- Installation
- Quick Start Guide
- Advanced Capabilities
- Testing and Validation
- License
Core Features
- Standardized API: Abstracts complex MAVLink byte protocols into intuitive, asynchronous-friendly Python classes (e.g.,
Takeoff,Goto,Land). - Reactive Safety Architecture: An integrated, priority-based safety manager capable of preempting active missions for deterministic fail-safe execution, such as auto-landing upon critical battery levels.
- Robust Mission Orchestration: Supports flexible mission execution, including synchronous sequence blocking and background threading orchestration.
- Deterministic Telemetry Replay: Features a built-in telemetry
Recorderthat captures high-frequency flight data to JSON. The accompanyingPlayerreconstructs flight conditions offline, ensuring logic verification without requiring physical flight. - Strict Type Safety: Comprehensive PEP 484 type hints are enforced across the entire codebase to maximize developer experience and reliability.
System Architecture
The following diagram illustrates the data and execution pipeline within the DroneBlock framework:
flowchart TD
App[User Application/Script] --> Drone[Drone.execute]
subscript_safety(Safety Layer)
SafetyMgr[Safety Manager] -. Monitors .-> State[Drone State]
SafetyMgr -. Preempts Mission .-> Executor
subgraph Execution Pipeline
Drone --> Executor[Mission Executor]
Executor --> Action[Action Node \n Takeoff/Goto]
end
subgraph Connector Backend
Action --> Factory[Connector Factory]
Factory --> Pylink[Pymavlink]
Factory --> MAVSDK[MAVSDK]
end
Pylink <--> Vehicle[(ArduPilot / PX4)]
MAVSDK <--> Vehicle
Vehicle -- Telemetry --> Mapper[Telemetry Mapper]
Mapper --> State
Mapper --> Recorder[Recorder/Player]
Prerequisites
To safely develop and test your drone logic, a Software-In-The-Loop (SITL) simulator is highly recommended.
- SITL Simulator (Optional): If you do not have hardware connected, install the ArduPilot SITL environment or deploy a pre-configured Docker container to simulate flight dynamics.
- Ground Control Station (Optional): Applications such as QGroundControl or Mission Planner are recommended for visual tracking during simulation.
Once configured, initiate the simulator. The connection port mapping varies based on your specific drone model, network configuration, and simulator software. However, unmodified standard ArduPilot SITL setups typically default to exposing a TCP connection on port 5762 or a UDP broadcast on 14550 for external API control.
# Example command to initialize an ArduPilot Copter SITL instance
sim_vehicle.py -v ArduCopter -f quad --map --console
Installation
You can install DroneBlock directly via pip. This deployment includes the necessary MAVLink drivers.
pip install droneblock
Alternatively, to build the framework from the source repository:
git clone https://github.com/hemhalatha/droneblock.git
cd droneblock
pip install -r requirements.txt
python setup.py install
Quick Start Guide
The following example demonstrates how to connect to a drone, establish safety protocols, and execute an autonomous mission. Create a file named first_flight.py and implement the script below:
import time
from droneblock import Drone, Arm, Takeoff, Goto, Land, Mission
from droneblock.safety.rules import SafetyManager, SafetyRule
def main():
# 1. Establish Hardware/Simulator Connection
drone = Drone.connect("tcp:127.0.0.1:5762")
print("Successfully connected to the vehicle.")
# 2. Configure Autonomous Safety Rules
# Example: Command an immediate landing if the battery percentage falls critically low.
safety = SafetyManager(drone)
safety.add_rule(SafetyRule(
condition=lambda state: 0.0 < state.battery_status.remaining_pct < 15,
action=Land(),
priority=100
))
# 3. Define the Mission Sequence
mission = Mission([
Arm(),
Takeoff(altitude=15.0, timeout=60),
Goto(lat=12.9716, lon=80.0450, alt=20.0, timeout=120),
Land()
])
# 4. Execute the Flight Plan
print("Transitioning to GUIDED mode and executing mission sequence...")
drone.set_mode("GUIDED")
time.sleep(3) # Provide adequate time for mode stabilization
try:
drone.execute(mission)
print("Mission executed successfully.")
except KeyboardInterrupt:
print("Execution aborted by user. Triggering emergency landing protocol.")
drone.execute(Land())
finally:
drone.close()
if __name__ == "__main__":
main()
Run the script from your terminal:
python first_flight.py
Advanced Capabilities
Offline Telemetry Replay
Debugging complex flight behaviors often requires reviewing telemetry data without initiating a live flight. DroneBlock's Deterministic Replay engine handles this seamlessly.
Step 1: Record the Flight Telemetry
from droneblock.replay.recorder import Recorder
recorder = Recorder(drone)
recorder.start() # Initializes background telemetry capture
# Execute your mission logic here...
recorder.stop("flight_trace.json")
Step 2: Execute Offline Playback Recorded traces can be injected back into the DroneBlock event bus. This triggers safety rules and logic controllers identically to a live deployment, allowing for precise incident review.
from droneblock.replay.player import Player
# Replay the flight data at accelerated speeds without an active simulator connection
player = Player("flight_trace.json")
player.play(speedup=5.0)
Connector Architecture
DroneBlock leverages a scalable Factory Pattern to manage multiple backend MAVLink drivers. The framework automatically parses the connection string provided to Drone.connect() and instantiates the appropriate adapter:
tcp:,udp:,serial:-> Pymavlink (Highly optimized production backend)dronekit:-> DroneKit (Hardware compatibility layer)mavsdk:-> MAVSDK (High-throughput, asynchronous backend)
Testing and Validation
DroneBlock strictly adheres to high code quality standards. The codebase maintains a 10.00/10 evaluation score on pylint and is verified by an extensive pytest suite.
To execute the test suite locally:
# Install testing dependencies
pip install pytest
# Execute unit and integration tests
pytest tests/
Note: For more comprehensive implementations combining telemetry mapping, safety managers, and trace logging, please review the
examples/full_sitl_demo.pyscript provided in the source code.
License
This project is licensed under the MIT License. See the LICENSE file for full details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file droneblock-1.0.0.tar.gz.
File metadata
- Download URL: droneblock-1.0.0.tar.gz
- Upload date:
- Size: 28.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0f2978bc34ed4389eb492a620266090b69eab098ff3b3f410084cea74f0daf20
|
|
| MD5 |
fdb0eebcb9a1a693f16d12f72787d8f1
|
|
| BLAKE2b-256 |
2ff52675661564678da4c4152ee55b3e01700eceab6aa56c55870e56d73e0d9e
|
File details
Details for the file droneblock-1.0.0-py3-none-any.whl.
File metadata
- Download URL: droneblock-1.0.0-py3-none-any.whl
- Upload date:
- Size: 30.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5816f33ecac5672ec9b57c68f8c27af71c3792dc2c48245fa477e436bf60e68b
|
|
| MD5 |
92f6d3414dc04191cdbaf82df308c97a
|
|
| BLAKE2b-256 |
a577a5d5aca6f0d50d3abdb090d3227c6b98c376e6ff030565e3a3d7f2ebf3ac
|