# tomiinek/star_tracker architecture

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

- Interactive diagram: https://gitdiagram.com/tomiinek/star_tracker
- Repository: https://github.com/tomiinek/star_tracker

## Overview

##### Main Components
- Arduino Microcontroller (“Star_Tracker.ino”): This is the central firmware controller that coordinates all subsystems.
- Firmware Modules:
- Configuration Module (src/config.h): Stores system configurations like geographical coordinates and motor parameters.
- Core Control Modules (located in src/core): Includes clock (RTC interface via DS3231), motor controller, mount controller, camera controller (Canon support), and utility elements (e.g., queue handling).
- Control Layer Modules (located in src/control): Contains user interface components such as display output, input handling (keypad/IR remote control definitions), and control processing.
- SD Card (SD/catalog.csv): Provides a catalogue of deep-sky objects for automatic pointing.
- External Hardware Components: Stepper motors with drivers (using A4988, with microstepping control), LCD display, IR receiver, potentiometers, RTC module, and optional camera trigger interface.

##### Relationships and Data Flow
- The Arduino microcontroller (running Star_Tracker.ino) integrates calls to both core (for precise timekeeping, motor control, mount and camera operations) and control modules (for manual input and display output).
- The control module handles user interaction (manual control via IR keypad and LCD display) and sends commands to the core modules.
- The SD card (mounted externally) is used to retrieve the catalogue CSV, which feeds into the automated pointing and tracking logic.
- The RTC (DS3231) communicated via I2C supply accurate time that underpins the tracking and alignments.
- There is also bidirectional data flow between the user-input layer (via key codes from the IR receiver) and the internal configuration which alters the behaviour of motor and camera modules.
- Modules for camera triggering and motor control encapsulate hardware-specific logic, and they must exchange control signals with the main firmware loop in Star_Tracker.ino.

##### Architectural Patterns and Design Principles
- Modularity: The project is segmented into distinct “core” and “control” components, allowing separation of concerns between hardware control (motors, RTC, camera) and user interface/command handling.
- Hardware Abstraction: The use of dedicated interface headers (e.g., rtc_ds3231.h, canon_eos1000d.h) allows for encapsulating device-specific details, so that alternative hardware implementations can plug in with minimal changes.
- Configurability: The configuration file (src/config.h) plays a key role in customizing both hardware parameters (like motor specifications, coordinate locations, calibration values) and operational behaviours.
- Asynchronous Operations: The README stresses asynchronous control for stepper motors, meaning that concurrent processing considerations might be represented as parallel flows if the implementation supports cooperative multitasking.

##### Technologies, Frameworks, and Libraries Involved
- Arduino IDE (C++ based firmware) for implementation.
- Standard Arduino libraries – RTCLib, LiquidCrystal, SD, SPI, Wire, EEPROM – which are integrated and used to interface with hardware peripherals.

##### Final Recommendations
- Try to incorporate any architectural patterns (modularity and hardware abstraction) into your depiction.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Hardware Components
    subgraph "Hardware Components"
        A_H("Arduino MEGA2560"):::hardware
        RTC_H("RTC (DS3231)"):::hardware
        LCD_H("LCD Display"):::hardware
        STEPPER("Stepper Driver (A4988)"):::hardware
        IR_H("IR Receiver"):::hardware
        SD_H("SD Card (catalog.csv)"):::hardware
        CAM_H("Camera Trigger Interface"):::hardware
    end

    %% Firmware - Main
    subgraph "Firmware - Main"
        F_FW("Star_Tracker.ino"):::main
        CONFIG("Configuration Module"):::main
    end

    %% Firmware - Core Modules
    subgraph "Firmware - Core Modules"
        RTC_M("RTC Module"):::core
        MOTOR("Motor Controller Module"):::core
        MOUNT("Mount Controller Module"):::core
        CAMERA("Camera Controller Module"):::core
        UTIL("Utility Module (Queue)"):::core
    end

    %% Firmware - Control Modules
    subgraph "Firmware - Control Modules"
        DISPLAY("Display / UI Module"):::control
        CONTROL("Control Processing Module"):::control
        INPUT("Input Handling Module"):::control
    end

    %% Ancillary Files
    subgraph "Ancillary Files"
        DOCS("Documentation & Configurations"):::doc
    end

    %% Interconnections between Firmware and Hardware
    A_H --- F_FW
    F_FW --> CONFIG
    F_FW --> RTC_M
    F_FW --> MOTOR
    F_FW --> MOUNT
    F_FW --> CAMERA
    F_FW --> UTIL
    F_FW --> DISPLAY
    F_FW --> CONTROL
    F_FW --> INPUT

    %% Hardware connections to Core Modules
    RTC_M -->|"interfaces"| RTC_H
    MOTOR -->|"controls"| STEPPER
    CAMERA -->|"triggers"| CAM_H

    %% Hardware connections to Control Modules
    DISPLAY -->|"outputs to"| LCD_H
    INPUT -->|"receives from"| IR_H

    %% SD Card connection feeds automated logic
    SD_H -->|"catalog data"| MOUNT

    %% Interactions within Control Modules and Core Modules
    INPUT -->|"sends commands"| CONTROL
    CONTROL -->|"commands"| MOTOR
    CONTROL -->|"commands"| MOUNT
    CONTROL -->|"commands"| CAMERA

    %% Styling for vertical orientation
    %% (Nodes are arranged in layers as defined by the subgraphs)

    %% Click Events for Firmware and Modules
    click F_FW "https://github.com/tomiinek/star_tracker/blob/master/Star_Tracker.ino"
    click CONFIG "https://github.com/tomiinek/star_tracker/blob/master/src/config.h"
    
    click RTC_M "https://github.com/tomiinek/star_tracker/blob/master/src/core/clock.cpp"
    click RTC_M "https://github.com/tomiinek/star_tracker/blob/master/src/core/clock.h"
    click RTC_M "https://github.com/tomiinek/star_tracker/blob/master/src/core/rtc_ds3231.h"
    
    click MOTOR "https://github.com/tomiinek/star_tracker/blob/master/src/core/motor_controller.cpp"
    click MOTOR "https://github.com/tomiinek/star_tracker/blob/master/src/core/motor_controller.h"
    
    click MOUNT "https://github.com/tomiinek/star_tracker/blob/master/src/core/mount_controller.cpp"
    click MOUNT "https://github.com/tomiinek/star_tracker/blob/master/src/core/mount_controller.h"
    
    click CAMERA "https://github.com/tomiinek/star_tracker/blob/master/src/core/camera_controller.h"
    click CAMERA "https://github.com/tomiinek/star_tracker/blob/master/src/core/canon_eos1000d.h"
    
    click UTIL "https://github.com/tomiinek/star_tracker/blob/master/src/core/queue.h"
    
    click DISPLAY "https://github.com/tomiinek/star_tracker/blob/master/src/control/display.cpp"
    click DISPLAY "https://github.com/tomiinek/star_tracker/blob/master/src/control/display.h"
    
    click CONTROL "https://github.com/tomiinek/star_tracker/blob/master/src/control/control.cpp"
    click CONTROL "https://github.com/tomiinek/star_tracker/blob/master/src/control/control.h"
    
    click INPUT "https://github.com/tomiinek/star_tracker/blob/master/src/control/keypad.h"
    
    click SD_H "https://github.com/tomiinek/star_tracker/blob/master/SD/catalog.csv"
    
    click DOCS "https://github.com/tomiinek/star_tracker/blob/master/README.md"
    click DOCS "https://github.com/tomiinek/star_tracker/blob/master/_config.yml"
    click DOCS "https://github.com/tomiinek/star_tracker/tree/master/_img"

    %% Styles
    classDef hardware fill:#ffcccc,stroke:#cc0000,stroke-width:2px
    classDef main fill:#ffebcc,stroke:#d2691e,stroke-width:2px
    classDef core fill:#ccffcc,stroke:#009900,stroke-width:2px
    classDef control fill:#ccccff,stroke:#0000ff,stroke-width:2px
    classDef doc fill:#ffffcc,stroke:#cccc00,stroke-width:2px
```
