# thomabir/nicecontrol architecture

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

- Interactive diagram: https://gitdiagram.com/thomabir/nicecontrol
- Repository: https://github.com/thomabir/nicecontrol

## Overview

##### Main Components

a. Hardware Components:
- Piezo Controllers
- MCL NanoDrive
- PI E727 Controller
- PI E754 Controller
- nF EBD Controller
- Analog Discovery 2 (debugging interface)
- Teensy microcontroller (for ADC activation)

b. Software Components:
- Main Control Interface (NICEcontrol.cpp)
- Control Systems
- MIMO Control Loop
- SISO Control Loop
- Null Lockin System
- Data Management
- Circular Buffers
- Scrolling Buffers
- Sensor Data Handling
- Filter Systems
- FIR Filter
- Control Loop Characterization

##### Specific Elements

a. Data Flow Indicators:
- Sensor data flow from hardware through buffers to UI
- Control signals from UI through controllers to hardware
- Feedback loops in the control systems

b. Component Relationships:
- Control signals (e.g., red)
- Sensor data (e.g., blue)
- User interface elements (e.g., green)
- Hardware components (e.g., gray)

##### Implementation Details

**[User Interface Layer]**
- ImGui/ImPlot visualization
- Control parameters input
- Real-time monitoring

**[Control Layer]**
- MIMO/SISO Control Loops
- PI Controllers
- Null Detection System
- FIR Filters

**[Data Management Layer]**
- Circular Buffers
- Scrolling Buffers
- Sensor Data Processing

**[Hardware Interface Layer]**
- MCL NanoDrive Interface
- PI Controller Interfaces
- nF EBD Controller Interface
- Teensy Interface

##### Technical Details to Note

- External dependencies (FFTW3, Boost, IIR1)
- Relationship between the control loops and hardware
- Where the FIR filters are applied in the signal chain

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph UI["User Interface Layer"]
        GUI["ImGui/ImPlot Visualization"]
        CP["Control Parameters"]
        MON["Real-time Monitoring"]
    end

    subgraph CL["Control Layer"]
        MIMO["MIMO Control Loop"]:::control
        SISO["SISO Control Loop"]:::control
        NLS["Null Lockin System"]:::control
        DIAG["Diagonal PI Controller"]:::control
        CONT["Controllers Base"]:::control
    end

    subgraph DM["Data Management Layer"]
        CB["Circular Buffer"]:::data
        SB["Scrolling Buffer"]:::data
        SD["Sensor Data"]:::data
        CD["Control Data"]:::data
        MT["Measurement Types"]:::data
    end

    subgraph FS["Filter Systems"]
        FIR["FIR Filter"]:::filter
        CLC["Control Loop Characterization"]:::filter
        JCLC["Joint Closed Loop Characterization"]:::filter
        OLC["Open Loop Characterization"]:::filter
    end

    subgraph HW["Hardware Interface Layer"]
        MCL["MCL NanoDrive"]:::hardware
        PIE727["PI E727 Controller"]:::hardware
        PIE754["PI E754 Controller"]:::hardware
        NFEBD["nF EBD Controller"]:::hardware
        TEENSY["Teensy (ADC)"]:::hardware
        AD2["Analog Discovery 2"]:::debug
    end

    %% Main Program
    MAIN["NICEcontrol"]:::main

    %% Connections
    MAIN --> GUI
    MAIN --> CP
    MAIN --> MON
    
    GUI --> MIMO
    GUI --> SISO
    GUI --> NLS
    
    MIMO --> CONT
    SISO --> CONT
    NLS --> CONT
    DIAG --> CONT
    
    CONT --> CB
    CONT --> SB
    CONT --> SD
    CONT --> CD
    
    CB --> FIR
    SD --> CLC
    CD --> JCLC
    MT --> OLC
    
    FIR --> MCL
    CLC --> PIE727
    JCLC --> PIE754
    OLC --> NFEBD
    
    TEENSY --> AD2

    %% Click Events
    click MAIN "https://github.com/thomabir/NICEcontrol/blob/main/src/NICEcontrol.cpp"
    click MCL "https://github.com/thomabir/NICEcontrol/blob/main/src/MCL_NanoDrive.hpp"
    click PIE727 "https://github.com/thomabir/NICEcontrol/blob/main/src/PI_E727_Controller.hpp"
    click PIE754 "https://github.com/thomabir/NICEcontrol/blob/main/src/PI_E754_Controller.hpp"
    click NFEBD "https://github.com/thomabir/NICEcontrol/blob/main/src/nF_EBD_Controller.hpp"
    click MIMO "https://github.com/thomabir/NICEcontrol/blob/main/src/MIMOControlLoop.hpp"
    click SISO "https://github.com/thomabir/NICEcontrol/blob/main/src/SISOControlLoop.hpp"
    click NLS "https://github.com/thomabir/NICEcontrol/blob/main/src/NullLockin.hpp"
    click DIAG "https://github.com/thomabir/NICEcontrol/blob/main/src/DiagPIController.hpp"
    click CONT "https://github.com/thomabir/NICEcontrol/blob/main/src/Controllers.hpp"
    click CB "https://github.com/thomabir/NICEcontrol/blob/main/src/TSCircularBuffer.hpp"
    click SB "https://github.com/thomabir/NICEcontrol/blob/main/src/ScrollingBuffer.hpp"
    click SD "https://github.com/thomabir/NICEcontrol/blob/main/src/SensorData.hpp"
    click CD "https://github.com/thomabir/NICEcontrol/blob/main/src/ControlData.hpp"
    click MT "https://github.com/thomabir/NICEcontrol/blob/main/src/MeasurementT.hpp"
    click FIR "https://github.com/thomabir/NICEcontrol/blob/main/src/FirFilter.hpp"
    click CLC "https://github.com/thomabir/NICEcontrol/blob/main/src/characterise_control_loop.hpp"
    click JCLC "https://github.com/thomabir/NICEcontrol/blob/main/src/characterise_joint_closed_loop.hpp"
    click OLC "https://github.com/thomabir/NICEcontrol/blob/main/src/characterise_open_loop.hpp"

    %% Styles
    classDef main fill:#f9f,stroke:#333,stroke-width:4px
    classDef control fill:#f96,stroke:#333
    classDef data fill:#69f,stroke:#333
    classDef filter fill:#9f6,stroke:#333
    classDef hardware fill:#999,stroke:#333
    classDef debug fill:#f66,stroke:#333

    %% Legend
    subgraph Legend
        L1["Main Program"]:::main
        L2["Control Component"]:::control
        L3["Data Component"]:::data
        L4["Filter Component"]:::filter
        L5["Hardware Component"]:::hardware
        L6["Debug Component"]:::debug
    end
```
