# kyurururn/telloedu_drone architecture

> Architecture diagram of the GitHub repository kyurururn/telloedu_drone, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-11-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/kyurururn/telloedu_drone
- Repository: https://github.com/kyurururn/telloedu_drone

## Overview

##### Project Type and Purpose
- This is a Python library (TelloDrone_Lib) for controlling a DJI Tello drone over UDP and optionally capturing video/images using OpenCV.
- It provides a simple CLI interface (via sample.py) to send commands (e.g., takeoff, land, move, shoot) and to stream or record video.

##### File Structure Analysis
- Top-level files:
- TelloDrone_Lib.py / TelloDrone_Lib_add_comment.py – core library implementation
- sample.py – example CLI client using the library
- setup.py – packaging script
- LICENSE.txt, README.MD – documentation
- No separate frontend/backend: the library itself encapsulates networking, command parsing, and (optionally) video capture/encoding.

##### Key Components
A. User Interface (CLI)
- sample.py or any user script
- Responsibilities: read user input, call `drone.send_command()`, display responses
B. TelloDrone_Lib Module
- Command Processor
- Parses high-level commands (e.g., “up 50”, “shoot”)
- Maps shorthand to standard commands
- UDP Communication Layer
- Sends UDP packets to drone’s control port (default 8889)
- Listens for acknowledgments on a local UDP socket
- Video/Camera Subsystem (optional, behind flags)
- Initializes video stream (Tello’s video UDP port)
- Uses OpenCV to decode H.264 frames into images/frames
- Handles “shoot” (save JPEG) and “take_movie” (video writer)
- Safety/Timeout Controller
- Monitors intervals between commands (send_regu flag)
- Triggers auto-land if no commands within timeout (unless disabled)
C. DJI Tello Drone Hardware
- Control Interface (UDP server on drone)
- Video Stream Interface (UDP H.264 stream)
- Camera sensor, flight controller
D. Optional Local File System
- Stores captured images/video files

##### Interactions and Data Flows
- User → CLI script: types command →
- CLI → TelloDrone_Lib Command Processor →
- UDP Comm Layer → Drone (control port) →
- Drone → UDP Comm Layer (ack) → Command Processor → CLI (print)
- If video enabled:
- Drone → UDP Video Stream → Video Subsystem → OpenCV Decoder → display or file write

##### Architectural Patterns and Design Principles
- Modular layering: separation of CLI, command parsing, networking, video processing
- Single-responsibility modules within the library
- Optional features toggled by constructor flags (send_regu, capture_setting, take_movie)
- Stateless command calls with internal timeout management

##### Step-by-Step Creation
6. Video Subsystem → File System (for shoot/movie)

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% User Machine with CLI and Library
    subgraph "User Machine"
        sample["CLI Client\n(sample.py)"]:::cli
        subgraph "TelloDrone_Lib Module"
            CP["Command Processor"]:::library
            UDP["UDP Communication Layer"]:::library
            VS["Video Subsystem"]:::library
            TC["Timeout Controller"]:::library
            LibFile["TelloDrone_Lib.py"]:::doc
            LibFile2["TelloDrone_Lib_add_comment.py"]:::doc
        end
    end

    %% Drone Hardware
    subgraph "Drone Hardware"
        DC["Control Interface\n(UDP 8889)"]:::hardware
        DV["Video Stream Interface\n(UDP H.264)"]:::hardware
    end

    %% Local File System
    FS["Local File System"]:::fs

    %% Project Files
    subgraph "Project Files"
        setup["setup.py"]:::doc
        readme["README.MD"]:::doc
        license["LICENSE.txt"]:::doc
    end

    %% Data Flows
    sample -->|"import & call send_command()"| CP
    CP -->|"parsed commands"| UDP
    UDP -->|"UDP Command\n(port 8889)"| DC
    DC -->|"acknowledgment"| UDP
    UDP -->|"ack to Command Processor"| CP
    DV -->|"UDP Video Stream\n(H.264)"| VS
    VS -->|"decoded frames"| sample
    VS -->|"save JPEG/video"| FS

    %% Click Events
    click sample "https://github.com/kyurururn/telloedu_drone/blob/main/sample.py"
    click LibFile "https://github.com/kyurururn/telloedu_drone/blob/main/TelloDrone_Lib.py"
    click LibFile2 "https://github.com/kyurururn/telloedu_drone/blob/main/TelloDrone_Lib_add_comment.py"
    click setup "https://github.com/kyurururn/telloedu_drone/blob/main/setup.py"
    click readme "https://github.com/kyurururn/telloedu_drone/blob/main/README.MD"
    click license "https://github.com/kyurururn/telloedu_drone/blob/main/LICENSE.txt"

    %% Styles
    classDef cli fill:#e7f3fe,stroke:#3182bd,color:#0b3d91
    classDef library fill:#d4edda,stroke:#2e7d32,color:#1b5e20
    classDef network stroke:#1e90ff,stroke-dasharray: 5 5
    classDef hardware fill:#f8d7da,stroke:#c62828,color:#b71c1c
    classDef fs fill:#fff3cd,stroke:#f9a825,color:#f57f17
    classDef doc fill:#ececec,stroke:#6c757d,color:#343a40
    class UDP network
    class DC network
    class DV network
```
