# beagleboard/librobotcontrol architecture

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

- Interactive diagram: https://gitdiagram.com/beagleboard/librobotcontrol
- Repository: https://github.com/beagleboard/librobotcontrol

## Overview

##### Project Context and Scope
- Remember that the core library is the set of C API functions and low‐level hardware control routines that enable robot control on embedded systems (like the Robotics Cape and BeagleBone Blue).
- We’re focusing solely on the library-related components (the “library” folder) from branch v1.1 – disregarding examples, firmware, services, and other peripheral elements.

##### And Isolate the Main Components
For the core library, extract these components from the file tree’s “library” directory:
a. API / Public Interface:
– The header files under library/include/rc and its subdirectories.
– They define the API for the various modules and provide the contracts for client code.
b. Hardware Interface Modules:
– Locate the low-level I/O routines in library/src/io (ADC, GPIO, I2C, SPI, UART, PWM).
– These modules abstract communication with the hardware peripherals.
c. Mathematical and Control Algorithms:
– Under library/src/math, include modules such as algebra, filter, kalman, matrix, polynomial, and vector operations.
– This set supports the discrete time feedback control and numerical operations necessary for robot control.
d. Sensor and Actuator Integration:
– Components handling sensor data such as the MPU integration (library/src/mpu) and motor, encoder, and servo controls (library/src/motor, library/src/encoder, etc.).
e. Communication and Protocol Layer:
– MAVLink support is evident from both header and source files in the “library/include/rc/mavlink” folder and its corresponding implementations.
f. General Utilities and Core Services:
– Common functionalities such as CPU timing, thread management (pthread), start/stop routines, and version control (library/src/time, library/src/start_stop, etc.).

##### Depicting Component Relationships & Data Flow
– Show the API/Public Interface at the top or center. This is the entry point for external calls.
– Illustrate data or control flow between the math processing components and sensor modules since sensor data is processed and then passed into control routines.
– Indicate that the communication layer (MAVLink) interfaces both with the API and directly with hardware/sensor modules for telemetry and control commands.

##### Architectural Patterns
– Emphasize the layered architecture:
- Top Layer: API / Public Interface (header files that define the library contracts).
- Middle Layer: Implementation modules that handle hardware I/O and mathematical processing.
- Lower Layer: Hardware interaction or communication drivers.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% API / Public Interface
    subgraph "API / Public Interface"
        API["API/Public Interface"]:::api
    end

    %% Hardware Interface Modules (Rounded Boxes)
    subgraph "Hardware Interface Modules"
        IO_ADC("ADC"):::hardware
        IO_GPIO("GPIO"):::hardware
        IO_I2C("I2C"):::hardware
        IO_SPI("SPI"):::hardware
        IO_UART("UART"):::hardware
        IO_PWM("PWM"):::hardware
    end

    %% Mathematical and Control Algorithms (Ovals)
    subgraph "Math and Control Algorithms"
        MATH_ALG(("Algebra")):::math
        MATH_FILTER(("Filter")):::math
        MATH_KALMAN(("Kalman")):::math
        MATH_MATRIX(("Matrix")):::math
        MATH_POLYNOMIAL(("Polynomial")):::math
        MATH_VECTOR(("Vector")):::math
    end

    %% Sensor & Actuator Integration (Diamonds)
    subgraph "Sensor & Actuator Integration"
        SENSOR_MPU{"MPU"}:::sensor
        SENSOR_MOTOR{"Motor"}:::sensor
        SENSOR_ENCODER{"Encoder"}:::sensor
    end

    %% Communication and Protocol Layer (Rectangles with highlight)
    subgraph "Communication and Protocol Layer"
        COM_MAV_HEADERS["MAVLink Headers"]:::communication
        COM_MAV_IMPL["MAVLink Implementation"]:::communication
    end

    %% General Utilities and Core Services (Rectangles)
    subgraph "General Utilities and Core Services"
        UTIL_TIMING["Timing"]:::utilities
        UTIL_STARTSTOP["Start/Stop"]:::utilities
        UTIL_THREAD["Thread Management"]:::utilities
    end

    %% Relationships from API/Public Interface to Modules
    API -->|"calls"| IO_ADC
    API -->|"calls"| IO_GPIO
    API -->|"calls"| IO_I2C
    API -->|"calls"| IO_SPI
    API -->|"calls"| IO_UART
    API -->|"calls"| IO_PWM

    API -->|"calls"| MATH_ALG
    API -->|"calls"| MATH_FILTER
    API -->|"calls"| MATH_KALMAN
    API -->|"calls"| MATH_MATRIX
    API -->|"calls"| MATH_POLYNOMIAL
    API -->|"calls"| MATH_VECTOR

    API -->|"calls"| SENSOR_MPU
    API -->|"calls"| SENSOR_MOTOR
    API -->|"calls"| SENSOR_ENCODER

    API -->|"calls"| COM_MAV_HEADERS
    API -->|"calls"| COM_MAV_IMPL

    API -->|"calls"| UTIL_TIMING
    API -->|"calls"| UTIL_STARTSTOP
    API -->|"calls"| UTIL_THREAD

    %% Data flow from Sensor Modules to Math Algorithms
    SENSOR_MPU -->|"data"| MATH_FILTER
    SENSOR_MOTOR -->|"data"| MATH_KALMAN
    SENSOR_ENCODER -->|"data"| MATH_MATRIX

    %% Communication layer interacting with Hardware and Sensor modules
    COM_MAV_IMPL -->|"communicates"| IO_UART
    COM_MAV_HEADERS -->|"sends"| SENSOR_MPU
    COM_MAV_IMPL -->|"sends"| SENSOR_MOTOR

    %% Click Events for API / Public Interface
    click API "https://github.com/beagleboard/librobotcontrol/tree/main/library/include/rc"

    %% Click Events for Hardware Interface Modules
    click IO_ADC "https://github.com/beagleboard/librobotcontrol/blob/main/library/src/io/adc.c"
    click IO_GPIO "https://github.com/beagleboard/librobotcontrol/blob/main/library/src/io/gpio.c"
    click IO_I2C "https://github.com/beagleboard/librobotcontrol/blob/main/library/src/io/i2c.c"
    click IO_SPI "https://github.com/beagleboard/librobotcontrol/blob/main/library/src/io/spi.c"
    click IO_UART "https://github.com/beagleboard/librobotcontrol/blob/main/library/src/io/uart.c"
    click IO_PWM "https://github.com/beagleboard/librobotcontrol/blob/main/library/src/io/pwm.c"

    %% Click Events for Mathematical and Control Algorithms
    click MATH_ALG "https://github.com/beagleboard/librobotcontrol/blob/main/library/src/math/algebra.c"
    click MATH_FILTER "https://github.com/beagleboard/librobotcontrol/blob/main/library/src/math/filter.c"
    click MATH_KALMAN "https://github.com/beagleboard/librobotcontrol/blob/main/library/src/math/kalman.c"
    click MATH_MATRIX "https://github.com/beagleboard/librobotcontrol/blob/main/library/src/math/matrix.c"
    click MATH_POLYNOMIAL "https://github.com/beagleboard/librobotcontrol/blob/main/library/src/math/polynomial.c"
    click MATH_VECTOR "https://github.com/beagleboard/librobotcontrol/blob/main/library/src/math/vector.c"

    %% Click Events for Sensor & Actuator Integration
    click SENSOR_MPU "https://github.com/beagleboard/librobotcontrol/tree/main/library/src/mpu"
    click SENSOR_MOTOR "https://github.com/beagleboard/librobotcontrol/tree/main/library/src/motor"
    click SENSOR_ENCODER "https://github.com/beagleboard/librobotcontrol/blob/main/library/src/encoder.c"

    %% Click Events for Communication and Protocol Layer
    click COM_MAV_HEADERS "https://github.com/beagleboard/librobotcontrol/tree/main/library/include/rc/mavlink"
    click COM_MAV_IMPL "https://github.com/beagleboard/librobotcontrol/blob/main/library/src/mavlink_udp.c"

    %% Click Events for General Utilities and Core Services
    click UTIL_TIMING "https://github.com/beagleboard/librobotcontrol/blob/main/library/src/time.c"
    click UTIL_STARTSTOP "https://github.com/beagleboard/librobotcontrol/blob/main/library/src/start_stop.c"
    click UTIL_THREAD "https://github.com/beagleboard/librobotcontrol/blob/main/library/src/pthread.c"

    %% Styles
    classDef api fill:#ADD8E6,stroke:#000,stroke-width:2px;
    classDef hardware fill:#90EE90,stroke:#000,stroke-width:2px,stroke-dasharray: 5,5;
    classDef math fill:#FFFF99,stroke:#000,stroke-width:2px;
    classDef sensor fill:#FFB6C1,stroke:#000,stroke-width:2px;
    classDef communication fill:#F08080,stroke:#000,stroke-width:2px;
    classDef utilities fill:#DDA0DD,stroke:#000,stroke-width:2px;
```
