# sparkyvt/hpr-rocket-flight-computer architecture

> Architecture diagram of the GitHub repository sparkyvt/hpr-rocket-flight-computer, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-09-18). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/sparkyvt/hpr-rocket-flight-computer
- Repository: https://github.com/sparkyvt/hpr-rocket-flight-computer

## Overview

##### Project type and purpose
- This is an embedded-systems project for a high-power rocket flight computer plus a companion ground-station and desktop parser.
- Purpose: Acquire, fuse, log and transmit sensor data in real time during a rocket flight; recover data post-flight; display live telemetry on a ground station; analyze flight logs on a PC.

##### File structure
Top-level directories:
- “Main Code” – the firmware for the on-board flight computer (Teensy).
- “Ground Station” – Arduino Nano BLE firmware for live telemetry reception and display.
- “Parser” – Python scripts for post-flight data analysis/plotting on a PC.
- “Build Photos”, “Operations Flow Chart.docx”, “LICENSE”, “README.txt” – docs and assets.
Key patterns:
- Main Code is split by functional modules (Device_Drivers, Telemetry, Event_Logic, SD, Radio drivers, Calibration, Rotation, etc.).
- Ground Station code is organized by sub-modules (GPS, Radio, LCD, SD_Card, packet parsing).
- Parser uses standalone Python scripts to read/write CSV data and generate plots.

##### Extract architectural insights from the README
- Hardware components: Teensy MCU, IMU, magnetometer, barometer, GPS, LoRa radio, SD card, pyro outputs.
- Ground station hardware: Arduino Nano, LoRa radio, GPS (optional), IMU, LCD, SD card.
- Data flows: Real-time telemetry via LoRa; local SD logging on both flight computer and ground station; post-flight USB/SD data extraction; desktop analysis.

##### Main components
A. On-Board Flight Computer
- Sensors: IMU, barometer, GPS
- MCU: Teensy 3.x/4.x running modular firmware (drivers, event logic, telemetry, SD logger)
- Outputs: Pyro drivers, continuity checks, servo outputs
- Storage: SD card (configuration + flight logs)
- Radio: LoRa transceiver (433/915 MHz)
B. Ground Station
- MCU: Arduino Nano 33 BLE
- Radio: LoRa transceiver (433/915 MHz)
- 20×4 LCD
- GPS + IMU (optional real-time position/orientation)
- Storage: SD card for telemetry logs
C. Desktop/PC Parser
- benchTestAnalysis.py, plotFlightData.py, plotTelemetryData.py
- Inputs: CSV/log files from SD cards or serial dumps
- Outputs: graphs, reports, Google Earth KML files

##### Relationships and data flows
- Sensors → MCU (I2C/SPI) on flight computer
- MCU processes data → stores on SD card
- MCU packages telemetry → sends via LoRa → Ground Station
- Ground Station LoRa RX → parses packets → updates LCD + logs to its SD
- Post-flight: remove SD or use USB serial → feed logs into Parser scripts on PC
- Parser scripts produce plots, event timing, trajectory analysis

##### Architectural patterns and design principles
- Real-time, event-driven state machine for flight phases (pre-launch, ascent, apogee, deployment).
- Sensor fusion for attitude and apogee detection.
- Modular firmware layers: hardware abstraction (drivers), core logic (event handling), I/O layers (SD, radio), user interface (configuration).
- Separation of concerns: on-board vs. ground vs. post-processing.

##### Technologies and frameworks to annotate
- Firmware: Arduino/C++ (`.ino` files), hardware drivers (SPI/I2C).
- Radio: LoRa (RFM9x family).
- Storage: SDfat or SD library.
- GPS: TinyGPS++ library.
- Parser: Python (matplotlib, pandas or built-ins).
- Deployment targets: Teensy 3.2/3.5/3.6/4.x, Arduino Nano 33 BLE.

## Diagram (Mermaid)

```mermaid
graph TB
    %% Flight Computer Block
    subgraph "On-Board Flight Computer"
        FC_Main["Main Firmware (.ino)"]:::firmware
        FC_Bus["Bus Management (I2C/SPI)"]:::firmware
        FC_Internal["Internal Sensor Drivers"]:::firmware
        FC_External["External Sensor Drivers"]:::firmware
        FC_Cal["Sensor Calibration"]:::firmware
        FC_Rot["Rotation & Attitude (Fusion)"]:::firmware
        FC_GPSconf["GPS Configuration"]:::firmware
        FC_Event["Flight Event State Machine"]:::firmware
        FC_Telem["Telemetry Formatting & Tx"]:::firmware
        FC_LoRa1["LoRa Transceiver Driver"]:::firmware
        FC_RFDx["Alt Radio Driver (RFDx)"]:::firmware
        FC_SD["SD Card Logging"]:::firmware
        FC_Pyro["Pyro Outputs & Continuity"]:::firmware
        FC_DevMgmt["Device Management"]:::firmware
        FC_InFlight["In-Flight Data Recovery"]:::firmware
        FC_Config["Config Settings"]:::firmware
    end

    %% Ground Station Block
    subgraph "Ground Station"
        GS_Core["Telemetry Receiver"]:::firmware
        GS_Radio["LoRa Radio Interface"]:::firmware
        GS_GPS["GPS Module Handler"]:::firmware
        GS_LCD["LCD Display Driver"]:::firmware
        GS_Parse["Packet Parsing Logic"]:::firmware
        GS_SD["SD Card Logger"]:::firmware
        GS_Settings["Config Settings"]:::firmware
    end

    %% PC Parser Block
    subgraph "Desktop Parser"
        PC_Bench["benchTestAnalysis.py"]:::pc
        PC_FlightPlot["plotFlightData.py"]:::pc
        PC_TelemPlot["plotTelemetryData.py"]:::pc
    end

    %% Hardware Entities
    Sensors["Sensors: IMU, Barometer, GPS"]:::hardware
    LoRa_Flight["LoRa Transceiver"]:::hardware
    SD_Flight["SD Card"]:::hardware
    LoRa_GS["LoRa Transceiver"]:::hardware
    LCD_HW["20×4 LCD"]:::hardware
    SD_GS["SD Card"]:::hardware

    %% Data Flows
    Sensors -->|"I2C/SPI"| FC_Bus
    FC_Bus --> FC_Internal
    FC_Bus --> FC_External
    FC_Internal --> FC_Cal
    FC_Cal --> FC_Rot
    FC_External --> FC_Rot
    FC_Rot --> FC_Event
    FC_Event --> FC_Telem
    FC_Telem -->|"SPI"| FC_LoRa1
    FC_LoRa1 --> LoRa_Flight
    LoRa_Flight --> LoRa_GS
    LoRa_GS --> GS_Radio
    GS_Radio --> GS_Parse
    GS_Parse --> GS_LCD
    GS_Parse --> GS_SD
    FC_SD --> SD_Flight
    FC_Telem --> GS_SD
    FC_SD --- FC_Config
    GS_SD --- GS_Settings
    SD_Flight -.- PC_Bench
    SD_Flight -.- PC_FlightPlot
    SD_Flight -.- PC_TelemPlot

    %% Deployment Recover Flow
    FC_InFlight --> FC_SD

    %% Click Events
    click FC_Main "https://github.com/sparkyvt/hpr-rocket-flight-computer/blob/V4_7_0/Main Code/HPR_Rocket_Flight_PC_V4_7.ino"
    click FC_Bus "https://github.com/sparkyvt/hpr-rocket-flight-computer/blob/V4_7_0/Main Code/Bus_Mgmt.ino"
    click FC_Internal "https://github.com/sparkyvt/hpr-rocket-flight-computer/blob/V4_7_0/Main Code/Device_Drivers.ino"
    click FC_External "https://github.com/sparkyvt/hpr-rocket-flight-computer/blob/V4_7_0/Main Code/Device_Drivers_External.ino"
    click FC_Cal "https://github.com/sparkyvt/hpr-rocket-flight-computer/blob/V4_7_0/Main Code/Calibration.ino"
    click FC_Rot "https://github.com/sparkyvt/hpr-rocket-flight-computer/blob/V4_7_0/Main Code/Rotation.ino"
    click FC_GPSconf "https://github.com/sparkyvt/hpr-rocket-flight-computer/blob/V4_7_0/Main Code/UBLOX_GNSS_Config.ino"
    click FC_Event "https://github.com/sparkyvt/hpr-rocket-flight-computer/blob/V4_7_0/Main Code/Event_Logic.ino"
    click FC_Telem "https://github.com/sparkyvt/hpr-rocket-flight-computer/blob/V4_7_0/Main Code/Telemetry.ino"
    click FC_LoRa1 "https://github.com/sparkyvt/hpr-rocket-flight-computer/blob/V4_7_0/Main Code/SX127X_Driver.ino"
    click FC_RFDx "https://github.com/sparkyvt/hpr-rocket-flight-computer/blob/V4_7_0/Main Code/RFDx_Driver.ino"
    click FC_SD "https://github.com/sparkyvt/hpr-rocket-flight-computer/blob/V4_7_0/Main Code/SD.ino"
    click FC_Pyro "https://github.com/sparkyvt/hpr-rocket-flight-computer/blob/V4_7_0/Main Code/Speed_Trig.ino"
    click FC_DevMgmt "https://github.com/sparkyvt/hpr-rocket-flight-computer/blob/V4_7_0/Main Code/Device_Mgmt.ino"
    click FC_InFlight "https://github.com/sparkyvt/hpr-rocket-flight-computer/blob/V4_7_0/Main Code/Infilght_Recover.ino"
    click FC_Config "https://github.com/sparkyvt/hpr-rocket-flight-computer/blob/V4_7_0/Main Code/Settings.txt"
    click GS_Core "https://github.com/sparkyvt/hpr-rocket-flight-computer/blob/V4_7_0/Ground Station/Telemetry_Rx_V10_2_Teensy.ino"
    click GS_Radio "https://github.com/sparkyvt/hpr-rocket-flight-computer/blob/V4_7_0/Ground Station/Radio.ino"
    click GS_GPS "https://github.com/sparkyvt/hpr-rocket-flight-computer/blob/V4_7_0/Ground Station/GPS.ino"
    click GS_LCD "https://github.com/sparkyvt/hpr-rocket-flight-computer/blob/V4_7_0/Ground Station/LCD.ino"
    click GS_Parse "https://github.com/sparkyvt/hpr-rocket-flight-computer/blob/V4_7_0/Ground Station/Parse_Packet.ino"
    click GS_SD "https://github.com/sparkyvt/hpr-rocket-flight-computer/blob/V4_7_0/Ground Station/SD_Card.ino"
    click GS_Settings "https://github.com/sparkyvt/hpr-rocket-flight-computer/blob/V4_7_0/Ground Station/Settings.txt"
    click PC_Bench "https://github.com/sparkyvt/hpr-rocket-flight-computer/blob/V4_7_0/Parser/benchTestAnalysis.py"
    click PC_FlightPlot "https://github.com/sparkyvt/hpr-rocket-flight-computer/blob/V4_7_0/Parser/plotFlightData.py"
    click PC_TelemPlot "https://github.com/sparkyvt/hpr-rocket-flight-computer/blob/V4_7_0/Parser/plotTelemetryData.py"

    %% Styles
    classDef hardware fill:#D0E1F9,stroke:#0366d6,color:#0366d6
    classDef firmware fill:#C8E6C9,stroke:#2e7d32,color:#2e7d32
    classDef pc fill:#FFE0B2,stroke:#ef6c00,color:#e65100
```
