# ildaron/laser_control architecture

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

- Interactive diagram: https://gitdiagram.com/ildaron/laser_control
- Repository: https://github.com/ildaron/laser_control

## Overview

##### Project type and purpose
- This is an embedded computer-vision & control system.
- Purpose: detect objects (mosquitoes, weeds, cockroaches) via camera(s), compute their 3D position, convert that into galvanometer mirror angles, and steer a (low-power) laser pointer to neutralize or mark the target.

##### File structure – main directories
- 1.Motor_driver: electrical schematics for the galvanometer driver boards.
- 2.Jetson_code/2.1_mirror_control: Python SPI code (mcp4922 DAC) to drive the analog mirror controller.
- 3.YoloV4: scripts for object detection (YOLOv4-tiny) on video streams.
- 7.Darknet: build and configure Darknet (including TensorRT) for optimized inference.

##### README – architecture clues
- Cameras → digital video input → onboard SBC (Raspberry Pi or Jetson Nano)
- Two processing paths:
a) X,Y detection via deep learning (YOLOv4-tiny)
b) Z (depth) via stereo vision
- Coordinate fusion → compute required mirror angles α (using geometric formulas)
- Control path: SPI → MCP4922 DAC → amplifier → galvanometer driver boards → galvanometer mirrors → laser beam direction
- Safety & future modules: human detection, audio sensors, uplink/downlink over Wi-Fi.

##### Sketch the system’s main components
a. Hardware layer
- Stereo Cameras (left + right)
- Jetson Nano / Raspberry Pi SBC
- SPI interface → MCP4922 DAC
- Analog amplifier board → ±12 V outputs
- Galvanometer driver boards → galvanometer mirrors
- Laser pointer module
- Power supply unit
- (Optional) Security sensors: additional cameras, audio, thermal
b. Software & processing layer
- Video capture & pre-processing (OpenCV)
- Object detection module (YOLOv4-tiny / Darknet)
- Stereo-vision module (depth map & Z calculation)
- Coordinate fusion & angle computation
- Mirror control module (DAC SPI commands)
- Laser control trigger
- Configuration & calibration scripts (My_project)
c. Optional / future/external services
- Remote control UI (over Wi-Fi)
- PC-hosted detection service
- PCB-based galvanometer controller

##### Relationships & data flow
1. Stereo Cameras capture frames →
2. SBC runs two parallel pipelines:
– Stereo depth calculation → Z
3. Fusion module combines (X,Y,Z) → computes mirror angles αx, αy
4. Mirror control module sends SPI commands to MCP4922 → generates analog voltages
5. Amplifier board ups voltages to ±12 V → galvanometer driver boards
6. Galvanometers tilt mirrors → laser beam directed at target
7. Laser module is (optionally) triggered on target lock
8. Feedback loop: cameras continuously monitor and update target position

##### Architectural patterns & design principles
- Layered design: separates sensor I/O, CV/ML, control, and hardware actuation
- Modular code: distinct folders for detection (YoloV4), control (Jetson_code), hardware specs (Motor_driver)
- Parallel processing: simultaneous inference & depth mapping
- Hardware-in-the-loop: real-time SPI control of analog electronics

##### Technologies, frameworks & libraries
- Python + OpenCV for image capture & stereo vision
- Darknet (C/C++), TensorRT, tkDNN for YOLOv4-tiny inference
- SPI Python bindings for MCP4922 DAC
- NumPy for depth / ROI averaging
- Makefiles & custom cfg for model build (in Darknet/my_files)

- Digital processing (blue)
- Control / SPI (green)
- Analog / power (orange)
- Laser / actuation (red)
– Annotations for protocols/interfaces (e.g., “SPI,” “USB,” “GPIO,” “I2C”).
– Optional side-blocks for safety modules or remote UI pointing to the central SBC.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Software Layer"
        VC["Video Capture & Pre-processing"]:::digital
        YOLO["Object Detection (YOLOv4-tiny)"]:::digital
        STEREO["Stereo Vision Module"]:::digital
        FUSION["Coordinate Fusion & Angle Computation"]:::digital
        INTEGRATION["Integration & Mirror Movement"]:::digital
        MODEL["Model Training & Optimization"]:::digital
        CALIB["Calibration & Supplementary Hardware Diagrams"]:::digital
        DOC["Project Documentation"]:::digital
    end

    subgraph "Control & SPI"
        MIRROR["Mirror Control Module (MCP4922 DAC)"]:::control
    end

    subgraph "Hardware Layer"
        CAM["Stereo Cameras"]:::hardware
        SBC["Jetson Nano SBC"]:::hardware
        AMP["Amplifier Board"]:::analog
        DRIVER["Galvanometer Driver Boards"]:::analog
        MIRRORS["Galvanometer Mirrors"]:::hardware
        LASER["Laser Pointer Module"]:::actuation
        PWR["Power Supply Unit"]:::analog
        SCHEM["Galvanometer Driver Schematics"]:::documentation
    end

    CAM -->|"USB/CSI"| SBC
    SBC -->|"frames"| VC
    VC -->|"frames"| YOLO
    VC -->|"frames"| STEREO
    YOLO -->|"X,Y"| FUSION
    STEREO -->|"Z"| FUSION
    FUSION -->|"angles"| INTEGRATION
    INTEGRATION -->|"SPI"| MIRROR
    MIRROR -->|"analog voltages"| AMP
    AMP -->|"±12V"| DRIVER
    DRIVER -->|"current"| MIRRORS
    MIRRORS -->|"redirect beam"| LASER
    PWR --> AMP
    PWR --> DRIVER
    PWR --> SBC
    PWR --> CAM
    SBC --- DOC
    SBC --- MODEL
    SBC --- CALIB
    SBC --- SCHEM

    click SCHEM "https://github.com/ildaron/laser_control/blob/master/1.Motor_driver/1.1_electrical_scheme/ReadMe.txt"
    click MIRROR "https://github.com/ildaron/laser_control/blob/master/2.Jetson_code/2.1_mirror_control/2.1.1_DAC_mcp4922.py"
    click VC "https://github.com/ildaron/laser_control/blob/master/3.YoloV4/3.1_Video_test.py"
    click YOLO "https://github.com/ildaron/laser_control/blob/master/3.YoloV4/3.2_yolov4tiny_from_colab.py"
    click INTEGRATION "https://github.com/ildaron/laser_control/blob/master/5.My_project/1.1_Detect_Color_and_move_mirrow.py"
    click MODEL "https://github.com/ildaron/laser_control/blob/master/7.Darknet/ReadMe.txt"
    click CALIB "https://github.com/ildaron/laser_control/blob/master/Supplementary files/Readme.txt"
    click DOC "https://github.com/ildaron/laser_control/blob/master/README.md"

    classDef digital fill:#ADD8E6,stroke:#000,stroke-width:1px
    classDef control fill:#90EE90,stroke:#000,stroke-width:1px
    classDef analog fill:#FFA500,stroke:#000,stroke-width:1px
    classDef actuation fill:#FF6347,stroke:#000,stroke-width:1px
    classDef hardware fill:#D3D3D3,stroke:#000,stroke-width:1px
    classDef documentation fill:#FFFFE0,stroke:#000,stroke-width:1px
```
