# kartoff-an/ball-plate-pid-control architecture

> Architecture diagram of the GitHub repository kartoff-an/ball-plate-pid-control, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-05). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/kartoff-an/ball-plate-pid-control
- Repository: https://github.com/kartoff-an/ball-plate-pid-control

## Overview

This is a ball-and-plate balancing system: the camera firmware detects the ball and streams images; the ESP32-S3 receives measurements, runs two-axis PID control, and drives the servos. A PyQt desktop GUI sends controller and calibration commands and presents telemetry, plots, and camera calibration. The README documents the overall control and monitoring goals. Several links rely on documented behavior or source-index references; unsampled command, telemetry, and receiver implementations are not inferred beyond those references.

Main entry points: [`gui/src/main_window.py`](https://github.com/kartoff-an/ball-plate-pid-control/blob/main/gui/src/main_window.py) (GUI Window), [`firmware/esp32_s3/main/pid_controller.c`](https://github.com/kartoff-an/ball-plate-pid-control/blob/main/firmware/esp32_s3/main/pid_controller.c) (PID Controller), [`firmware/esp32_cam/main/camera.c`](https://github.com/kartoff-an/ball-plate-pid-control/blob/main/firmware/esp32_cam/main/camera.c) (Camera Capture), [`gui/src/communication/telemetry_receiver.py`](https://github.com/kartoff-an/ball-plate-pid-control/blob/main/gui/src/communication/telemetry_receiver.py) (Telemetry Receiver)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_vision["Vision Firmware"]
  node_cam_app["Camera App<br/>[app_main.c]"]
  node_camera["Camera Capture<br/>[camera.c]"]
  node_detection["Ball Detection<br/>[ball_detection.c]"]
  node_vision_tuner["Vision Tuning<br/>[vision_tuner.c]"]
  node_frame_stream["Frame Stream<br/>[wifi_stream.c]"]
  node_station["Wi-Fi Station<br/>[wifi_station.c]"]
end

subgraph group_control["Control Firmware"]
  node_s3_app["Control App<br/>[app_main.c]"]
  node_ball_receiver["Ball Receiver<br/>[ball_receiver.c]"]
  node_pid["PID Controller<br/>[pid_controller.c]"]
  node_kalman["Kalman Filter<br/>[kalman_filter.c]"]
  node_commands["Config Commands<br/>[config_commands.c]"]
  node_cal_commands["Calibration Commands"]
  node_telemetry["Telemetry<br/>[telemetry.c]"]
  node_wifi_ap["Wi-Fi Access Point<br/>[wifi_ap.c]"]
end

subgraph group_desktop["Desktop GUI"]
  node_gui_main["GUI Window<br/>[main_window.py]"]
  node_state["Application State<br/>[state.py]"]
  node_sender["Command Sender<br/>[esp_sender.py]"]
  node_telemetry_rx["Telemetry Receiver"]
  node_camera_rx["Camera Receiver<br/>[camera_receiver.py]"]
  node_controller_panel["Controller Panel"]
  node_calibration_ui["Camera Calibration"]
  node_plots["Telemetry Plots<br/>[plots.py]"]
  node_telemetry_ui["Telemetry View<br/>[telemetry.py]"]
end

subgraph group_hardware["Device Interfaces"]
  node_pca["PWM Driver<br/>[pca9685.c]"]
  node_servos["Servo Motors"]
end

node_operator(("Operator"))
node_network{{"UDP Network"}}

node_operator -->|"uses"| node_gui_main
node_gui_main -->|"creates"| node_controller_panel
node_gui_main -->|"creates"| node_plots
node_gui_main -->|"creates"| node_telemetry_ui
node_gui_main -->|"creates"| node_sender
node_controller_panel -->|"sends commands"| node_sender
node_controller_panel -->|"updates"| node_state
node_gui_main -->|"updates"| node_state
node_gui_main -->|"receives samples"| node_telemetry_rx
node_telemetry_rx -.->|"updates"| node_state
node_telemetry_rx -->|"supplies samples"| node_plots
node_telemetry_rx -->|"supplies samples"| node_telemetry_ui
node_gui_main -->|"opens"| node_calibration_ui
node_calibration_ui -->|"starts camera"| node_camera_rx
node_sender -->|"sends UDP"| node_network
node_network -.->|"delivers commands"| node_commands
node_network -.->|"delivers telemetry"| node_telemetry_rx
node_network -->|"delivers frames"| node_camera_rx
node_cam_app -->|"initializes"| node_camera
node_cam_app -->|"initializes"| node_station
node_cam_app -->|"initializes"| node_frame_stream
node_cam_app -->|"initializes"| node_vision_tuner
node_camera -->|"detects ball"| node_detection
node_camera -->|"submits frames"| node_frame_stream
node_vision_tuner -->|"configures"| node_detection
node_camera -->|"streams frames"| node_network
node_detection -.->|"provides position"| node_ball_receiver
node_s3_app -.->|"initializes"| node_ball_receiver
node_s3_app -.->|"initializes"| node_pid
node_s3_app -.->|"initializes"| node_wifi_ap
node_ball_receiver -->|"provides measurement"| node_pid
node_pid -->|"filters position"| node_kalman
node_pid -->|"sets PWM"| node_pca
node_pca -->|"drives"| node_servos
node_pid -->|"publishes"| node_telemetry
node_commands -.->|"configures"| node_pid
node_cal_commands -->|"configures"| node_pid
node_cal_commands -->|"configures"| node_pca
node_telemetry -.->|"sends telemetry"| node_network
node_network -->|"registers receiver"| node_camera

click node_cam_app "https://github.com/kartoff-an/ball-plate-pid-control/blob/main/firmware/esp32_cam/main/app_main.c"
click node_camera "https://github.com/kartoff-an/ball-plate-pid-control/blob/main/firmware/esp32_cam/main/camera.c"
click node_detection "https://github.com/kartoff-an/ball-plate-pid-control/blob/main/firmware/esp32_cam/main/ball_detection.c"
click node_vision_tuner "https://github.com/kartoff-an/ball-plate-pid-control/blob/main/firmware/esp32_cam/main/vision_tuner.c"
click node_frame_stream "https://github.com/kartoff-an/ball-plate-pid-control/blob/main/firmware/esp32_cam/main/wifi_stream.c"
click node_station "https://github.com/kartoff-an/ball-plate-pid-control/blob/main/firmware/esp32_cam/main/wifi_station.c"
click node_s3_app "https://github.com/kartoff-an/ball-plate-pid-control/blob/main/firmware/esp32_s3/main/app_main.c"
click node_ball_receiver "https://github.com/kartoff-an/ball-plate-pid-control/blob/main/firmware/esp32_s3/main/ball_receiver.c"
click node_pid "https://github.com/kartoff-an/ball-plate-pid-control/blob/main/firmware/esp32_s3/main/pid_controller.c"
click node_kalman "https://github.com/kartoff-an/ball-plate-pid-control/blob/main/firmware/esp32_s3/main/kalman_filter.c"
click node_commands "https://github.com/kartoff-an/ball-plate-pid-control/blob/main/firmware/esp32_s3/main/config_commands.c"
click node_cal_commands "https://github.com/kartoff-an/ball-plate-pid-control/blob/main/firmware/esp32_s3/main/calibration_commands.c"
click node_telemetry "https://github.com/kartoff-an/ball-plate-pid-control/blob/main/firmware/esp32_s3/main/telemetry.c"
click node_wifi_ap "https://github.com/kartoff-an/ball-plate-pid-control/blob/main/firmware/esp32_s3/main/wifi_ap.c"
click node_pca "https://github.com/kartoff-an/ball-plate-pid-control/blob/main/firmware/esp32_s3/main/pca9685.c"
click node_gui_main "https://github.com/kartoff-an/ball-plate-pid-control/blob/main/gui/src/main_window.py"
click node_state "https://github.com/kartoff-an/ball-plate-pid-control/blob/main/gui/src/state.py"
click node_sender "https://github.com/kartoff-an/ball-plate-pid-control/blob/main/gui/src/communication/esp_sender.py"
click node_telemetry_rx "https://github.com/kartoff-an/ball-plate-pid-control/blob/main/gui/src/communication/telemetry_receiver.py"
click node_camera_rx "https://github.com/kartoff-an/ball-plate-pid-control/blob/main/gui/src/communication/camera_receiver.py"
click node_controller_panel "https://github.com/kartoff-an/ball-plate-pid-control/blob/main/gui/src/widgets/controller_panel.py"
click node_calibration_ui "https://github.com/kartoff-an/ball-plate-pid-control/blob/main/gui/src/widgets/camera_calibration.py"
click node_plots "https://github.com/kartoff-an/ball-plate-pid-control/blob/main/gui/src/widgets/plots.py"
click node_telemetry_ui "https://github.com/kartoff-an/ball-plate-pid-control/blob/main/gui/src/widgets/telemetry.py"

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_cam_app,node_camera,node_detection,node_vision_tuner,node_frame_stream,node_station toneBlue
class node_s3_app,node_ball_receiver,node_pid,node_kalman,node_commands,node_cal_commands,node_telemetry,node_wifi_ap toneAmber
class node_gui_main,node_state,node_sender,node_telemetry_rx,node_camera_rx,node_controller_panel,node_calibration_ui,node_plots,node_telemetry_ui toneMint
class node_pca,node_servos toneRose
class node_operator,node_network toneIndigo
```

## Components

### Vision Firmware

- [Camera App](https://github.com/kartoff-an/ball-plate-pid-control/blob/main/firmware/esp32_cam/main/app_main.c): `firmware/esp32_cam/main/app_main.c`
- [Camera Capture](https://github.com/kartoff-an/ball-plate-pid-control/blob/main/firmware/esp32_cam/main/camera.c): `firmware/esp32_cam/main/camera.c`
- [Ball Detection](https://github.com/kartoff-an/ball-plate-pid-control/blob/main/firmware/esp32_cam/main/ball_detection.c): `firmware/esp32_cam/main/ball_detection.c`
- [Vision Tuning](https://github.com/kartoff-an/ball-plate-pid-control/blob/main/firmware/esp32_cam/main/vision_tuner.c): `firmware/esp32_cam/main/vision_tuner.c`
- [Frame Stream](https://github.com/kartoff-an/ball-plate-pid-control/blob/main/firmware/esp32_cam/main/wifi_stream.c): `firmware/esp32_cam/main/wifi_stream.c`
- [Wi-Fi Station](https://github.com/kartoff-an/ball-plate-pid-control/blob/main/firmware/esp32_cam/main/wifi_station.c): `firmware/esp32_cam/main/wifi_station.c`

### Control Firmware

- [Control App](https://github.com/kartoff-an/ball-plate-pid-control/blob/main/firmware/esp32_s3/main/app_main.c): `firmware/esp32_s3/main/app_main.c`
- [Ball Receiver](https://github.com/kartoff-an/ball-plate-pid-control/blob/main/firmware/esp32_s3/main/ball_receiver.c): `firmware/esp32_s3/main/ball_receiver.c`
- [PID Controller](https://github.com/kartoff-an/ball-plate-pid-control/blob/main/firmware/esp32_s3/main/pid_controller.c): `firmware/esp32_s3/main/pid_controller.c`
- [Kalman Filter](https://github.com/kartoff-an/ball-plate-pid-control/blob/main/firmware/esp32_s3/main/kalman_filter.c): `firmware/esp32_s3/main/kalman_filter.c`
- [Config Commands](https://github.com/kartoff-an/ball-plate-pid-control/blob/main/firmware/esp32_s3/main/config_commands.c): `firmware/esp32_s3/main/config_commands.c`
- [Calibration Commands](https://github.com/kartoff-an/ball-plate-pid-control/blob/main/firmware/esp32_s3/main/calibration_commands.c): `firmware/esp32_s3/main/calibration_commands.c`
- [Telemetry](https://github.com/kartoff-an/ball-plate-pid-control/blob/main/firmware/esp32_s3/main/telemetry.c): `firmware/esp32_s3/main/telemetry.c`
- [Wi-Fi Access Point](https://github.com/kartoff-an/ball-plate-pid-control/blob/main/firmware/esp32_s3/main/wifi_ap.c): `firmware/esp32_s3/main/wifi_ap.c`

### Desktop GUI

- [GUI Window](https://github.com/kartoff-an/ball-plate-pid-control/blob/main/gui/src/main_window.py): `gui/src/main_window.py`
- [Application State](https://github.com/kartoff-an/ball-plate-pid-control/blob/main/gui/src/state.py): `gui/src/state.py`
- [Command Sender](https://github.com/kartoff-an/ball-plate-pid-control/blob/main/gui/src/communication/esp_sender.py): `gui/src/communication/esp_sender.py`
- [Telemetry Receiver](https://github.com/kartoff-an/ball-plate-pid-control/blob/main/gui/src/communication/telemetry_receiver.py): `gui/src/communication/telemetry_receiver.py`
- [Camera Receiver](https://github.com/kartoff-an/ball-plate-pid-control/blob/main/gui/src/communication/camera_receiver.py): `gui/src/communication/camera_receiver.py`
- [Controller Panel](https://github.com/kartoff-an/ball-plate-pid-control/blob/main/gui/src/widgets/controller_panel.py): `gui/src/widgets/controller_panel.py`
- [Camera Calibration](https://github.com/kartoff-an/ball-plate-pid-control/blob/main/gui/src/widgets/camera_calibration.py): `gui/src/widgets/camera_calibration.py`
- [Telemetry Plots](https://github.com/kartoff-an/ball-plate-pid-control/blob/main/gui/src/widgets/plots.py): `gui/src/widgets/plots.py`
- [Telemetry View](https://github.com/kartoff-an/ball-plate-pid-control/blob/main/gui/src/widgets/telemetry.py): `gui/src/widgets/telemetry.py`

### Device Interfaces

- [PWM Driver](https://github.com/kartoff-an/ball-plate-pid-control/blob/main/firmware/esp32_s3/main/pca9685.c): `firmware/esp32_s3/main/pca9685.c`
- **Servo Motors**

### Other components

- **Operator**
- **UDP Network**

## Connections

- Operator → GUI Window: uses (evidence: `README.md`)
- GUI Window → Controller Panel: creates (evidence: `gui/src/main_window.py`)
- GUI Window → Telemetry Plots: creates (evidence: `gui/src/main_window.py`)
- GUI Window → Telemetry View: creates (evidence: `gui/src/main_window.py`)
- GUI Window → Command Sender: creates (evidence: `gui/src/main_window.py`)
- Controller Panel → Command Sender: sends commands (evidence: `gui/src/widgets/controller_panel.py`)
- Controller Panel → Application State: updates (evidence: `gui/src/widgets/controller_panel.py`)
- GUI Window → Application State: updates (evidence: `gui/src/main_window.py`)
- GUI Window → Telemetry Receiver: receives samples (evidence: `gui/src/main_window.py`)
- Telemetry Receiver → Application State: updates
- Telemetry Receiver → Telemetry Plots: supplies samples (evidence: `gui/src/main_window.py`)
- Telemetry Receiver → Telemetry View: supplies samples (evidence: `gui/src/widgets/telemetry.py`)
- GUI Window → Camera Calibration: opens (evidence: `gui/src/main_window.py`)
- Camera Calibration → Camera Receiver: starts camera (evidence: `gui/src/widgets/camera_calibration.py`)
- Command Sender → UDP Network: sends UDP (evidence: `gui/src/communication/esp_sender.py`)
- UDP Network → Config Commands: delivers commands
- UDP Network → Telemetry Receiver: delivers telemetry
- UDP Network → Camera Receiver: delivers frames (evidence: `gui/src/communication/camera_receiver.py`)
- Camera App → Camera Capture: initializes (evidence: `firmware/esp32_cam/main/app_main.c`)
- Camera App → Wi-Fi Station: initializes (evidence: `firmware/esp32_cam/main/app_main.c`)
- Camera App → Frame Stream: initializes (evidence: `firmware/esp32_cam/main/app_main.c`)
- Camera App → Vision Tuning: initializes (evidence: `firmware/esp32_cam/main/app_main.c`)
- Camera Capture → Ball Detection: detects ball (evidence: `firmware/esp32_cam/main/camera.c`)
- Camera Capture → Frame Stream: submits frames (evidence: `firmware/esp32_cam/main/camera.c`)
- Vision Tuning → Ball Detection: configures (evidence: `firmware/esp32_cam/main/vision_tuner.c`)
- Camera Capture → UDP Network: streams frames
- Ball Detection → Ball Receiver: provides position
- Control App → Ball Receiver: initializes
- Control App → PID Controller: initializes
- Control App → Wi-Fi Access Point: initializes
- Ball Receiver → PID Controller: provides measurement (evidence: `firmware/esp32_s3/main/pid_controller.c`)
- PID Controller → Kalman Filter: filters position (evidence: `firmware/esp32_s3/main/pid_controller.c`)
- PID Controller → PWM Driver: sets PWM (evidence: `firmware/esp32_s3/main/pid_controller.c`)
- PWM Driver → Servo Motors: drives
- PID Controller → Telemetry: publishes (evidence: `firmware/esp32_s3/main/pid_controller.c`)
- Config Commands → PID Controller: configures
- Calibration Commands → PID Controller: configures (evidence: `firmware/esp32_s3/main/calibration_commands.c`)
- Calibration Commands → PWM Driver: configures (evidence: `firmware/esp32_s3/main/calibration_commands.c`)
- Telemetry → UDP Network: sends telemetry
- UDP Network → Camera Capture: registers receiver
