# chrgri/diy-sim-racing-ffb-pedal architecture

> Architecture diagram of the GitHub repository chrgri/diy-sim-racing-ffb-pedal, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/chrgri/diy-sim-racing-ffb-pedal
- Repository: https://github.com/chrgri/diy-sim-racing-ffb-pedal

## Overview

##### Major components and layers
- Hardware Layer:
- Mechanical and electrical aspects (as documented in the separate “Mechanical Design” repo).
- Sensor interfaces: load cell, pedal geometry measurement, force feedback sensors.
- Actuators: High-power servo (or stepper motor in some variants) driven via dedicated power/control boards.
- Custom PCBs and wiring (as seen in the “Wiring” and “OTA” folders).
- Embedded Firmware Layer (ESP32/ESP32_master directories):
- Core firmware modules (found in ESP32/src and ESP32_master/src) including:
- Controller (handles overall control logic)
- Signal processing modules such as CycleTimer, SignalFilter, SignalFilter_2nd_order
- Sensor interfacing modules (LoadCell, PedalGeometry, etc.)
- Feedback modules (ForceCurve, Modbus, OTA update routines, etc.)
- Communication and connectivity modules (ESPNOW, USB and wireless interfaces)
- Communication and Integration Layer:
- SimHub integration: a PC-side plugin (SimHubPlugin directory) that communicates with the pedal.
- OTA update scripts and helper modules (in Helper and OTA folders).
- Possibly external simulation/control board interfaces (e.g., Fanatec integration, as well as stepper parameterization tools and test modules for validation).

##### Lay out the relationships and data flows
- The sensors (Load cell, pedal geometry sensors, etc.) send raw signals to the microcontroller.
- The firmware’s signal processing modules apply filtering (using SignalFilter or 2nd order algorithms), and the processed data is passed to the Controller.
- The Controller uses control loop strategies (possibly referenced in the CycleTimer and ForceCurve modules) to compute the appropriate feedback force.
- The computed control commands are then sent to the actuator drivers (StepperWithLimits/Servo controllers) on the hardware PCB.
- In parallel, communication modules handle bidirectional communication with the PC:
– Sending telemetry and pedal status to the PC (for simulation feedback).
– Receiving calibration settings / profile updates (e.g., through Modbus protocols or USB commands).
– Supporting OTA updates and version string generation (using the Helper scripts, for instance).
- At the PC level, the SimHub plugin uses the received data to render additional force feedback effects in conjunction with in-game data.

##### Architectural patterns and design principles
- Modular design: The firmware is divided into clearly separated modules (Controller, Sensor Interfaces, Signal Filtering, Communication, etc.) enabling clear layering.
- Feedback and control loop: There is an inherent closed-loop control structure where sensor input, signal processing, and actuator commands are all tied together.
- Hardware abstraction: Separate layers abstract low-level sensor handling and actuator control, making it easier to swap or upgrade hardware components.

##### Relevant technologies, frameworks, or libraries
- Arduino/PlatformIO environment for the firmware.
- ESP32-specific libraries and components (note: directories indicate PlatformIO and Arduino projects).
- Custom libraries for signal filtering, interpolation (e.g., InterpolationLib in the Arduino_outdated/lib folder) and possibly a fast stepper control library (FastAccelStepper).
- SimHub Plugin framework on the PC side (written in C#).

##### Essential elements
- Hardware Subsystem:
- Sensors – load cell, pedal position sensor.
- Actuators – servo/stepper and their drivers.
- Supporting circuitry – power boards, PCBs, wiring (from the Wiring and OTA sections).
- Embedded Firmware Subsystem:
- Core Controller module.
- Signal Processing (Filters, CycleTimer).
- Sensor Interface Modules.
- Actuator control modules (StepperWithLimits, ForceCurve).
- Communication Interfaces (USB/Wireless, OTA routines, Modbus).
- Boot and version management (Helper scripts for version string, build directories).
- PC Integration Subsystem:
- SimHub Plugin – handles user interface, telemetry, and effect profiles.
- Firmware Updater (OTA procedures).
- Annotations and Legends:
- Interactions (e.g., “Control Loop Feedback”, “Profile Data Transfer”, “Firmware Update”).

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Hardware Layer
    subgraph "Hardware Layer"
        HD1["Mechanical Design & PCB"]
        HD2["Wiring"]
        HD3["Wiring/Esp32_V3"]
        HD4["Wiring/Esp32S3_V4"]
        HD5["Wiring/PowerPcb"]
        HD6["Sensors (Load Cell, Pedal Geometry)"]
        HD7["Actuator Drivers (Servo/Stepper)"]
    end

    %% Embedded Firmware Layer
    subgraph "Embedded Firmware Layer"
        subgraph "Core Firmware"
            CF1["Controller & Signal Processing"]
            CF2["Sensor Interface Modules"]
            CF3["Actuator Control Modules"]
            CF4["Firmware Source"]
            CF5["Firmware Headers"]
        end
        subgraph "Communication & OTA"
            COM1["OTA Routines"]
            COM2["Helper Scripts"]
            COM3["Communication Interfaces"]
        end
    end

    %% PC Integration Layer
    subgraph "PC Integration Layer"
        PC1["SimHub Plugin Interface"]
        PC2["Simhub Dashboard"]
    end

    %% Testing & Calibration
    TV1["Testing & Validation"]
    TV2["Stepper Calibration Tools"]

    %% Connections within Hardware Layer
    HD1 -->|"informs"| HD2
    HD2 -->|"routes to"| HD6
    HD2 -->|"routes to"| HD7

    %% Hardware to Firmware connections
    HD6 -->|"sensor data"| CF2
    CF2 -->|"processed data"| CF1
    CF1 -->|"actuation command"| CF3
    CF3 -->|"control signal"| HD7

    %% Firmware internal connections
    CF4 --- CF1
    CF5 --- CF1

    %% Communication with PC Integration
    COM3 <-->|"telemetry|profile"| PC1
    COM2 --- COM1

    %% Connections for Testing & Calibration
    CF2 -->|"test signals"| TV1
    HD7 -->|"calibration"| TV2

    %% Click Events
    click HD1 "https://github.com/chrgri/diy-sim-racing-ffb-pedal/blob/main/Design/MechanicalDesign.md"
    click HD2 "https://github.com/chrgri/diy-sim-racing-ffb-pedal/tree/main/Wiring"
    click HD3 "https://github.com/chrgri/diy-sim-racing-ffb-pedal/tree/main/Wiring/Esp32_V3"
    click HD4 "https://github.com/chrgri/diy-sim-racing-ffb-pedal/tree/main/Wiring/Esp32S3_V4"
    click HD5 "https://github.com/chrgri/diy-sim-racing-ffb-pedal/tree/main/Wiring/PowerPcb"
    click CF4 "https://github.com/chrgri/diy-sim-racing-ffb-pedal/tree/main/ESP32/src"
    click CF5 "https://github.com/chrgri/diy-sim-racing-ffb-pedal/tree/main/ESP32/include"
    click COM1 "https://github.com/chrgri/diy-sim-racing-ffb-pedal/tree/main/OTA"
    click COM2 "https://github.com/chrgri/diy-sim-racing-ffb-pedal/blob/main/Helper/obtainVersionString.py"
    click PC1 "https://github.com/chrgri/diy-sim-racing-ffb-pedal/tree/main/SimHubPlugin"
    click PC2 "https://github.com/chrgri/diy-sim-racing-ffb-pedal/tree/main/SimhubDash"
    click TV1 "https://github.com/chrgri/diy-sim-racing-ffb-pedal/tree/main/Validation"
    click TV2 "https://github.com/chrgri/diy-sim-racing-ffb-pedal/tree/main/StepperParameterization"

    %% Styles
    class HD1,HD2,HD3,HD4,HD5,HD6,HD7 hardware
    class CF1,CF2,CF3,CF4,CF5 firmware
    class COM1,COM2,COM3 communication
    class PC1,PC2 pc
    class TV1,TV2 testing

    %% Class Definitions
    classDef hardware fill:#FFD700,stroke:#333,stroke-width:2px;
    classDef firmware fill:#87CEFA,stroke:#333,stroke-width:2px;
    classDef communication fill:#FFB6C1,stroke:#333,stroke-width:2px;
    classDef pc fill:#98FB98,stroke:#333,stroke-width:2px;
    classDef testing fill:#D3D3D3,stroke:#333,stroke-width:2px;
```
