# fipatech/cdfr2025 architecture

> Architecture diagram of the GitHub repository fipatech/cdfr2025, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-17). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/fipatech/cdfr2025
- Repository: https://github.com/fipatech/cdfr2025

## Overview

##### Project type and purpose
- This is a robotics control system (“CDFR2025”) consisting of:
- Embedded firmware running on an STM32F4 microcontroller (firmware/…​)
- A ROS 2-based software stack on a companion computer (software/ros2_ws/…​)
- A Node.js server component (software/server/…​)
- Purpose: low-level real-time control, sensor processing, UI on the device; high-level strategy & perception on ROS 2; web/API access via Node.js.

##### File structure
- firmware/robot_firmware
- Core C code under Core/Inc & Core/Src
- FreeRTOS tasks
- STM32 HAL and BSP drivers under Drivers/…
- TouchGFX UI middleware under Middlewares/ST/touchgfx
- Build project files for EWARM, MDK, CubeIDE, GCC
- software/ros2_ws
- bringup: launch ROS graph
- imu_fusion: sensor‐fusion node (likely IMU + odometry)
- match_control: high-level strategy loader (YAML-driven)
- rplidar_ros2: LiDAR driver
- uart_bridge: serial↔ROS bridge
- software/server
- index.js: Node.js backend (REST/WebSocket API)

##### README
- No further architecture description there, so inference from code.

##### Main components & interactions
a. Embedded MCU
- Hardware: IMU, encoders (odometry), servos, UART, LCD+touch
- Firmware stacks:
– STM32 HAL + BSP → low-level drivers
– FreeRTOS → task scheduling
– Core modules: odometry, command_manager, strategy_manager, servo_controller, uart_handler
– TouchGFX MVC UI layer
b. Companion Computer (ROS 2)
- Nodes:
– uart_bridge: publishes sensor topics, subscribes command topics
– imu_fusion: fuses IMU + odometry → filtered pose
– rplidar_ros2: publishes LiDAR scans
– match_control: loads strategy YAML, reacts to sensor topics → publishes setpoints
- Launch: bringup.launch.py to start the graph
c. Node.js Server
- Exposes APIs or websockets for monitoring & control
- Connects either directly to ROS 2 (via rosbridge) or uses custom messaging

##### Architectural patterns & principles
- Embedded: layered architecture (HAL → middleware → application logic → UI)
- Real-time OS with tasks communicating via queues/circular buffers
- TouchGFX: Model-View-Presenter pattern
- ROS 2: distributed micro-services (nodes) communicating via topics/services
- Node.js: event-driven, non-blocking server

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Hardware Layer
    subgraph "Hardware"
        IMU["IMU Sensor"]:::hardware
        Encoders["Encoders"]:::hardware
        Servos["Servos"]:::hardware
        LCD["LCD + Touchscreen"]:::hardware
    end

    %% Embedded Firmware Layer
    subgraph "STM32F4 MCU (Embedded Firmware)"
        subgraph "Drivers & Middleware"
            HALDrivers["STM32 HAL Drivers"]:::firmware
            BSPDrivers["BSP Drivers"]:::firmware
            CMSIS["CMSIS Device Headers"]:::firmware
            FreeRTOS["FreeRTOS Middleware"]:::firmware
        end
        subgraph "Application Modules"
            CoreModules["Core Application Modules"]:::firmware
            TouchGFX["TouchGFX UI"]:::firmware
        end
    end

    %% ROS 2 Layer
    subgraph "ROS 2 on Companion PC"
        Bringup["bringup.launch.py"]:::ros
        UartBridge["uart_bridge"]:::ros
        ImuFusion["imu_fusion"]:::ros
        Rplidar["rplidar_ros2"]:::ros
        MatchControl["match_control"]:::ros
        subgraph "ROS Topics"
            OdometryTopic[(/odometry)]:::topic
            ImuTopic[(/imu)]:::topic
            ScanTopic[(/scan)]:::topic
            SetpointTopic[(/setpoints)]:::topic
        end
    end

    %% Server & Clients Layer
    subgraph "Node.js Server & Clients"
        NodeServer["Node.js Server"]:::server
        Client["Web UI / Dashboard"]:::server
    end

    %% Connections: Hardware -> Firmware
    IMU -->|"raw IMU data"| CoreModules
    Encoders -->|"encoder data"| CoreModules
    CoreModules -->|"servo commands"| Servos
    CoreModules -->|"UI data"| TouchGFX
    TouchGFX -->|"render frames"| LCD
    LCD -->|"touch events"| TouchGFX

    %% Drivers & Middleware to Core
    HALDrivers --> CoreModules
    BSPDrivers --> CoreModules
    CMSIS --> CoreModules
    FreeRTOS --> CoreModules

    %% Firmware <-> ROS via UART
    CoreModules -->|"UART"| UartBridge
    UartBridge --> OdometryTopic
    UartBridge --> ImuTopic
    SetpointTopic --> UartBridge

    %% ROS Bringup orchestration
    Bringup --> UartBridge
    Bringup --> ImuFusion
    Bringup --> Rplidar
    Bringup --> MatchControl

    %% ROS data flows
    ImuTopic --> ImuFusion
    OdometryTopic --> ImuFusion
    ImuFusion --> OdometryTopic
    Rplidar --> ScanTopic
    OdometryTopic --> MatchControl
    ImuTopic --> MatchControl
    ScanTopic --> MatchControl
    MatchControl --> SetpointTopic

    %% ROS <-> Server
    OdometryTopic --> NodeServer
    ImuTopic --> NodeServer
    ScanTopic --> NodeServer
    SetpointTopic --> NodeServer

    %% Clients <-> Server
    Client -->|"REST/WebSocket"| NodeServer
    NodeServer --> Client

    %% Click events
    click CoreModules "https://github.com/fipatech/cdfr2025/tree/software/firmware/robot_firmware/Core"
    click HALDrivers "https://github.com/fipatech/cdfr2025/tree/software/firmware/robot_firmware/Drivers/STM32F4xx_HAL_Driver"
    click BSPDrivers "https://github.com/fipatech/cdfr2025/tree/software/firmware/robot_firmware/Drivers/BSP/Components"
    click CMSIS "https://github.com/fipatech/cdfr2025/tree/software/firmware/robot_firmware/Drivers/CMSIS/Device/ST/STM32F4xx/Include"
    click FreeRTOS "https://github.com/fipatech/cdfr2025/tree/software/firmware/robot_firmware/Middlewares/Third_Party/FreeRTOS"
    click TouchGFX "https://github.com/fipatech/cdfr2025/tree/software/firmware/robot_firmware/Middlewares/ST/touchgfx"
    click Bringup "https://github.com/fipatech/cdfr2025/blob/software/software/ros2_ws/src/bringup/launch/bringup.launch.py"
    click ImuFusion "https://github.com/fipatech/cdfr2025/tree/software/software/ros2_ws/src/imu_fusion"
    click Rplidar "https://github.com/fipatech/cdfr2025/tree/software/software/ros2_ws/src/rplidar_ros2"
    click UartBridge "https://github.com/fipatech/cdfr2025/blob/software/software/ros2_ws/src/uart_bridge/src/uart_bridge.cpp"
    click MatchControl "https://github.com/fipatech/cdfr2025/blob/software/software/ros2_ws/src/match_control/src/match_control.cpp"
    click NodeServer "https://github.com/fipatech/cdfr2025/blob/software/software/server/index.js"

    %% Styles
    classDef hardware fill:#9f6,stroke:#333,stroke-width:1px
    classDef firmware fill:#6cf,stroke:#333,stroke-width:1px
    classDef ros fill:#f90,stroke:#333,stroke-width:1px
    classDef server fill:#c6f,stroke:#333,stroke-width:1px
    classDef topic fill:#eee,stroke:#666,stroke-width:1px,stroke-dasharray: 4 2
```
