# we-worker/robot_localization_in_stationary_scenario architecture

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

- Interactive diagram: https://gitdiagram.com/we-worker/robot_localization_in_stationary_scenario
- Repository: https://github.com/we-worker/robot_localization_in_stationary_scenario

## Overview

##### Main Components
a. Hardware
- LIDAR Sensors (LD06, T-mini-Pro)
- STM32 microcontroller (driving wheels, stepper motors, robotic arm)
b. Software Processes (all Python scripts)
- Sensor Acquisition
- LIDAR_LD06_python_loder/CalcLidarData.py
- T_mini_pro_loder/CalcLidarData.py
- Data Processing & Localization
- LikelihoodField.py
- Location.py
- Location_simulation.py (log-replay mode)
- Communication
- Socket_fun.py (inter‐process IPC via TCP/UDP sockets)
- contorller.py (UART interface to STM32)
- Orchestration & Logic
- Main.py (high-level robot logic, ties everything together)
- Configuration & Data Stores
- config.yaml (parameters)
- maps/ (map files)
- logs/ (recorded LIDAR/serial logs)
- Helpers & Scripts
- run.bat, stop.bat (launch/terminate processes)

##### Relationships & Data Flows
- Sensor → Acquisition:
LIDAR devices stream raw bytes over serial → CalcLidarData modules parse into “ranges”, “angles”, “is_new” → push into a shared dictionary (multiprocessing.Manager).
- Acquisition → Localization:
CalcLidarData writes to Manager dict → Location.py and LikelihoodField.py pull data to compute robot pose.
- Localization ↔ Simulation:
Location_simulation.py uses saved logs + same localization pipeline for debugging; no live serial.
- Localization → Orchestration:
Estimated pose → forwarded to Main.py via socket_fun (TCP/UDP).
- Orchestration → Actuators:
Main.py decisions → contorller.py (UART) → STM32 → motor/arm hardware.
- Config & Maps:
All processes read config.yaml; localization loads maps/map1.pixil.
- Logging:
Every module optionally logs to logs/*.json for replay or debugging.

##### Architectural Patterns & Design Principles
- Modular, multi‐process pipeline: each major function runs as an independent Python process for isolation.
- Publisher/Subscriber style via shared Manager dict for sensor data and via socket_fun for inter‐process messaging.
- Separation of concerns: acquisition, estimation, decision logic, and hardware interfacing are distinct components.
- Config‐driven behavior: parameters in config.yaml steer algorithms without code changes.
- Simulation mode: reuse pipeline for offline debugging (Location_simulation.py).

##### Final Recommendations
- Be exhaustive: include every Python script and its role.
- Related modules together but keep data flow obvious.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Orchestration Layer
    subgraph "Orchestration Layer"
        Main["Main.py"]:::orchestration
        Ctrl["Contorller.py"]:::communication
        Socket["Socket_fun.py"]:::communication
    end

    %% Localization & Estimation Layer
    subgraph "Localization & Estimation Layer"
        Likelihood["LikelihoodField.py"]:::estimation
        Location["Location.py"]:::estimation
        Sim["Location_simulation.py"]:::estimation
    end

    %% Acquisition Layer
    subgraph "Acquisition Layer"
        LD06["CalcLidarData (LD06)"]:::acquisition
        TMini["CalcLidarData (T-mini-Pro)"]:::acquisition
    end

    %% Helpers & Scripts
    subgraph "Helpers & Scripts"
        Run["run.bat"]:::helper
        Stop["stop.bat"]:::helper
    end

    %% Configuration & Data
    subgraph "Configuration & Data"
        Config["config.yaml"]:::data
        Maps["maps/map1.pixil"]:::data
        Logs1["logs/log_0317135854.json"]:::data
        Logs2["logs/log_0318154629.json"]:::data
    end

    %% Hardware Layer
    subgraph "Hardware Layer"
        LD06_HW["LIDAR LD06"]:::hardware
        TMini_HW["LIDAR T-mini-Pro"]:::hardware
        STM32["STM32 Microcontroller"]:::hardware
        Motors["Motors & Arm"]:::hardware
    end

    %% Data Flows - Acquisition
    LD06_HW -->|"Serial/UART"| LD06
    TMini_HW -->|"Serial/UART"| TMini

    %% Acquisition to Localization
    LD06 -->|"Shared Manager dict"| Likelihood
    LD06 -->|"Shared Manager dict"| Location
    TMini -->|"Shared Manager dict"| Likelihood
    TMini -->|"Shared Manager dict"| Location

    %% Simulation (log-replay)
    Logs1 -.->|"log file"| Sim
    Logs2 -.->|"log file"| Sim
    Sim -->|"Simulated data"| Likelihood
    Sim -->|"Simulated data"| Location

    %% Localization to Orchestration
    Location -->|"pose data"| Socket
    Likelihood -->|"field data"| Socket
    Socket -->|"TCP/UDP"| Main

    %% Orchestration to Hardware
    Main -->|"decision"| Ctrl
    Ctrl -->|"UART"| STM32
    STM32 -->|"PWM signals"| Motors

    %% Configuration usage
    Config -.-> LD06
    Config -.-> TMini
    Config -.-> Likelihood
    Config -.-> Location
    Config -.-> Sim
    Config -.-> Main
    Maps -.-> Likelihood

    %% Helpers usage
    Run --> LD06
    Run --> TMini
    Run --> Main
    Stop --> LD06
    Stop --> TMini
    Stop --> Main

    %% Click Events
    click LD06 "https://github.com/we-worker/robot_localization_in_stationary_scenario/blob/master/LIDAR_LD06_python_loder/CalcLidarData.py"
    click TMini "https://github.com/we-worker/robot_localization_in_stationary_scenario/blob/master/T_mini_pro_loder/CalcLidarData.py"
    click Likelihood "https://github.com/we-worker/robot_localization_in_stationary_scenario/blob/master/LikelihoodField.py"
    click Location "https://github.com/we-worker/robot_localization_in_stationary_scenario/blob/master/Location.py"
    click Sim "https://github.com/we-worker/robot_localization_in_stationary_scenario/blob/master/Location_simulation.py"
    click Socket "https://github.com/we-worker/robot_localization_in_stationary_scenario/blob/master/Socket_fun.py"
    click Ctrl "https://github.com/we-worker/robot_localization_in_stationary_scenario/blob/master/Contorller.py"
    click Main "https://github.com/we-worker/robot_localization_in_stationary_scenario/blob/master/Main.py"
    click Config "https://github.com/we-worker/robot_localization_in_stationary_scenario/blob/master/config.yaml"
    click Maps "https://github.com/we-worker/robot_localization_in_stationary_scenario/blob/master/maps/map1.pixil"
    click Logs1 "https://github.com/we-worker/robot_localization_in_stationary_scenario/blob/master/logs/log_0317135854.json"
    click Logs2 "https://github.com/we-worker/robot_localization_in_stationary_scenario/blob/master/logs/log_0318154629.json"
    click Run "https://github.com/we-worker/robot_localization_in_stationary_scenario/blob/master/run.bat"
    click Stop "https://github.com/we-worker/robot_localization_in_stationary_scenario/blob/master/stop.bat"

    %% Styles
    classDef hardware fill:#f2f2f2,stroke:#333,stroke-width:1px
    classDef acquisition fill:#cce5ff,stroke:#0366d6,stroke-width:1px
    classDef estimation fill:#d4edda,stroke:#155724,stroke-width:1px
    classDef orchestration fill:#fff3cd,stroke:#856404,stroke-width:1px
    classDef communication fill:#ffe5b4,stroke:#ff8c00,stroke-width:1px
    classDef data fill:#e2e3e5,stroke:#6c757d,stroke-width:1px,stroke-dasharray: 2 2
    classDef helper fill:#fce8f1,stroke:#d63384,stroke-width:1px,stroke-dasharray: 2 2
```
