# songge8/cf-drone architecture

> Architecture diagram of the GitHub repository songge8/cf-drone, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-13). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/songge8/cf-drone
- Repository: https://github.com/songge8/cf-drone

## Overview

CF-Drone is ESP32-family multirotor flight-controller firmware. The principal workflow is pilot input (SBUS or the documented web remote), flight-control computation, and motor output, with IMU sensing feeding attitude estimation and safety logic constraining operation. The README also documents battery protection, Wi-Fi/web control, console configuration, LEDs, and logging. Several runtime files are unsampled, so their likely connections are shown only as unverified dashed edges; source-level links are limited to indexed references and excerpts.

Main entry points: [`control.ino`](https://github.com/songge8/cf-drone/blob/main/control.ino) (Flight control), [`estimate.ino`](https://github.com/songge8/cf-drone/blob/main/estimate.ino) (Attitude estimation), [`drivers/MPU9250.cpp`](https://github.com/songge8/cf-drone/blob/main/drivers/MPU9250.cpp) (MPU6500/9250 driver), [`safety.ino`](https://github.com/songge8/cf-drone/blob/main/safety.ino) (Arming and failsafe)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_input["Pilot interfaces"]
  node_sbus["SBUS receiver<br/>[SBUS.cpp]"]
  node_webremote["Web remote<br/>[web_rc.ino]"]
  node_webui["Remote interface<br/>[web_rc_html.h]"]
  node_wifi["Wi-Fi service<br/>[wifi.ino]"]
end

subgraph group_flight["Flight control"]
  node_flightcontrol["Flight control<br/>[control.ino]"]
  node_pid["PID controllers<br/>[pid.h]"]
  node_filters["Low-pass filter<br/>[lpf.h]"]
  node_motors["Motor output<br/>[motors.ino]"]
end

subgraph group_sensing["Sensing and estimation"]
  node_imuinterface["IMU interface<br/>[IMU.h]"]
  node_mpu["MPU6500/9250 driver<br/>[MPU9250.cpp]"]
  node_imuio["Sensor bus I/O<br/>[invensense_imu.cpp]"]
  node_estimator["Attitude estimation<br/>[estimate.ino]"]
  node_vectors["Vector math<br/>[vector.h]"]
  node_quaternions["Quaternion math<br/>[quaternion.h]"]
  node_vectorsmath["Vector primitives<br/>[vector.h]"]
end

subgraph group_runtime["Runtime and safety"]
  node_battery["Battery monitoring<br/>[battery.ino]"]
  node_safety["Arming and failsafe<br/>[safety.ino]"]
  node_config["Parameters and console<br/>[parameters.ino]"]
  node_cli["Debug console<br/>[cli.ino]"]
  node_status["LED status<br/>[led.ino]"]
  node_logs["Logging<br/>[log.ino]"]
  node_mavlink["MAVLink<br/>[mavlink.ino]"]
end

node_pilot(("Pilot"))

node_pilot -.->|"sends commands"| node_sbus
node_pilot -.->|"sends commands"| node_webui
node_webui -.->|"provides interface"| node_webremote
node_wifi -.->|"hosts remote"| node_webremote
node_sbus -.->|"supplies input"| node_flightcontrol
node_webremote -.->|"supplies input"| node_flightcontrol
node_flightcontrol -.->|"uses control loops"| node_pid
node_pid -->|"filters derivative"| node_filters
node_flightcontrol -.->|"commands output"| node_motors
node_mpu -->|"uses bus I/O"| node_imuio
node_mpu -->|"implements interface"| node_imuinterface
node_mpu -.->|"provides measurements"| node_estimator
node_estimator -.->|"provides attitude"| node_flightcontrol
node_quaternions -->|"uses vector math"| node_vectors
node_estimator -.->|"uses rotations"| node_quaternions
node_estimator -.->|"uses vectors"| node_vectorsmath
node_battery -.->|"triggers protection"| node_safety
node_safety -.->|"limits operation"| node_motors
node_config -.->|"configured through"| node_cli
node_safety -.->|"signals warnings"| node_status
node_cli -.->|"displays diagnostics"| node_logs

click node_sbus "https://github.com/songge8/cf-drone/blob/main/drivers/SBUS.cpp"
click node_webremote "https://github.com/songge8/cf-drone/blob/main/web_rc.ino"
click node_webui "https://github.com/songge8/cf-drone/blob/main/web_rc_html.h"
click node_wifi "https://github.com/songge8/cf-drone/blob/main/wifi.ino"
click node_flightcontrol "https://github.com/songge8/cf-drone/blob/main/control.ino"
click node_pid "https://github.com/songge8/cf-drone/blob/main/pid.h"
click node_filters "https://github.com/songge8/cf-drone/blob/main/lpf.h"
click node_motors "https://github.com/songge8/cf-drone/blob/main/motors.ino"
click node_imuinterface "https://github.com/songge8/cf-drone/blob/main/drivers/IMU.h"
click node_mpu "https://github.com/songge8/cf-drone/blob/main/drivers/MPU9250.cpp"
click node_imuio "https://github.com/songge8/cf-drone/blob/main/drivers/invensense_imu.cpp"
click node_estimator "https://github.com/songge8/cf-drone/blob/main/estimate.ino"
click node_vectors "https://github.com/songge8/cf-drone/blob/main/vector.h"
click node_quaternions "https://github.com/songge8/cf-drone/blob/main/quaternion.h"
click node_battery "https://github.com/songge8/cf-drone/blob/main/battery.ino"
click node_safety "https://github.com/songge8/cf-drone/blob/main/safety.ino"
click node_config "https://github.com/songge8/cf-drone/blob/main/parameters.ino"
click node_cli "https://github.com/songge8/cf-drone/blob/main/cli.ino"
click node_status "https://github.com/songge8/cf-drone/blob/main/led.ino"
click node_logs "https://github.com/songge8/cf-drone/blob/main/log.ino"
click node_mavlink "https://github.com/songge8/cf-drone/blob/main/mavlink.ino"
click node_vectorsmath "https://github.com/songge8/cf-drone/blob/main/vector.h"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_sbus,node_webremote,node_webui,node_wifi toneBlue
class node_flightcontrol,node_pid,node_filters,node_motors toneAmber
class node_imuinterface,node_mpu,node_imuio,node_estimator,node_vectors,node_quaternions,node_vectorsmath toneMint
class node_battery,node_safety,node_config,node_cli,node_status,node_logs,node_mavlink toneRose
class node_pilot toneIndigo
```

## Components

### Pilot interfaces

- [SBUS receiver](https://github.com/songge8/cf-drone/blob/main/drivers/SBUS.cpp): `drivers/SBUS.cpp`
- [Web remote](https://github.com/songge8/cf-drone/blob/main/web_rc.ino): `web_rc.ino`
- [Remote interface](https://github.com/songge8/cf-drone/blob/main/web_rc_html.h): `web_rc_html.h`
- [Wi-Fi service](https://github.com/songge8/cf-drone/blob/main/wifi.ino): `wifi.ino`

### Flight control

- [Flight control](https://github.com/songge8/cf-drone/blob/main/control.ino): `control.ino`
- [PID controllers](https://github.com/songge8/cf-drone/blob/main/pid.h): `pid.h`
- [Low-pass filter](https://github.com/songge8/cf-drone/blob/main/lpf.h): `lpf.h`
- [Motor output](https://github.com/songge8/cf-drone/blob/main/motors.ino): `motors.ino`

### Sensing and estimation

- [IMU interface](https://github.com/songge8/cf-drone/blob/main/drivers/IMU.h): `drivers/IMU.h`
- [MPU6500/9250 driver](https://github.com/songge8/cf-drone/blob/main/drivers/MPU9250.cpp): `drivers/MPU9250.cpp`
- [Sensor bus I/O](https://github.com/songge8/cf-drone/blob/main/drivers/invensense_imu.cpp): `drivers/invensense_imu.cpp`
- [Attitude estimation](https://github.com/songge8/cf-drone/blob/main/estimate.ino): `estimate.ino`
- [Vector math](https://github.com/songge8/cf-drone/blob/main/vector.h): `vector.h`
- [Quaternion math](https://github.com/songge8/cf-drone/blob/main/quaternion.h): `quaternion.h`
- [Vector primitives](https://github.com/songge8/cf-drone/blob/main/vector.h): `vector.h`

### Runtime and safety

- [Battery monitoring](https://github.com/songge8/cf-drone/blob/main/battery.ino): `battery.ino`
- [Arming and failsafe](https://github.com/songge8/cf-drone/blob/main/safety.ino): `safety.ino`
- [Parameters and console](https://github.com/songge8/cf-drone/blob/main/parameters.ino): `parameters.ino`
- [Debug console](https://github.com/songge8/cf-drone/blob/main/cli.ino): `cli.ino`
- [LED status](https://github.com/songge8/cf-drone/blob/main/led.ino): `led.ino`
- [Logging](https://github.com/songge8/cf-drone/blob/main/log.ino): `log.ino`
- [MAVLink](https://github.com/songge8/cf-drone/blob/main/mavlink.ino): `mavlink.ino`

### Other components

- **Pilot**

## Connections

- Pilot → SBUS receiver: sends commands
- Pilot → Remote interface: sends commands
- Remote interface → Web remote: provides interface
- Wi-Fi service → Web remote: hosts remote
- SBUS receiver → Flight control: supplies input
- Web remote → Flight control: supplies input
- Flight control → PID controllers: uses control loops
- PID controllers → Low-pass filter: filters derivative (evidence: `pid.h`)
- Flight control → Motor output: commands output
- MPU6500/9250 driver → Sensor bus I/O: uses bus I/O
- MPU6500/9250 driver → IMU interface: implements interface
- MPU6500/9250 driver → Attitude estimation: provides measurements
- Attitude estimation → Flight control: provides attitude
- Quaternion math → Vector math: uses vector math (evidence: `quaternion.h`)
- Attitude estimation → Quaternion math: uses rotations
- Attitude estimation → Vector primitives: uses vectors
- Battery monitoring → Arming and failsafe: triggers protection (evidence: `README.MD`)
- Arming and failsafe → Motor output: limits operation (evidence: `README.MD`)
- Parameters and console → Debug console: configured through (evidence: `README.MD`)
- Arming and failsafe → LED status: signals warnings (evidence: `README.MD`)
- Debug console → Logging: displays diagnostics
