Technical Details

This page provides comprehensive technical documentation of all algorithms, mathematical formulations, and implementation details for the drone cooperative system. Each section includes equations, pseudocode, performance metrics, and design rationale.

System Architecture Diagram

1. AR Drone (Helper/Scout) System

The AR Drone serves as a high-altitude scout, performing grid-based search patterns to locate ArUco markers and computing world-frame transforms for target localization.

AR Drone Navigation Pipeline

1.1 ArUco Marker Detection

Overview

ArUco markers are fiducial markers used for precise pose estimation and localization. The system detects markers in video frames using OpenCV and estimates the drone's position relative to them with ±2cm accuracy at 1m distance.

Detection Algorithm

Dictionary: DICT_4X4_50 (50 unique 4×4 markers)

Process:

  1. Convert frame to grayscale: $I_{gray} = \text{RGB2Gray}(I)$
  2. Adaptive thresholding with block size 11
  3. Contour detection and square filtering
  4. Perspective transform to canonical view
  5. Binary pattern decoding and validation

Pose Estimation (PnP)

Given 4 corner points in image space and known marker size $L$ (15cm), solve the Perspective-n-Point problem:

$$ \begin{bmatrix} R & t \\ 0 & 1 \end{bmatrix} = \text{solvePnP}(M, P, K, D) $$

Where:

  • $R \in SO(3)$ is the 3×3 rotation matrix
  • $t \in \mathbb{R}^3$ is the translation vector
  • $M$ = 3D marker corners in marker frame
  • $P$ = 2D corner points in image (pixels)
  • $K$ = camera intrinsic matrix
  • $D$ = distortion coefficients

Camera Intrinsic Matrix

For AR Drone camera (640×480):

$$ K = \begin{bmatrix} 700 & 0 & 320 \\ 0 & 700 & 240 \\ 0 & 0 & 1 \end{bmatrix} $$

Distance to Marker

$$ d = \|t\| = \sqrt{t_x^2 + t_y^2 + t_z^2} $$

Performance

Distance Position Error Angle Error Detection Rate
0.5m±1cm±1°30 FPS
1.0m±2cm±2°30 FPS
2.0m±5cm±3°28 FPS
3.0m±10cm±5°25 FPS

Implementation: See AR Drone/aruco_detection/detector.py

1.3 Transform Computation (Body Frame → World Frame)

Overview

Computes world-frame position by integrating body-frame velocities over time, using IMU yaw data to rotate velocities into the world frame.

Coordinate Frames

  • Body Frame: Forward (+x), Right (+y), Down (+z) relative to drone
  • World Frame: North (+x), East (+y), Down (+z) relative to origin

Transform Equations

For each time step $\Delta t$ with velocity command $(v_x, v_y)$ and yaw $\psi$:

$$ \begin{align} x' &= x + v_x \cdot \cos(\psi) \cdot \Delta t - v_y \cdot \sin(\psi) \cdot \Delta t \\ y' &= y + v_x \cdot \sin(\psi) \cdot \Delta t + v_y \cdot \cos(\psi) \cdot \Delta t \end{align} $$

Example Transform Calculation

Measured data from actual flight:

  • $\Delta x = 1.251$ m (right +, left −)
  • $\Delta y = 4.018$ m (forward +, back −)
  • $\Delta\psi = -0.08°$ (yaw drift)
Transform Computation Logs
Figure: System logs showing velocity integration and position estimation

Error Analysis

Position error accumulates as:

$$ \sigma_{pos} \approx \sqrt{n} \cdot \sigma_{cmd} + D \cdot \sin(\sigma_\psi) $$

Where $n$ is number of movements, $D$ is total distance, and $\sigma$ terms are individual errors.

Typical Accuracy: ±10cm after 3m flight with 6 movements

1.4 Optical Centering (Proportional Control)

Overview

Pixel-based proportional control system that centers the drone above an ArUco marker by aligning the marker's center with the image center.

Control Algorithm

  1. Detect ArUco marker in frame
  2. Calculate marker center: $c_{tag} = (x_{tag}, y_{tag})$
  3. Calculate image center: $c_{img} = (w/2, h/2)$
  4. Compute error: $e = c_{tag} - c_{img}$
  5. Apply proportional control: $u = K_p \cdot e$

Control Law

$$ \begin{align} e_x &= x_{tag} - \frac{w}{2} \\ e_y &= y_{tag} - \frac{h}{2} \\ u_x &= K_p \cdot e_x \\ u_y &= K_p \cdot e_y \end{align} $$

Where $K_p = 0.3$ (tuned proportional gain).

Demonstration Video

Optical centering demonstration showing proportional control convergence
Optical Centering Diagram
Figure: Optical centering algorithm visualization

1.5 IMU Positional Centering

Overview

Uses instantaneous velocity measurements and IMU integration to maintain centered position above marker, compensating for wind and drift.

Velocity Integration

$$ \begin{align} \Delta d &= v \cdot \Delta t \\ x' &= x + \sum \Delta d_x \\ y' &= y + \sum \Delta d_y \end{align} $$

Proportional Correction

After disturbances (wind, takeoff drift), apply correction:

$$ u_{correct} = K_p \cdot (x_{target} - x_{current}) $$

Performance: ±5cm accuracy with disturbance rejection

2. Tello Drone (Parent/Payload) System

The Tello Drone executes low-altitude navigation with real-time obstacle detection, distance estimation, reactive avoidance, and precision landing control.

Tello Navigation Pipeline

2.1 YOLOv8 Object Detection Pipeline

Overview

YOLOv8 (You Only Look Once v8) performs real-time object detection, identifying and localizing 80+ object classes in a single forward pass through a convolutional neural network.

Model Specifications

  • Variant: YOLOv8-nano
  • Parameters: 3.2 million (6MB file size)
  • Performance: 10-15 FPS on Tello
  • Accuracy: 89.7% mAP on COCO dataset
  • Classes: 80 object categories (person, chair, bottle, etc.)

Network Architecture

Input (320×240) → Backbone (CSPDarknet) → Neck (PANet) → Head → Detections

Detection Output

Each detection $d_i$ contains:

$$ d_i = (\text{bbox}, \text{class}, \text{confidence}) $$

Where:

  • $\text{bbox} = (x_1, y_1, x_2, y_2)$ are bounding box coordinates
  • $\text{class} \in \{\text{person}, \text{chair}, \text{bottle}, \ldots\}$
  • $\text{confidence} \in [0, 1]$ is detection confidence

Detection Filtering

Filter detections by confidence threshold $\theta = 0.5$:

$$ D_{filtered} = \{d \in D \mid \text{confidence}(d) \geq 0.5\} $$

Implementation

# YOLOv8 Detection
results = model(frame, conf=0.5, verbose=False)

for box in results[0].boxes:
    x1, y1, x2, y2 = box.xyxy[0].cpu().numpy()
    confidence = float(box.conf[0])
    class_id = int(box.cls[0])
    class_name = model.names[class_id]

Code: See Tello/obstacle_avoidance/obstacle_detector.py

2.2 Pinhole Camera Distance Estimation

Overview

Estimates distance to detected objects using the pinhole camera model and known object dimensions, providing monocular depth estimation without requiring a depth sensor.

Pinhole Camera Equation

$$ d = \frac{H \times f}{h} $$

Where:

  • $d$ = distance to object (meters)
  • $H$ = known real-world height of object (meters)
  • $f$ = focal length of camera (700 pixels, calibrated)
  • $h$ = pixel height of object in image

Derivation (Similar Triangles)

Real World              Image Plane
    ↓                         ↓
|----H----|              |--h--|
|         |              |     |
|  Object |      →      Camera
|         |              |     |
|---------|              |-----|
    ↑                         ↑
Distance d            Focal length f

Similar triangles: H/d = h/f
Solving for d: d = (H × f) / h

Object Height Database

Object ClassHeight (m)
person1.7
chair0.9
bottle0.25
cup0.12
laptop0.02
tv0.6

Focal Length Calibration

Empirical calibration process:

$$ f = \frac{h \times d}{H} $$

Example: Place person (H = 1.7m) at d = 2.0m, measure h = 150 pixels:

$$ f = \frac{150 \times 2.0}{1.7} \approx 176.5 \text{ pixels} $$

Configured value: f = 700 pixels (empirically tuned for Tello camera)

Error Analysis

Relative error scales with pixel measurement error:

$$ \epsilon = \frac{\Delta d}{d} = \frac{\Delta h}{h} $$
DistancePixel HeightError (±2px)
0.5m600px0.7%
1.0m300px1.3%
2.0m150px2.7%
5.0m60px6.7%
10.0m30px13.3%

Typical Accuracy: ±20% at 5m distance

2.3 Threat Assessment Algorithm

Overview

Classifies detected obstacles into threat levels (HIGH, MEDIUM, LOW) based on distance and position relative to the drone's flight path.

Position Classification

Bounding box center $x_c = (x_1 + x_2) / 2$ determines position:

$$ \text{position} = \begin{cases} \text{LEFT} & \text{if } x_c < W/3 \\ \text{CENTER} & \text{if } W/3 \leq x_c \leq 2W/3 \\ \text{RIGHT} & \text{if } x_c > 2W/3 \end{cases} $$

Where $W = 320$ pixels (image width).

Threat Level Determination

For CENTER obstacles (direct collision path):

$$ \text{threat} = \begin{cases} \text{HIGH} & \text{if } d < 1.5\text{m} \\ \text{MEDIUM} & \text{if } 1.5\text{m} \leq d < 2.5\text{m} \\ \text{LOW} & \text{if } d \geq 2.5\text{m} \end{cases} $$

For LEFT/RIGHT obstacles:

$$ \text{threat} = \begin{cases} \text{MEDIUM} & \text{if } d < 1.05\text{m} \\ \text{LOW} & \text{if } d \geq 1.05\text{m} \end{cases} $$

Note: Side threshold is 70% of center HIGH threshold (1.05m = 0.7 × 1.5m)

Threat Decision Matrix

Position< 1.05m1.05-1.5m1.5-2.5m> 2.5m
CENTERHIGHHIGHMEDIUMLOW
LEFTMEDIUMLOWLOWLOW
RIGHTMEDIUMLOWLOWLOW

Response Actions

  • HIGH threat: Emergency stop + vertical/lateral dodge
  • MEDIUM threat: Slow approach + prepare avoidance
  • LOW threat: Continue with monitoring

2.4 Obstacle Avoidance Maneuvers

Overview

Reactive obstacle avoidance using pre-planned dodge maneuvers that ensure the drone returns to its original path after avoiding an obstacle. Key property: Net displacement = 0 (path preservation).

Lateral Dodge Maneuver

Three-step balanced maneuver:

  1. Move sideways: $y_1 = y_0 + D_{lateral}$ (80cm)
  2. Move forward: $x_2 = x_0 + d + w/2 + m$ (pass obstacle)
  3. Move back sideways: $y_3 = y_0$ (return to path)

Net displacement: $\Delta y = y_3 - y_0 = 0$ ✓

$$ \begin{align} D_{lateral} &= 80\text{cm} \\ d_{pass} &= d + \frac{w}{2} + m \\ m &= 50\text{cm (clearance margin)} \end{align} $$

Vertical Dodge Maneuver

For wide obstacles (w > threshold):

  1. Move up: $z_1 = z_0 + D_{vertical}$ (60cm)
  2. Move forward: $x_2 = x_0 + d + w/2 + m$
  3. Move down: $z_3 = z_0$ (return to altitude)

Net displacement: $\Delta z = z_3 - z_0 = 0$ ✓

Maneuver Diagram

                Obstacle
                   🚧
                   │
START ────────┐    │    ┌─────────> GOAL
   (x₀,y₀)    │    │    │
              │    │    │
          1.  ↓    │    ↑  3.
         (lateral) │ (lateral)
                   │
              ────→│────→
                2. forward
                 (pass)

Benefits

  • Mathematically balanced: Returns to exact original path
  • Endpoint preservation: Final position unaffected by detours
  • Predictable: Deterministic maneuver sequence
  • Safe: 50cm clearance margin

Trade-offs

  • ⚠️ Increases flight time by 10-20%
  • ⚠️ Battery cost ~5-10% per maneuver
  • ✓ Guarantees target accuracy (critical for landing)

Code: See Tello/obstacle_avoidance/circumvent.py

2.5 PID Controller (Position Control)

Overview

PID (Proportional-Integral-Derivative) controller for precise position control and landing, using feedback from position estimation to minimize error and achieve ±10cm accuracy.

PID Control Law

$$ u(t) = K_p \cdot e(t) + K_i \cdot \int e(\tau) d\tau + K_d \cdot \frac{de(t)}{dt} $$

Where:

  • $e(t) = \text{target} - \text{current}$ is the error
  • $K_p$ = proportional gain (immediate response)
  • $K_i$ = integral gain (eliminates steady-state error)
  • $K_d$ = derivative gain (dampens oscillations)

Discrete-Time Implementation

At time step $k$ with sampling period $\Delta t$:

$$ \begin{align} e[k] &= \text{target} - \text{current}[k] \\ P[k] &= K_p \times e[k] \\ I[k] &= I[k-1] + K_i \times e[k] \times \Delta t \\ D[k] &= K_d \times \frac{e[k] - e[k-1]}{\Delta t} \\ u[k] &= P[k] + I[k] + D[k] \end{align} $$

Anti-Windup (Integral Clamping)

Prevent integral term from growing unbounded:

$$ I[k] = \text{clamp}(I[k], -I_{max}, I_{max}) $$

Where $I_{max} = 50$cm.

Deadband

Prevent oscillation near target:

$$ \text{if } |e[k]| < \epsilon_{deadband}: \quad e[k] = 0, \quad I[k] = 0 $$

Where $\epsilon_{deadband} = 10$cm for position, 5° for yaw.

Tuned PID Gains

AxisKpKiKdPerformance
X, Y, Z1.00.10.3±10cm, 2-3 iterations
Yaw0.50.050.1±5°, 1-2 iterations

Example Correction Sequence

Target: (200cm, 100cm, 120cm, 45°)

Iteration 1: Position (185, 95, 115, 40°)
  Error: (15, 5, 5, 5°)
  Command: forward(15cm), right(5cm), up(5cm), rotate(5°)

Iteration 2: Position (198, 102, 118, 43°)
  Error: (2, -2, 2, 2°)
  Command: forward(2cm), left(2cm), up(2cm), rotate(2°)

Iteration 3: Position (201, 99, 121, 46°)
  Error: (-1, 1, -1, -1°)
  Within tolerance ✓

Final: (201, 99, 121, 46°) - Error: <10cm, <5°

Code: See Tello/pid_controller/position_controller.py

2.6 Dead Reckoning (Position Estimation)

Overview

Estimates drone position by integrating movement commands and IMU data, tracking position in 3D space relative to takeoff point.

State Vector

$$ s = \begin{bmatrix} x \\ y \\ z \\ \psi \end{bmatrix} $$

Where $(x, y, z)$ is position in cm, $\psi$ is yaw in degrees.

Update Equations

For movement command with distance $d$:

Forward:

$$ \begin{align} x' &= x + d \cdot \cos(\psi \cdot \pi/180) \\ y' &= y + d \cdot \sin(\psi \cdot \pi/180) \end{align} $$

Backward:

$$ \begin{align} x' &= x - d \cdot \cos(\psi \cdot \pi/180) \\ y' &= y - d \cdot \sin(\psi \cdot \pi/180) \end{align} $$

Left:

$$ \begin{align} x' &= x + d \cdot \cos((\psi - 90) \cdot \pi/180) \\ y' &= y + d \cdot \sin((\psi - 90) \cdot \pi/180) \end{align} $$

Right:

$$ \begin{align} x' &= x + d \cdot \cos((\psi + 90) \cdot \pi/180) \\ y' &= y + d \cdot \sin((\psi + 90) \cdot \pi/180) \end{align} $$

Vertical:

$$ z' = z \pm d $$

Rotation:

$$ \psi' = (\psi \pm \theta) \bmod 360 $$

Coordinate Frame

      Y (Right)
      ↑
      │
      │
      └────→ X (Forward)
     ⊙
     Z (Up)

Origin: Takeoff position

Error Accumulation

Cumulative error after $n$ movements over distance $D$:

$$ \sigma_{pos} \approx \sqrt{n} \cdot \sigma_{cmd} + D \cdot \sin(\sigma_\psi) $$

Example: After 6 moves over 3m:

$$ \sigma_{pos} \approx \sqrt{6} \times 5\text{cm} + 300\text{cm} \times \sin(3°) \approx 28\text{cm} $$

Typical Accuracy: ±10-30cm per 3m traveled

Code: See Tello/obstacle_avoidance/path_executor.py

2.7 Hybrid Path Planning: Linear Interpolation + Bresenham

Overview

The Tello Drone uses a hybrid approach combining linear interpolation for direct path generation with Bresenham's algorithm for discrete waypoint computation. This enables efficient straight-line navigation with reactive obstacle avoidance and path replanning.

Path Planning Strategy

  1. Initial Planning: Linear interpolation generates direct waypoints from current position to goal
  2. Waypoint Discretization: Bresenham's algorithm converts continuous path to discrete grid points
  3. Reactive Replanning: When obstacles detected, execute dodge maneuver and recompute path to goal
  4. Path Preservation: Balanced maneuvers ensure return to original trajectory after avoidance
Tello Navigation Pipeline

Linear Interpolation (Direct Path)

Generates straight-line waypoints from start to goal:

$$ \begin{align} \mathbf{p}(t) &= (1-t) \cdot \mathbf{p}_{start} + t \cdot \mathbf{p}_{goal} \\ t &\in [0, 1] \end{align} $$

Where $\mathbf{p}(t) = (x(t), y(t))$ is position along the path.

Bresenham's Algorithm (Discrete Waypoints)

Converts continuous linear path to discrete integer grid points using only integer arithmetic (no floating-point operations). This is critical for waypoint-based navigation on the Tello's command interface.

Given start $(x_0, y_0)$ and end $(x_1, y_1)$:

  1. Calculate deltas: $dx = |x_1 - x_0|$, $dy = |y_1 - y_0|$
  2. Determine step direction: $s_x = \text{sign}(x_1 - x_0)$, $s_y = \text{sign}(y_1 - y_0)$
  3. Initialize error: $err = dx - dy$
  4. Iterate until reaching end point

Pseudocode

def bresenham_line(x0, y0, x1, y1):
    points = []
    dx = abs(x1 - x0)
    dy = abs(y1 - y0)
    sx = 1 if x0 < x1 else -1
    sy = 1 if y0 < y1 else -1
    err = dx - dy

    x, y = x0, y0

    while True:
        points.append((x, y))

        if x == x1 and y == y1:
            break

        e2 = 2 * err

        if e2 > -dy:
            err -= dy
            x += sx

        if e2 < dx:
            err += dx
            y += sy

    return points

Example: (0,0) → (5,3)

Step-by-step execution:

Initial: dx=5, dy=3, sx=1, sy=1, err=2

Iteration 1: (0,0), e2=4, step x → (1,0), err=-1
Iteration 2: (1,0), e2=-2, step y → (1,1), err=4
Iteration 3: (1,1), e2=8, step x → (2,1), err=1
Iteration 4: (2,1), e2=2, step x → (3,1), err=-2
Iteration 5: (3,1), e2=-4, step y → (3,2), err=3
Iteration 6: (3,2), e2=6, step x → (4,2), err=0
Iteration 7: (4,2), e2=0, step x → (5,2), err=-3
Iteration 8: (5,2), e2=-6, step y → (5,3), done

Output: [(0,0), (1,0), (1,1), (2,1), (3,1), (3,2), (4,2), (5,2), (5,3)]

Visualization

3 |           ●
2 |       ● ● ●
1 | ● ● ● ●
0 | ●
  +-------------
    0 1 2 3 4 5

Reactive Replanning

When obstacle is detected during flight:

  1. Detect: YOLOv8 identifies obstacle + threat level
  2. Dodge: Execute lateral or vertical balanced maneuver
  3. Recompute: Linear interpolation from new position to goal
  4. Discretize: Bresenham converts new path to waypoints
  5. Continue: Resume navigation on updated path

Benefits of Hybrid Approach

  • Efficiency: Straight-line paths minimize flight time and battery usage
  • Simplicity: Linear interpolation is fast ($O(1)$ planning time)
  • Precision: Bresenham provides optimal discrete approximation
  • Reactive: Can replan path in real-time when obstacles appear
  • Integer-only: No floating-point errors in waypoint generation
  • Deterministic: Same inputs always produce same waypoints

Complexity Analysis

  • Linear Interpolation: $O(1)$ - constant time
  • Bresenham: $O(\max(dx, dy))$ - linear in distance
  • Total Path Generation: $O(\max(dx, dy))$
  • Replanning: Same as initial planning (very fast)

Code: See Tello/obstacle_avoidance/path_planner.py

3. Key Equations Summary

Distance Estimation (Pinhole Camera)

$$ d = \frac{H \times f}{h} $$

PID Control

$$ u(t) = K_p \cdot e(t) + K_i \cdot \int e(t) dt + K_d \cdot \frac{de(t)}{dt} $$

Dead Reckoning (Forward Motion)

$$ \begin{align} x' &= x + d \cdot \cos(\psi \cdot \pi/180) \\ y' &= y + d \cdot \sin(\psi \cdot \pi/180) \end{align} $$

Bresenham Error Update

$$ \text{err} = dx - dy $$

Transform Rotation Matrix

$$ \begin{bmatrix} x' \\ y' \end{bmatrix} = \begin{bmatrix} \cos(\psi) & -\sin(\psi) \\ \sin(\psi) & \cos(\psi) \end{bmatrix} \begin{bmatrix} x \\ y \end{bmatrix} $$

ArUco Pose (PnP)

$$ \begin{bmatrix} R & t \\ 0 & 1 \end{bmatrix} = \text{solvePnP}(M, P, K, D) $$

4. System Integration & Data Flow

Overall System Architecture

┌─────────────────────────────────────────────────────────┐
│                     PERCEPTION LAYER                    │
├─────────────────────┬───────────────────────────────────┤
│   AR Drone          │         Tello Drone               │
│   - ArUco Detection │   - YOLOv8 Detection              │
│   - Camera Frames   │   - Distance Estimation           │
│                     │   - Threat Assessment             │
└─────────────────────┴───────────────────────────────────┘
           │                           │
           ▼                           ▼
┌─────────────────────────────────────────────────────────┐
│                     PLANNING LAYER                      │
├─────────────────────┬───────────────────────────────────┤
│   AR Drone          │         Tello Drone               │
│   - Grid Search     │   - Waypoint Following            │
│   - Transform Calc  │   - Obstacle Circumvention        │
│                     │   - Bresenham Pathing             │
└─────────────────────┴───────────────────────────────────┘
           │                           │
           ▼                           ▼
┌─────────────────────────────────────────────────────────┐
│                     CONTROL LAYER                       │
├─────────────────────┬───────────────────────────────────┤
│   AR Drone          │         Tello Drone               │
│   - Optical Center  │   - PID Controller                │
│   - IMU Centering   │   - Dead Reckoning                │
│   - Velocity Ctrl   │   - Position Estimator            │
└─────────────────────┴───────────────────────────────────┘
           │                           │
           ▼                           ▼
┌─────────────────────────────────────────────────────────┐
│                   COMMUNICATION LAYER                   │
│         Transform Data Exchange (WiFi/Network)          │
└─────────────────────────────────────────────────────────┘

AR Drone Pipeline

Camera → ArUco Detection → Transform Computation → Grid Search → Optical Centering → Navigation Commands

Tello Drone Pipeline

Camera → YOLOv8 → Distance Estimation → Threat Assessment → Obstacle Avoidance → Dead Reckoning → PID Control → Precision Landing

Multi-Agent Coordination

  1. AR Drone performs grid search at high altitude
  2. Detects ArUco Marker 0 (origin) and Marker 1 (target)
  3. Computes transform: body frame → world frame
  4. Communicates target coordinates to Tello Drone
  5. Tello Drone navigates to target using waypoints
  6. Real-time obstacle detection and avoidance
  7. PID-controlled precision landing at target (±10cm)

Explore More

For more information about this project: