# gkd-rm-lab/gkd_control architecture

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

- Interactive diagram: https://gitdiagram.com/gkd-rm-lab/gkd_control
- Repository: https://github.com/gkd-rm-lab/gkd_control

## Overview

- Third‐Party Libraries:
– Show the 3rdparty “serial” library components (both headers and source). Indicate that these modules are responsible for serial communication and provide platform abstraction (Unix/Windows).
- Hardware Interface Layer:
– Include components like “hardware” (e.g., can.cc, dji_motor.cc) and “device” modules (IMU, referee protocols, UI, RC controller, etc.). These represent the interfaces to the underlying physical devices.
- Control and Logic Layer:
– Represent the control modules such as “control” (controller.cc, pid_controller.cc, ramp.cc), “robot_controller”, and support logic (user_lib) that steer the robotic actions.
- Subsystem Modules:
– Gimbal: Include the gimbal control logic (src/gimbal) and related configuration files.
– Shooting: Represent the shooting subsystem (src/shoot) that contains bullet solving algorithms and shooting configurations.
- I/O and Communication Layer:
– Illustrate the I/O modules (src/io) such as serial_interface.cc and socket_interface.cc that handle data input and output – this ensures various external connections.
- Build & Deployment/Entry Point:
– Highlight the main entry point (src/main.cc) that integrates and starts the control loop, and emphasize the build configurations (Makefile and CMakeLists.txt) which are part of the “deployment pipeline”.

##### Relationships and Data Flow
– From the main() entry point to the robot controller.
– From the robot controller to individual subsystems (chassis, gimbal, shoot) and to I/O modules.
– Between the hardware modules and the device interfaces.
– Between control algorithms and I/O interfaces (to send commands and receive sensor data).

##### Architectural Patterns and Design Principles
- Modular Layering: Show how responsibilities are separated into hardware abstraction, control logic, and communication interfaces.
- Clear Separation of Concerns: Ensure that modules like device communication, control algorithms, and hardware drivers are clearly distinguished.
- Integration of Third-Party Code: Illustrate that the serial communication library (3rdparty) is integrated into the I/O layer.
- Platform-Dependent Implementation: Note that certain parts of the serial library handle Unix vs. Windows specifics.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Build & Deployment
    subgraph "Build & Deployment"
        A1["Main Entry (src/main.cc)"]:::build
        A2["Makefile"]:::build
        A3["CMakeLists.txt"]:::build
    end

    %% Control and Logic Layer
    subgraph "Control and Logic Layer"
        B1["Robot Controller"]:::control
        B2["Control Algorithms"]:::control
        B3["Support Logic"]:::control
    end

    %% Subsystem Modules
    subgraph "Subsystem Modules"
        C1["Chassis Subsystem"]:::subsystem
        C2["Gimbal Subsystem"]:::subsystem
        C3["Shooting Subsystem"]:::subsystem
    end

    %% I/O and Communication Layer
    subgraph "I/O and Communication Layer"
        D1["Serial Interface Module"]:::io
        D2["Socket Interface Module"]:::io
    end

    %% Hardware Interface Layer
    subgraph "Hardware Interface Layer"
        E1["Hardware Drivers"]:::hardware
        E2["IMU Interface"]:::hardware
        E3["RC Controller Interface"]:::hardware
        E4["Referee Interface"]:::hardware
    end

    %% Third-Party Libraries
    subgraph "Third-Party Libraries"
        F1["Serial Lib Headers"]:::thirdParty
        F2["Serial Lib Sources"]:::thirdParty
    end

    %% Connections
    A1 -->|"init"| B1
    B1 -->|"commands"| B2
    B1 ---|"support"| B3

    B2 -->|"control"| C1
    B2 -->|"control"| C2
    B2 -->|"control"| C3

    B1 -->|"data"| D1
    B1 -->|"data"| D2

    D1 ---|"uses"| F1
    D1 ---|"uses"| F2

    E1 -->|"interacts"| E2
    E1 -->|"interacts"| E3
    E1 -->|"interacts"| E4

    E2 ---|"sensors"| B2
    E3 ---|"sensors"| B2
    E4 ---|"sensors"| B2

    %% Click Events
    click F1 "https://github.com/gkd-rm-lab/gkd_control/tree/main/3rdparty/include/serial"
    click F2 "https://github.com/gkd-rm-lab/gkd_control/tree/main/3rdparty/src-serial"
    click E1 "https://github.com/gkd-rm-lab/gkd_control/tree/main/src/hardware"
    click E2 "https://github.com/gkd-rm-lab/gkd_control/blob/main/src/device/imu.cc"
    click E3 "https://github.com/gkd-rm-lab/gkd_control/blob/main/src/device/rc_controller.cc"
    click E4 "https://github.com/gkd-rm-lab/gkd_control/tree/main/src/device/referee"
    click B2 "https://github.com/gkd-rm-lab/gkd_control/tree/main/src/control"
    click B1 "https://github.com/gkd-rm-lab/gkd_control/blob/main/include/robot_controller.hpp"
    click B3 "https://github.com/gkd-rm-lab/gkd_control/blob/main/include/user_lib.hpp"
    click C1 "https://github.com/gkd-rm-lab/gkd_control/tree/main/include/chassis"
    click C2 "https://github.com/gkd-rm-lab/gkd_control/tree/main/include/gimbal"
    click C3 "https://github.com/gkd-rm-lab/gkd_control/tree/main/include/shoot"
    click D1 "https://github.com/gkd-rm-lab/gkd_control/blob/main/include/serial_interface.hpp"
    click D2 "https://github.com/gkd-rm-lab/gkd_control/blob/main/include/socket_interface.hpp"
    click A1 "https://github.com/gkd-rm-lab/gkd_control/blob/main/src/main.cc"
    click A2 "https://github.com/gkd-rm-lab/gkd_control/tree/main/Makefile"
    click A3 "https://github.com/gkd-rm-lab/gkd_control/blob/main/CMakeLists.txt"

    %% Styles
    classDef thirdParty fill:#F8AFA6,stroke:#333,stroke-width:2px;
    classDef hardware fill:#FCEABB,stroke:#333,stroke-width:2px;
    classDef control fill:#AED6F1,stroke:#333,stroke-width:2px;
    classDef subsystem fill:#D5F5E3,stroke:#333,stroke-width:2px;
    classDef io fill:#E8DAEF,stroke:#333,stroke-width:2px;
    classDef build fill:#F9E79F,stroke:#333,stroke-width:2px;
```
