# taintedy/flock_gpt architecture

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

- Interactive diagram: https://gitdiagram.com/taintedy/flock_gpt
- Repository: https://github.com/taintedy/flock_gpt

## Overview

##### Project Type and Purpose
- FlockGPT is a ROS‐based robotics application that integrates a Large Language Model (OpenAI) with UAV flocking control via the CrazySwarm framework and a Unity simulator.
- Purpose: Accept natural‐language commands, generate formation goals via LLM, convert goals into flocking constraints, and execute them on either real Crazyflie drones or a Unity simulator, with optional visualization in RViz.

##### Main System Components
a. User Interface & Language Layer
- LLM Process (scripts/gpt_sdf.py) — sends prompts to OpenAI, receives geometry descriptions (SDF definitions).
b. ROS Control & Orchestration
- APF Controller Node (scripts/apf_controller.py) — implements artificial potential field for collision avoidance and smoothing.
- Point Distributor (scripts/point_distributor.py) — allocates UAVs to target positions in the formation.
c. CrazySwarm Interface
- CF Show Node (scripts/cf_show_node.py) — wraps CrazySwarm API to take off, fly formations, land.
- CF Test Node (scripts/cf_test.py) — for standalone Crazyflie tests.
d. Simulator & Visualization
- ROS‐TCP‐Endpoint (external package) — bridges ROS topics to Unity simulator via TCP.
- Unity Simulator — renders UAV swarm in 3D using data from ROS‐TCP‐Endpoint.
e. Messaging & Config
- Custom ROS message Vector3StampedArray (msg/Vector3StampedArray.msg).
- launch files (launch/*.launch) — orchestrate startup of ROS nodes for different modes (simulator, CF, RViz).

##### Relationships and Data Flows
- User → LLM Process → SDF output → Swarm Controller
- Swarm Controller → APF Controller & Point Distributor → CF Show Node (or Simulator)
- CF Show Node ↔ CrazySwarm API → Real Drones
- Simulator ↔ ROS‐TCP‐Endpoint ↔ ROS Nodes

##### Architectural Patterns & Design Principles
- Modular ROS nodes separate concerns: language processing, formation logic, low-level control.
- Use of ROS topics/actions for loose coupling and easy extension.
- External service integration: OpenAI API for LLM, TCP‐bridge for Unity simulator.

##### Technologies & Libraries to Annotate
- ROS Noetic, catkin build system (CMakeLists.txt, package.xml)
- Python 3 scripts with dependencies in requirements.txt (openai, rospy, pycrazyswarm, etc.)
- CrazySwarm for hardware interface
- ROS‐TCP‐Endpoint + Unity for simulation

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Natural Language Interface
    subgraph "Natural Language Interface"
        direction TB
        LLM["LLM Process\n(scripts/gpt_sdf.py)"]:::language
        SDFFuncs["Custom SDF Functions\n(scripts/functions/)"]:::language
    end

    %% ROS Control Layer
    subgraph "ROS Control Layer"
        direction TB
        SwarmCtrl["Swarm Controller Node\n(scripts/swarm_controller_node.py)"]:::ros
        APF["APF Controller Node\n(scripts/apf_controller.py)"]:::ros
        Distributor["Point Distributor Node\n(scripts/point_distributor.py)"]:::ros
        MsgDef["Vector3StampedArray Msg\n(msg/Vector3StampedArray.msg)"]:::storage
        RVizLaunch["RViz Config\n(rviz/llm_viz.rviz)"]:::viz
    end

    %% CrazySwarm Interface
    subgraph "CrazySwarm Interface"
        direction TB
        CFShow["CF Show Node\n(scripts/cf_show_node.py)"]:::external
        CFTest["CF Test Node\n(scripts/cf_test.py)"]:::external
        CrazyAPI["CrazySwarm API"]:::external
        RealDrones["Real Drones"]:::external
    end

    %% Simulation & Visualization
    ROS_TCP["ROS-TCP-Endpoint"]:::external
    Unity["Unity Simulator"]:::external

    %% Launch Files
    subgraph "Launch Configurations"
        direction TB
        CFShowLaunch["cf_show.launch"]:::launch
        SimLaunch["sim_swarm_control.launch"]:::launch
        TestLaunch["swarm_control_test.launch"]:::launch
    end

    %% Connections
    User["User"]:::user
    OpenAI["OpenAI API"]:::external

    User -->|"natural-language cmd"| LLM
    LLM -->|"SDF prompts"| OpenAI
    OpenAI -->|"geometry desc"| LLM
    LLM -->|"SDF definitions"| SDFFuncs
    SDFFuncs -->|"shapes"| SwarmCtrl
    SwarmCtrl -->|"formation_cmd topic"| APF
    SwarmCtrl -->|"formation_cmd topic"| Distributor
    APF -->|"filtered_cmd topic"| CFShow
    Distributor -->|"assignments topic"| CFShow
    CFShow -->|"flight commands"| CrazyAPI
    CrazyAPI -->|"radio link"| RealDrones
    APF -->|"sim_cmd topic"| ROS_TCP
    Distributor -->|"sim_assign topic"| ROS_TCP
    ROS_TCP -->|"TCP|ROS bridge"| Unity
    SwarmCtrl -->|"visualization topics"| RVizLaunch
    APF -->|"state topics"| RVizLaunch
    Distributor -->|"state topics"| RVizLaunch

    %% Launch connections
    CFShowLaunch --> CFShow
    CFShowLaunch --> CrazyAPI
    SimLaunch --> SwarmCtrl
    SimLaunch --> ROS_TCP
    TestLaunch --> SwarmCtrl
    TestLaunch --> CFTest

    %% Click Events
    click LLM "https://github.com/taintedy/flock_gpt/blob/main/scripts/gpt_sdf.py"
    click SDFFuncs "https://github.com/taintedy/flock_gpt/tree/main/scripts/functions/"
    click SwarmCtrl "https://github.com/taintedy/flock_gpt/blob/main/scripts/swarm_controller_node.py"
    click APF "https://github.com/taintedy/flock_gpt/blob/main/scripts/apf_controller.py"
    click Distributor "https://github.com/taintedy/flock_gpt/blob/main/scripts/point_distributor.py"
    click CFShow "https://github.com/taintedy/flock_gpt/blob/main/scripts/cf_show_node.py"
    click CFTest "https://github.com/taintedy/flock_gpt/blob/main/scripts/cf_test.py"
    click RVizLaunch "https://github.com/taintedy/flock_gpt/blob/main/rviz/llm_viz.rviz"
    click MsgDef "https://github.com/taintedy/flock_gpt/blob/main/msg/Vector3StampedArray.msg"
    click CFShowLaunch "https://github.com/taintedy/flock_gpt/blob/main/launch/cf_show.launch"
    click SimLaunch "https://github.com/taintedy/flock_gpt/blob/main/launch/sim_swarm_control.launch"
    click TestLaunch "https://github.com/taintedy/flock_gpt/blob/main/launch/swarm_control_test.launch"

    %% Styles
    classDef language fill:#D0E8FF,stroke:#0366D6,color:#0366D6,stroke-width:1px
    classDef ros fill:#E1F8E7,stroke:#0A6622,color:#0A6622,stroke-width:1px
    classDef external fill:#FFE8D0,stroke:#D9730D,color:#D9730D,stroke-width:1px
    classDef viz fill:#F3E1FF,stroke:#8E44AD,color:#8E44AD,stroke-width:1px
    classDef storage fill:#FFF2CC,stroke:#B38F00,color:#B38F00,stroke-width:1px
    classDef user fill:#CCCCCC,stroke:#333333,color:#333333,stroke-width:1px
    classDef launch fill:#E8F0FE,stroke:#1A73E8,color:#1A73E8,stroke-width:1px
```
