# adimogli2/airobot architecture

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

- Interactive diagram: https://gitdiagram.com/adimogli2/airobot
- Repository: https://github.com/adimogli2/airobot

## Overview

##### Main Components
- Hardware Devices: Represent the physical components such as the Rev Robotics Expansion Hub, motorized wheels (mecanum wheels), and the FTC chassis. Although these are external to the software, they are critical to the overall system.
- Communication & Control Layers:
- HTTP Server: The “src/main/java/AIRobot/HttpServer” package contains handlers for various HTTP requests (e.g., EchoGetHandler, EchoPostHandler, RootHandler). This server is the communication bridge between the Driver Station (MacBook) and the robot’s control system.
- Command Processing: The “src/main/java/AIRobot/commands” package defines different commands (e.g., PingCommand, MotorPowerCommand, etc.) for handling robot operations, translating external requests into actionable instructions.
- Device Utilities and Hardware Abstraction: The “src/main/java/AIRobot/DeviceUtil” and “src/main/java/AIRobot/devices” packages encapsulate interactions with the motors and other hardware components.
- USB Interface: The “src/main/java/AIRobot/usb” package (with classes like UsbInterface and TimeWindow) deals with the details of communicating with the Expansion Hub using USB.
- Utility Components: The “src/main/java/AIRobot/util” package includes helper classes for buffering, message handling, and error/exception management (e.g., BulkPacketBuffer, ReadBufferWorker, RobotCoreException).

##### Relationships and Interactions
- The Driver Station sends commands via HTTP (over Wi-Fi) to the Raspberry Pi.
- The HTTP server component receives these requests and routes them to the corresponding command handlers.
- Command handlers (located in the “commands” package) interpret the instructions and trigger actions in the device abstraction layer.
- The DeviceUtil and devices packages then translate high-level commands into lower-level control signals for the motors and other devices.
- The USB interface bridges these command signals to the physical Expansion Hub, managing the communication protocols.
- Utility classes support reliable data handling and buffering across communication and hardware interfaces.

##### Architectural Patterns and Design Principles
- Layered Architecture: The software is organized into several layers (HTTP communication, command processing, device abstraction, and hardware interfacing).
- Separation of Concerns: Each package and component (commands, utilities, device management) is separated so that each handles distinct responsibilities.
- Modular Design: With clearly defined packages (for commands, USB operations, and utilities), the system is designed to be modular and extensible.
- Integration with External Tools: The system leverages open-source projects like OpenRC-Turbo and DeepPiCar to manage the hardware interface and model training aspects.

##### Relevant Technologies, Frameworks, and Libraries
- Java (the primary language)
- Maven (build and dependency management, as indicated by pom.xml)
- An embedded HTTP server (for communication on the Raspberry Pi)
- USB communication protocols (custom reverse-engineered commands for the Rev Robotics Expansion Hub)
- Deep learning model training (for self-driving functionality, though that portion might be integrated externally with Python on the Raspberry Pi)
- External open-source projects like OpenRC-Turbo and DeepPiCar which helped inform the system design

## Diagram (Mermaid)

```mermaid
graph TD
    %% Global External Entities
    DS["Driver Station (MacBook)"]:::external

    %% Internal Software Layers
    HS["HTTP Server\n(AIRobot/HttpServer)"]:::http
    CP["Command Processing\n(AIRobot/commands)"]:::cmd
    UC["Utility Components\n(AIRobot/util)"]:::util
    DU["Device Utilities\n(AIRobot/DeviceUtil)"]:::device
    HA["Hardware Abstraction\n(AIRobot/devices)"]:::device
    UI["USB Interface\n(AIRobot/usb)"]:::usb

    %% Physical Hardware Layer
    HW["Physical Robotics Hardware\n(FTC Chassis, Mecanum Wheels, Rev Robotics Expansion Hub)"]:::hardware

    %% Data Flow Connections
    DS -->|"HTTP-request"| HS
    HS -->|"routes"| CP
    CP -->|"invokes"| DU
    CP -->|"utilizes"| UC
    DU -->|"translates"| HA
    HA -->|"communicatesViaUSB"| UI
    UI -->|"controls"| HW

    %% Click Events for Component Mapping
    click HS "https://github.com/adimogli2/airobot/tree/main/src/main/java/AIRobot/HttpServer"
    click CP "https://github.com/adimogli2/airobot/tree/main/src/main/java/AIRobot/commands"
    click DU "https://github.com/adimogli2/airobot/tree/main/src/main/java/AIRobot/DeviceUtil"
    click HA "https://github.com/adimogli2/airobot/tree/main/src/main/java/AIRobot/devices"
    click UI "https://github.com/adimogli2/airobot/tree/main/src/main/java/AIRobot/usb"
    click UC "https://github.com/adimogli2/airobot/tree/main/src/main/java/AIRobot/util"

    %% Styles
    classDef external fill:#ffcc00,stroke:#333,stroke-width:2px
    classDef http fill:#aaddff,stroke:#333,stroke-width:2px
    classDef cmd fill:#ddffdd,stroke:#333,stroke-width:2px
    classDef device fill:#ffdddd,stroke:#333,stroke-width:2px
    classDef usb fill:#ddccff,stroke:#333,stroke-width:2px
    classDef util fill:#ffffcc,stroke:#333,stroke-width:2px
    classDef hardware fill:#d9d9d9,stroke:#333,stroke-width:2px
```
