# mgagvani/apriltag-localization-frc architecture

> Architecture diagram of the GitHub repository mgagvani/apriltag-localization-frc, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2024-12-27). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/mgagvani/apriltag-localization-frc
- Repository: https://github.com/mgagvani/apriltag-localization-frc

## Overview

##### Hardware Layer
- OAK Camera
- Jetson (Processing Unit)
- FRC Robot
- Network Switch

##### Software Components
Main Processing Pipeline:
- AprilTag Detection Module (detect_apriltag.py)
- SLAM Processing Module (slam_apriltag.py)
- Tag Localization Module (tag_localizer.py)
- Utilities (utils.py)

##### Data Flow Components
- Configuration Management (config_converter.py)
- Log Visualization (log_visualizer.py)
- Configuration Files (apriltag_configs/)

##### External Dependencies
- OpenCV
- DepthAI
- Spectacular AI SDK
- pupil_apriltags
- NetworkTables (FRC Communication)

- Input Layer  |

- Processing Layer|

- Output Layer   |

##### Input Layer should show
- OAK Camera
- Configuration Files

##### Processing Layer should show
- AprilTag Detection Pipeline
- SLAM Processing
- Calculation

##### Output Layer should show
- NetworkTables Communication
- Logging System
- Visualization Tools

Key Relationships to Highlight:

##### Data Flow
- Camera → Detection → SLAM → Position Calculation → NetworkTables

##### Configuration Management
- How apriltag_configs/ feeds into the main processing pipeline

##### Monitoring and Debugging
- How logging and visualization tools connect to the main pipeline

Special Considerations:

##### Real-time Processing
- Real-time nature of the system with appropriate symbols
- FPS constraints mentioned in the README (20-30 FPS)

##### Coordinate Systems
- A small coordinate system reference showing:
- Camera-relative coordinates
- Field-relative coordinates
- AprilTag positioning

##### Error Handling
- Fallback paths when AprilTags aren't detected
- Initialization requirements (AprilTag presence at startup)

- Blue: Core processing components
- Green: Input/sensor components
- Yellow: Configuration components
- Red: Critical paths/dependencies
- Gray: External services/dependencies

- Critical connection points
- Coordinate system references

Level of Detail:
- AprilTag detection pipeline
- SLAM processing details
- Network communication flow

## Diagram (Mermaid)

```mermaid
graph TB
    %% Style Definitions
    classDef hardware fill:#90EE90,stroke:#333,stroke-width:2px
    classDef processing fill:#ADD8E6,stroke:#333,stroke-width:2px
    classDef config fill:#FFE4B5,stroke:#333,stroke-width:2px
    classDef external fill:#D3D3D3,stroke:#333,stroke-width:2px
    classDef output fill:#FFA07A,stroke:#333,stroke-width:2px
    
    %% Hardware Layer
    subgraph Hardware
        OAK[OAK Camera]:::hardware
        JETSON[Jetson Processing Unit]:::hardware
        ROBOT[FRC Robot]:::hardware
        SWITCH[Network Switch]:::hardware
    end

    %% Input Layer
    subgraph Input
        CONFIG[Configuration Files]:::config
        COMP_CONFIG[Competition Configs]:::config
    end

    %% Processing Layer
    subgraph Processing
        DETECT[AprilTag Detection]:::processing
        SLAM[SLAM Processing]:::processing
        TAG_LOC[Tag Localization]:::processing
        UTILS[Utilities]:::processing
    end

    %% External Dependencies
    subgraph Dependencies
        OPENCV[OpenCV]:::external
        DEPTHAI[DepthAI]:::external
        SAI[Spectacular AI SDK]:::external
        PUPIL[pupil_apriltags]:::external
        NT[NetworkTables]:::external
    end

    %% Output and Monitoring
    subgraph Output
        LOG_VIS[Log Visualization]:::output
        LOGGING[Logging System]:::output
        CONFIG_CONV[Config Converter]:::output
    end

    %% Relationships
    OAK --> DETECT
    CONFIG --> DETECT
    COMP_CONFIG --> CONFIG
    DETECT --> SLAM
    SLAM --> TAG_LOC
    UTILS --> DETECT
    UTILS --> SLAM
    UTILS --> TAG_LOC
    TAG_LOC --> NT
    NT --> ROBOT
    
    DETECT --> LOGGING
    SLAM --> LOGGING
    TAG_LOC --> LOGGING
    LOGGING --> LOG_VIS
    CONFIG --> CONFIG_CONV

    %% Click Events
    click DETECT "https://github.com/mgagvani/apriltag-localization-frc/blob/main/detect_apriltag.py"
    click SLAM "https://github.com/mgagvani/apriltag-localization-frc/blob/main/slam_apriltag.py"
    click TAG_LOC "https://github.com/mgagvani/apriltag-localization-frc/blob/main/tag_localizer.py"
    click UTILS "https://github.com/mgagvani/apriltag-localization-frc/blob/main/utils.py"
    click CONFIG_CONV "https://github.com/mgagvani/apriltag-localization-frc/blob/main/config_converter.py"
    click LOG_VIS "https://github.com/mgagvani/apriltag-localization-frc/blob/main/log_visualizer.py"
    click CONFIG "https://github.com/mgagvani/apriltag-localization-frc/tree/main/apriltag_configs/"
    click COMP_CONFIG "https://github.com/mgagvani/apriltag-localization-frc/tree/main/apriltag_configs/crescendo/"
    click LOGGING "https://github.com/mgagvani/apriltag-localization-frc/tree/main/logs/"

    %% Legend
    subgraph Legend
        L1[Hardware Components]:::hardware
        L2[Processing Modules]:::processing
        L3[Configuration]:::config
        L4[External Dependencies]:::external
        L5[Output & Monitoring]:::output
    end
```
