AirHub raises €4.4M from Keen Venture Partners to scale drone operations software
Back to Tutorials
techTutorialintermediate

AirHub raises €4.4M from Keen Venture Partners to scale drone operations software

April 7, 202614 views4 min read

Learn to build a drone operations management system using Python and DroneKit, simulating core functionality that companies like AirHub use to manage drone fleets.

Introduction

In this tutorial, you'll learn how to build a basic drone operations management system using Python and the DroneKit library. This system will simulate core functionality that companies like AirHub use to manage drone fleets, including flight planning, status monitoring, and command execution. We'll create a simplified version that demonstrates the fundamental concepts behind commercial drone operations software.

Prerequisites

To follow this tutorial, you'll need:

  • Python 3.7 or higher installed on your system
  • Basic understanding of Python programming concepts
  • DroneKit library (a Python API for controlling drones)
  • Access to a simulated drone environment or actual drone hardware

Why these prerequisites? DroneKit is essential because it provides the interface to communicate with drones, while Python gives us the flexibility to build custom management systems. Having a simulated environment allows us to test without risking actual hardware.

Step-by-Step Instructions

1. Set Up Your Development Environment

First, create a new directory for our project and set up a virtual environment:

mkdir drone_operations_system
 cd drone_operations_system
python -m venv drone_env
source drone_env/bin/activate  # On Windows: drone_env\Scripts\activate

Why? Using a virtual environment isolates our project dependencies and prevents conflicts with other Python projects on your system.

2. Install Required Libraries

Install DroneKit and other necessary libraries:

pip install dronekit
pip install dronekit-sitl

Why? DroneKit is our main library for communicating with drones. DroneKit-SITL (Software In The Loop) provides a simulated drone environment for testing without hardware.

3. Create a Basic Drone Connection Script

Create a file called drone_connection.py:

from dronekit import connect, VehicleMode
import time

def connect_to_drone(connection_string):
    print(f"Connecting to vehicle on: {connection_string}")
    vehicle = connect(connection_string, wait_ready=True)
    return vehicle

if __name__ == "__main__":
    # For simulation, use SITL
    vehicle = connect_to_drone("127.0.0.1:14550")
    print(f"Vehicle is armed: {vehicle.armed}")
    print(f"Vehicle mode: {vehicle.mode.name}")
    vehicle.close()

Why? This script establishes a connection to a drone and retrieves basic information. In a real system, this would be the foundation for all drone communication.

4. Implement Flight Planning Functionality

Create a file called flight_planner.py:

from dronekit import LocationGlobalRelative
from dronekit import connect
import time

class FlightPlanner:
    def __init__(self, vehicle):
        self.vehicle = vehicle

    def arm_and_takeoff(self, altitude):
        print("Basic pre-arm checks")
        while not self.vehicle.is_armable:
            print("Waiting for vehicle to initialise...")
            time.sleep(1)

        print("Setting mode to GUIDED")
        self.vehicle.mode = VehicleMode("GUIDED")
        time.sleep(1)

        print("Arming motors")
        self.vehicle.armed = True
        while not self.vehicle.armed:
            print("Waiting for arming...")
            time.sleep(1)

        print("Taking off!")
        self.vehicle.simple_takeoff(altitude)

        while True:
            print(f"Altitude: {self.vehicle.location.global_relative_frame.alt}")
            if self.vehicle.location.global_relative_frame.alt >= altitude * 0.95:
                print("Reached target altitude")
                break
            time.sleep(1)

    def goto_location(self, lat, lon, alt):
        target_location = LocationGlobalRelative(lat, lon, alt)
        self.vehicle.simple_goto(target_location)
        print(f"Going to location: {target_location}")

Why? This class encapsulates core flight planning functions. The arm_and_takeoff method handles the necessary pre-flight checks and takeoff sequence, while goto_location allows us to navigate to specific coordinates.

5. Build a Drone Status Monitoring System

Create a file called status_monitor.py:

import time
from dronekit import connect


class StatusMonitor:
    def __init__(self, vehicle):
        self.vehicle = vehicle

    def get_drone_status(self):
        status = {
            'armed': self.vehicle.armed,
            'mode': self.vehicle.mode.name,
            'battery': self.vehicle.battery.voltage,
            'altitude': self.vehicle.location.global_relative_frame.alt,
            'latitude': self.vehicle.location.global_relative_frame.lat,
            'longitude': self.vehicle.location.global_relative_frame.lon,
            'groundspeed': self.vehicle.groundspeed,
            'airspeed': self.vehicle.airspeed
        }
        return status

    def print_status(self):
        status = self.get_drone_status()
        print("\n=== DRONE STATUS ===")
        for key, value in status.items():
            print(f"{key}: {value}")
        print("===================\n")

    def monitor_loop(self, interval=2):
        while True:
            self.print_status()
            time.sleep(interval)

Why? Monitoring drone status is crucial for fleet management. This system continuously tracks and reports key metrics that operators need to make informed decisions.

6. Create a Main Management Script

Create a file called main_system.py:

from drone_connection import connect_to_drone
from flight_planner import FlightPlanner
from status_monitor import StatusMonitor
import time


def main():
    # Connect to drone
    vehicle = connect_to_drone("127.0.0.1:14550")
    
    # Initialize components
    planner = FlightPlanner(vehicle)
    monitor = StatusMonitor(vehicle)
    
    # Arm and takeoff
    planner.arm_and_takeoff(10)
    
    # Monitor status
    print("Monitoring drone status...")
    monitor.monitor_loop(5)
    
    # Navigate to a location
    planner.goto_location(51.5074, -0.1278, 15)  # London coordinates
    
    # Close connection
    vehicle.close()
    print("Connection closed")

if __name__ == "__main__":
    main()

Why? This main script ties together all our components into a cohesive system. It demonstrates how different modules work together to manage a drone operation.

7. Run the Simulation

First, start a simulated drone environment:

dronekit-sitl copter-3.3 --home=51.5074,-0.1278,0,0

Then run your main system:

python main_system.py

Why? The SITL environment provides a realistic simulation of drone behavior, allowing you to test your system without physical hardware.

Summary

In this tutorial, we've built a foundational drone operations management system using Python and DroneKit. We've covered connecting to drones, flight planning, and status monitoring - core components that companies like AirHub use to scale their drone operations. While this is a simplified version, it demonstrates the fundamental concepts behind commercial drone management software. You've learned how to:

  • Establish drone connections using DroneKit
  • Implement basic flight operations like takeoff and navigation
  • Monitor drone status and telemetry data
  • Structure a drone management system using object-oriented programming

This system can be extended with additional features like mission planning, geofencing, real-time communication, and fleet management capabilities that commercial systems implement at scale.

Source: TNW Neural

Related Articles