# rctestflight/trail_tracer_mower architecture

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

- Interactive diagram: https://gitdiagram.com/rctestflight/trail_tracer_mower
- Repository: https://github.com/rctestflight/trail_tracer_mower

## Overview

This is ESP32 firmware for the WFRX TrailTracer receiver/controller. Its principal workflow is to receive sensor, status, and charging packets from an STM32 over UART, use firmware control logic to manage steering and charging, and exchange commands and telemetry with connected systems. At startup, it loads device settings through a USB mass-storage configuration interface and applies them. The graph includes the sampled PWM capture and stuck-detection modules; unsampled behavior is represented only where documented or referenced, so some internal control and integration links are omitted.

Main entry points: [`src/main.cpp`](https://github.com/rctestflight/trail_tracer_mower/blob/main/src/main.cpp) (Firmware coordinator), [`src/usb_msc_fat.cpp`](https://github.com/rctestflight/trail_tracer_mower/blob/main/src/usb_msc_fat.cpp) (Configuration service), [`src_public_release/main.cpp`](https://github.com/rctestflight/trail_tracer_mower/blob/main/src_public_release/main.cpp) (Telemetry broadcast), [`src_public_release/rctf_wfrx_esp32.cpp`](https://github.com/rctestflight/trail_tracer_mower/blob/main/src_public_release/rctf_wfrx_esp32.cpp) (Stuck detection)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Firmware runtime"]
  node_main["Firmware coordinator<br/>[main.cpp]"]
  node_telemetry["Telemetry broadcast<br/>[main.cpp]"]
end

subgraph group_control["Vehicle control"]
  node_stuck["Stuck detection"]
  node_steering["Steering control<br/>[main.cpp]"]
  node_charging["Charge management<br/>[main.cpp]"]
end

subgraph group_configuration["Device configuration"]
  node_config["Configuration service<br/>[usb_msc_fat.cpp]"]
  node_config_api["Configuration API<br/>[usb_msc_fat.h]"]
  node_flash[("Flash-backed storage<br/>[usb_msc_fat.cpp]")]
  node_filesystem["FAT config files<br/>[usb_msc_fat.cpp]"]
end

subgraph group_interfaces["Hardware interfaces"]
  node_packet["UART packet contract<br/>[wfrx_stm32_comms.h]"]
  node_status["Status bit definitions"]
  node_pwm["PWM input capture<br/>[pwm_read_rmt.c]"]
end

node_operator(("USB host"))
node_stm32["STM32 controller"]

node_stm32 -->|"sends UART packets"| node_main
node_main -->|"uses packet format"| node_packet
node_main -->|"uses status bits"| node_status
node_main -->|"initializes settings"| node_config
node_main -->|"imports capture API"| node_pwm
node_main -->|"computes steering"| node_steering
node_main -->|"runs charge control"| node_charging
node_main -->|"queues telemetry"| node_telemetry
node_main -.->|"uses detector"| node_stuck
node_operator -->|"edits config"| node_config
node_config -->|"implements API"| node_config_api
node_config -->|"reads and writes"| node_flash
node_config -->|"loads and saves JSON"| node_filesystem

click node_main "https://github.com/rctestflight/trail_tracer_mower/blob/main/src/main.cpp"
click node_packet "https://github.com/rctestflight/trail_tracer_mower/blob/main/include/wfrx_stm32_comms.h"
click node_status "https://github.com/rctestflight/trail_tracer_mower/blob/main/include/rctf_wfrx_status_bits.h"
click node_pwm "https://github.com/rctestflight/trail_tracer_mower/blob/main/src/pwm_read_rmt.c"
click node_stuck "https://github.com/rctestflight/trail_tracer_mower/blob/main/src_public_release/rctf_wfrx_esp32.cpp"
click node_steering "https://github.com/rctestflight/trail_tracer_mower/blob/main/src_public_release/main.cpp"
click node_charging "https://github.com/rctestflight/trail_tracer_mower/blob/main/src/main.cpp"
click node_telemetry "https://github.com/rctestflight/trail_tracer_mower/blob/main/src_public_release/main.cpp"
click node_config "https://github.com/rctestflight/trail_tracer_mower/blob/main/src/usb_msc_fat.cpp"
click node_config_api "https://github.com/rctestflight/trail_tracer_mower/blob/main/include/usb_msc_fat.h"
click node_flash "https://github.com/rctestflight/trail_tracer_mower/blob/main/src/usb_msc_fat.cpp"
click node_filesystem "https://github.com/rctestflight/trail_tracer_mower/blob/main/src/usb_msc_fat.cpp"

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_main,node_telemetry toneBlue
class node_stuck,node_steering,node_charging toneAmber
class node_config,node_config_api,node_flash,node_filesystem toneMint
class node_packet,node_status,node_pwm toneRose
class node_operator,node_stm32 toneIndigo
```

## Components

### Firmware runtime

- [Firmware coordinator](https://github.com/rctestflight/trail_tracer_mower/blob/main/src/main.cpp): `src/main.cpp`
- [Telemetry broadcast](https://github.com/rctestflight/trail_tracer_mower/blob/main/src_public_release/main.cpp): `src_public_release/main.cpp`

### Vehicle control

- [Stuck detection](https://github.com/rctestflight/trail_tracer_mower/blob/main/src_public_release/rctf_wfrx_esp32.cpp): `src_public_release/rctf_wfrx_esp32.cpp`
- [Steering control](https://github.com/rctestflight/trail_tracer_mower/blob/main/src_public_release/main.cpp): `src_public_release/main.cpp`
- [Charge management](https://github.com/rctestflight/trail_tracer_mower/blob/main/src/main.cpp): `src/main.cpp`

### Device configuration

- [Configuration service](https://github.com/rctestflight/trail_tracer_mower/blob/main/src/usb_msc_fat.cpp): `src/usb_msc_fat.cpp`
- [Configuration API](https://github.com/rctestflight/trail_tracer_mower/blob/main/include/usb_msc_fat.h): `include/usb_msc_fat.h`
- [Flash-backed storage](https://github.com/rctestflight/trail_tracer_mower/blob/main/src/usb_msc_fat.cpp): `src/usb_msc_fat.cpp`
- [FAT config files](https://github.com/rctestflight/trail_tracer_mower/blob/main/src/usb_msc_fat.cpp): `src/usb_msc_fat.cpp`

### Hardware interfaces

- [UART packet contract](https://github.com/rctestflight/trail_tracer_mower/blob/main/include/wfrx_stm32_comms.h): `include/wfrx_stm32_comms.h`
- [Status bit definitions](https://github.com/rctestflight/trail_tracer_mower/blob/main/include/rctf_wfrx_status_bits.h): `include/rctf_wfrx_status_bits.h`
- [PWM input capture](https://github.com/rctestflight/trail_tracer_mower/blob/main/src/pwm_read_rmt.c): `src/pwm_read_rmt.c`

### Other components

- **USB host**
- **STM32 controller**

## Connections

- STM32 controller → Firmware coordinator: sends UART packets (evidence: `src/main.cpp`)
- Firmware coordinator → UART packet contract: uses packet format (evidence: `src/main.cpp`)
- Firmware coordinator → Status bit definitions: uses status bits (evidence: `src/main.cpp`)
- Firmware coordinator → Configuration service: initializes settings (evidence: `src/main.cpp`)
- Firmware coordinator → PWM input capture: imports capture API (evidence: `src/main.cpp`)
- Firmware coordinator → Steering control: computes steering (evidence: `src_public_release/main.cpp`)
- Firmware coordinator → Charge management: runs charge control (evidence: `src/main.cpp`)
- Firmware coordinator → Telemetry broadcast: queues telemetry (evidence: `src_public_release/main.cpp`)
- Firmware coordinator → Stuck detection: uses detector
- USB host → Configuration service: edits config
- Configuration service → Configuration API: implements API (evidence: `src/usb_msc_fat.cpp`)
- Configuration service → Flash-backed storage: reads and writes (evidence: `src/usb_msc_fat.cpp`)
- Configuration service → FAT config files: loads and saves JSON (evidence: `src/usb_msc_fat.cpp`)
