# muhyildiz/robohexa architecture

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

- Interactive diagram: https://gitdiagram.com/muhyildiz/robohexa
- Repository: https://github.com/muhyildiz/robohexa

## Overview

##### Project type and purpose
- This is an embedded real-time control system for a hexapod robot (RoboHexa) designed to traverse rough terrain. It comprises both hardware (mechanics, PCB, sensors, actuators) and firmware (sensor drivers, PID motion control, RF communication, mapping integration).

##### Key components
- Mechanical subsystem (six‐leg chassis)
- Electrical/PCB subsystem (power management, PWM drivers, SPI/I²C bus)
- Sensors
- IMU6050 (orientation & acceleration)
- Mini limit switches (leg contact)
- LIDAR module (optional mapping)
- Actuators
- 6× MG996R servo motors
- Control & processing
- STM32 microcontroller running firmware (sensor acquisition, control loops, state machine)
- Communication
- NRF24L01 transceiver (robot ↔ wireless handheld controller)
- External operator interface (RF remote controller)

##### Relationships and data flows
- Sensors → MCU: IMU6050 via I²C, switches via GPIO, LIDAR via serial or I²C
- MCU → Actuators: PWM outputs (18 channels) drive servos
- MCU ↔ PCB: power regulation and signal routing (internal to board)
- MCU ↔ Remote controller: bidirectional packets over NRF24L01
- Firmware modules interact:
- Sensor drivers feed data to balance & gait algorithms
- PID controller issues real-time PWM commands
- RF module transmits telemetry & receives user commands
- Mapping subroutine (LIDAR data) may run on MCU or an off-board processor

##### Architectural patterns and design principles
- Modular firmware architecture:
- Hardware abstraction layer (HAL) for sensors, timers, comms
- Control layer implementing gait scheduler and PID loops
- Communication layer handling RF packets and mapping data
- Real-time control loop: fixed-rate main loop or RTOS threads
- Separation of concerns: sensing, planning, actuation, communication

##### Details
- Every bus and signal (I²C, SPI, PWM, GPIO, RF)
- Real-time feedback loops (sensor → control → actuator)
- Power domains and voltage rails
- Firmware tasks and their timing constraints (e.g., PID loop at 100 Hz, RF update at 10 Hz)

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Mechanical subsystem
    Frame["Mechanical Frame\n& Six Legs"]:::hardware

    %% PCB and MCU inside
    subgraph "Custom PCB" 
        style CustomPCB fill:#f2f2f2,stroke:#333,stroke-width:2px
        MCU["STM32 MCU\n(clock, memory, GPIO)"]:::processing
        Power["Power Regulation\n+5V, GND"]:::hardware
        PWM["PWM Drivers\n(18 Channels)"]:::hardware
        Buses["SPI / I²C Buses"]:::hardware
    end

    Frame --> CustomPCB

    Power --> MCU
    MCU --> PWM
    MCU --> Buses

    %% Firmware modules inside MCU
    subgraph "Firmware Modules" 
        HAL["Hardware Abstraction Layer"]:::firmware
        Control["Gait Scheduler & PID\n(100 Hz)"]:::firmware
        RFModule["RF Communication\n(10 Hz)"]:::firmware
        Mapping["Mapping Subroutine"]:::firmware
    end

    MCU --> HAL
    HAL --> Control
    HAL --> RFModule
    HAL --> Mapping
    Control --> PWM
    RFModule --> MCU

    %% Sensors around PCB
    subgraph Sensors
        IMU["IMU6050\n(I²C)"]:::sensor
        Switches["Limit Switches\n(GPIO)"]:::sensor
        LIDAR["LIDAR Module\n(Serial/I²C)"]:::sensor
    end

    IMU -->|"I²C"| MCU
    Switches -->|"GPIO"| MCU
    LIDAR -->|"Serial / I²C"| MCU

    %% Actuators around frame
    subgraph Actuators
        Servos["6× MG996R Servos\n(PWM)"]:::actuator
    end

    MCU -->|"PWM Outputs"| Servos

    %% Communication
    NRF["NRF24L01 Radio"]:::communication
    Remote["Remote Controller\n(RF Handheld)"]:::communication

    MCU -->|"SPI"| NRF
    NRF -->|"RF Packets"| Remote

    %% Optional external processor
    PC["External PC / Laptop\n(Heavy Mapping)"]:::external
    PC -->|"Mapping Data"| MCU

    %% Documentation
    Doc["Project Documentation"]:::doc
    click Doc "https://github.com/muhyildiz/robohexa/blob/main/README.md"

    %% Legend
    subgraph Legend
        direction LR
        SENS["Sensors"]:::sensor
        ACT["Actuators"]:::actuator
        COMM["Communication"]:::communication
        PROC["Processing"]:::processing
        FIRM["Firmware"]:::firmware
        HW["Hardware"]:::hardware
        DOCN["Documentation"]:::doc
    end

    classDef hardware fill:#cccccc,stroke:#333,stroke-width:1px
    classDef processing fill:#ffffff,stroke:#333,stroke-width:1px
    classDef firmware fill:#ffcc99,stroke:#333,stroke-width:1px
    classDef sensor fill:#99ff99,stroke:#333,stroke-width:1px
    classDef actuator fill:#ff9999,stroke:#333,stroke-width:1px
    classDef communication fill:#99ccff,stroke:#333,stroke-width:1px
    classDef external fill:#e6e6e6,stroke:#333,stroke-width:1px
    classDef doc fill:#e0b3ff,stroke:#333,stroke-width:1px
```
