# naman1034/a-neuroadaptive-closed-loop-wearable-device-integrating-bio-inspired-reinforcement-learning-and-pred architecture

> Architecture diagram of the GitHub repository naman1034/a-neuroadaptive-closed-loop-wearable-device-integrating-bio-inspired-reinforcement-learning-and-pred, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-01). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/naman1034/a-neuroadaptive-closed-loop-wearable-device-integrating-bio-inspired-reinforcement-learning-and-pred
- Repository: https://github.com/naman1034/a-neuroadaptive-closed-loop-wearable-device-integrating-bio-inspired-reinforcement-learning-and-pred

## Overview

This repository combines Teensy sensor acquisition, Raspberry Pi real-time tremor monitoring/control, and offline model training and controller tuning. The principal intervention workflow is sensor packets into the Pi, feature/control computation, then stimulation commands; separate offline workflows train a tremor model and tune MPC parameters from recorded traces. The README is empty, and several source excerpts are partial, so links between unsampled firmware behavior and runtime components are limited to relationships explicit in the excerpts.

Main entry points: [`Science-Fair-Project2526/raspberrypi code/realtime.py`](https://github.com/naman1034/a-neuroadaptive-closed-loop-wearable-device-integrating-bio-inspired-reinforcement-learning-and-pred/blob/main/Science-Fair-Project2526/raspberrypi%20code/realtime.py) (Pi runtime), [`Science-Fair-Project2526/training/imuandemgdata.csv`](https://github.com/naman1034/a-neuroadaptive-closed-loop-wearable-device-integrating-bio-inspired-reinforcement-learning-and-pred/blob/main/Science-Fair-Project2526/training/imuandemgdata.csv) (Recorded traces), [`Science-Fair-Project2526/teensy code/teensy.ino`](https://github.com/naman1034/a-neuroadaptive-closed-loop-wearable-device-integrating-bio-inspired-reinforcement-learning-and-pred/blob/main/Science-Fair-Project2526/teensy%20code/teensy.ino) (Teensy firmware), [`Science-Fair-Project2526/training/imuemgdatacollect.py`](https://github.com/naman1034/a-neuroadaptive-closed-loop-wearable-device-integrating-bio-inspired-reinforcement-learning-and-pred/blob/main/Science-Fair-Project2526/training/imuemgdatacollect.py) (CSV collector)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_acquisition["Sensor acquisition"]
  node_teensy["Teensy firmware<br/>[teensy.ino]"]
  node_collector["CSV collector"]
end

subgraph group_runtime["Live monitoring and control"]
  node_live["Pi runtime<br/>[realtime.py]"]
  node_serial["Serial frame reader<br/>[realtime.py]"]
  node_features["Signal features<br/>[realtime.py]"]
  node_tremor_model["Tremor inference<br/>[realtime.py]"]
  node_mpc_control["MPC controller<br/>[realtime.py]"]
  node_stimulation["Stimulation output<br/>[realtime.py]"]
end

subgraph group_offline["Offline training and tuning"]
  node_cnn_training["CNN-LSTM training<br/>[cnnlstm.py]"]
  node_rl_training["DQN training<br/>[rl.py]"]
  node_mpc_tuning["MPC tuning<br/>[mpc.py]"]
end

subgraph group_artifacts["Data and models"]
  node_data_collection[("Recorded traces<br/>[imuandemgdata.csv]")]
  node_trained_model["Tremor model<br/>[tremor_model.keras]"]
  node_mpc_params["Tuned MPC parameters"]
end

node_operator(("Operator"))

node_operator -->|"starts runtime"| node_live
node_teensy -->|"sends packets"| node_serial
node_serial -->|"queues frames"| node_live
node_live -->|"computes features"| node_features
node_live -->|"solves control"| node_mpc_control
node_live -->|"sends control"| node_stimulation
node_live -.->|"uses inference"| node_tremor_model
node_teensy -->|"streams samples"| node_collector
node_collector -->|"writes CSV"| node_data_collection
node_data_collection -->|"trains from"| node_cnn_training
node_cnn_training -->|"saves model"| node_trained_model
node_data_collection -->|"loads trace"| node_rl_training
node_data_collection -->|"tunes from logs"| node_mpc_tuning
node_mpc_tuning -->|"writes parameters"| node_mpc_params
node_mpc_params -->|"loads parameters"| node_live

click node_teensy "https://github.com/naman1034/a-neuroadaptive-closed-loop-wearable-device-integrating-bio-inspired-reinforcement-learning-and-pred/blob/main/Science-Fair-Project2526/teensy%20code/teensy.ino"
click node_collector "https://github.com/naman1034/a-neuroadaptive-closed-loop-wearable-device-integrating-bio-inspired-reinforcement-learning-and-pred/blob/main/Science-Fair-Project2526/training/imuemgdatacollect.py"
click node_live "https://github.com/naman1034/a-neuroadaptive-closed-loop-wearable-device-integrating-bio-inspired-reinforcement-learning-and-pred/blob/main/Science-Fair-Project2526/raspberrypi%20code/realtime.py"
click node_serial "https://github.com/naman1034/a-neuroadaptive-closed-loop-wearable-device-integrating-bio-inspired-reinforcement-learning-and-pred/blob/main/Science-Fair-Project2526/raspberrypi%20code/realtime.py"
click node_features "https://github.com/naman1034/a-neuroadaptive-closed-loop-wearable-device-integrating-bio-inspired-reinforcement-learning-and-pred/blob/main/Science-Fair-Project2526/raspberrypi%20code/realtime.py"
click node_tremor_model "https://github.com/naman1034/a-neuroadaptive-closed-loop-wearable-device-integrating-bio-inspired-reinforcement-learning-and-pred/blob/main/Science-Fair-Project2526/raspberrypi%20code/realtime.py"
click node_mpc_control "https://github.com/naman1034/a-neuroadaptive-closed-loop-wearable-device-integrating-bio-inspired-reinforcement-learning-and-pred/blob/main/Science-Fair-Project2526/raspberrypi%20code/realtime.py"
click node_stimulation "https://github.com/naman1034/a-neuroadaptive-closed-loop-wearable-device-integrating-bio-inspired-reinforcement-learning-and-pred/blob/main/Science-Fair-Project2526/raspberrypi%20code/realtime.py"
click node_cnn_training "https://github.com/naman1034/a-neuroadaptive-closed-loop-wearable-device-integrating-bio-inspired-reinforcement-learning-and-pred/blob/main/Science-Fair-Project2526/training/cnnlstm.py"
click node_rl_training "https://github.com/naman1034/a-neuroadaptive-closed-loop-wearable-device-integrating-bio-inspired-reinforcement-learning-and-pred/blob/main/Science-Fair-Project2526/training/rl.py"
click node_mpc_tuning "https://github.com/naman1034/a-neuroadaptive-closed-loop-wearable-device-integrating-bio-inspired-reinforcement-learning-and-pred/blob/main/Science-Fair-Project2526/training/mpc.py"
click node_data_collection "https://github.com/naman1034/a-neuroadaptive-closed-loop-wearable-device-integrating-bio-inspired-reinforcement-learning-and-pred/blob/main/Science-Fair-Project2526/training/imuandemgdata.csv"
click node_trained_model "https://github.com/naman1034/a-neuroadaptive-closed-loop-wearable-device-integrating-bio-inspired-reinforcement-learning-and-pred/blob/main/Science-Fair-Project2526/training/models/tremor_model.keras"
click node_mpc_params "https://github.com/naman1034/a-neuroadaptive-closed-loop-wearable-device-integrating-bio-inspired-reinforcement-learning-and-pred/blob/main/Science-Fair-Project2526/training/models/mpc_cem_best_params.json"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_teensy,node_collector toneBlue
class node_live,node_serial,node_features,node_tremor_model,node_mpc_control,node_stimulation toneAmber
class node_cnn_training,node_rl_training,node_mpc_tuning toneMint
class node_data_collection,node_trained_model,node_mpc_params toneRose
class node_operator toneIndigo
```

## Components

### Sensor acquisition

- [Teensy firmware](https://github.com/naman1034/a-neuroadaptive-closed-loop-wearable-device-integrating-bio-inspired-reinforcement-learning-and-pred/blob/main/Science-Fair-Project2526/teensy%20code/teensy.ino): `Science-Fair-Project2526/teensy code/teensy.ino`
- [CSV collector](https://github.com/naman1034/a-neuroadaptive-closed-loop-wearable-device-integrating-bio-inspired-reinforcement-learning-and-pred/blob/main/Science-Fair-Project2526/training/imuemgdatacollect.py): `Science-Fair-Project2526/training/imuemgdatacollect.py`

### Live monitoring and control

- [Pi runtime](https://github.com/naman1034/a-neuroadaptive-closed-loop-wearable-device-integrating-bio-inspired-reinforcement-learning-and-pred/blob/main/Science-Fair-Project2526/raspberrypi%20code/realtime.py): `Science-Fair-Project2526/raspberrypi code/realtime.py`
- [Serial frame reader](https://github.com/naman1034/a-neuroadaptive-closed-loop-wearable-device-integrating-bio-inspired-reinforcement-learning-and-pred/blob/main/Science-Fair-Project2526/raspberrypi%20code/realtime.py): `Science-Fair-Project2526/raspberrypi code/realtime.py`
- [Signal features](https://github.com/naman1034/a-neuroadaptive-closed-loop-wearable-device-integrating-bio-inspired-reinforcement-learning-and-pred/blob/main/Science-Fair-Project2526/raspberrypi%20code/realtime.py): `Science-Fair-Project2526/raspberrypi code/realtime.py`
- [Tremor inference](https://github.com/naman1034/a-neuroadaptive-closed-loop-wearable-device-integrating-bio-inspired-reinforcement-learning-and-pred/blob/main/Science-Fair-Project2526/raspberrypi%20code/realtime.py): `Science-Fair-Project2526/raspberrypi code/realtime.py`
- [MPC controller](https://github.com/naman1034/a-neuroadaptive-closed-loop-wearable-device-integrating-bio-inspired-reinforcement-learning-and-pred/blob/main/Science-Fair-Project2526/raspberrypi%20code/realtime.py): `Science-Fair-Project2526/raspberrypi code/realtime.py`
- [Stimulation output](https://github.com/naman1034/a-neuroadaptive-closed-loop-wearable-device-integrating-bio-inspired-reinforcement-learning-and-pred/blob/main/Science-Fair-Project2526/raspberrypi%20code/realtime.py): `Science-Fair-Project2526/raspberrypi code/realtime.py`

### Offline training and tuning

- [CNN-LSTM training](https://github.com/naman1034/a-neuroadaptive-closed-loop-wearable-device-integrating-bio-inspired-reinforcement-learning-and-pred/blob/main/Science-Fair-Project2526/training/cnnlstm.py): `Science-Fair-Project2526/training/cnnlstm.py`
- [DQN training](https://github.com/naman1034/a-neuroadaptive-closed-loop-wearable-device-integrating-bio-inspired-reinforcement-learning-and-pred/blob/main/Science-Fair-Project2526/training/rl.py): `Science-Fair-Project2526/training/rl.py`
- [MPC tuning](https://github.com/naman1034/a-neuroadaptive-closed-loop-wearable-device-integrating-bio-inspired-reinforcement-learning-and-pred/blob/main/Science-Fair-Project2526/training/mpc.py): `Science-Fair-Project2526/training/mpc.py`

### Data and models

- [Recorded traces](https://github.com/naman1034/a-neuroadaptive-closed-loop-wearable-device-integrating-bio-inspired-reinforcement-learning-and-pred/blob/main/Science-Fair-Project2526/training/imuandemgdata.csv): `Science-Fair-Project2526/training/imuandemgdata.csv`
- [Tremor model](https://github.com/naman1034/a-neuroadaptive-closed-loop-wearable-device-integrating-bio-inspired-reinforcement-learning-and-pred/blob/main/Science-Fair-Project2526/training/models/tremor_model.keras): `Science-Fair-Project2526/training/models/tremor_model.keras`
- [Tuned MPC parameters](https://github.com/naman1034/a-neuroadaptive-closed-loop-wearable-device-integrating-bio-inspired-reinforcement-learning-and-pred/blob/main/Science-Fair-Project2526/training/models/mpc_cem_best_params.json): `Science-Fair-Project2526/training/models/mpc_cem_best_params.json`

### Other components

- **Operator**

## Connections

- Operator → Pi runtime: starts runtime
- Teensy firmware → Serial frame reader: sends packets (evidence: `Science-Fair-Project2526/raspberrypi code/realtime.py`)
- Serial frame reader → Pi runtime: queues frames (evidence: `Science-Fair-Project2526/raspberrypi code/realtime.py`)
- Pi runtime → Signal features: computes features (evidence: `Science-Fair-Project2526/raspberrypi code/realtime.py`)
- Pi runtime → MPC controller: solves control (evidence: `Science-Fair-Project2526/raspberrypi code/realtime.py`)
- Pi runtime → Stimulation output: sends control (evidence: `Science-Fair-Project2526/raspberrypi code/realtime.py`)
- Pi runtime → Tremor inference: uses inference (evidence: `Science-Fair-Project2526/raspberrypi code/realtime.py`)
- Teensy firmware → CSV collector: streams samples (evidence: `Science-Fair-Project2526/training/imuemgdatacollect.py`)
- CSV collector → Recorded traces: writes CSV (evidence: `Science-Fair-Project2526/training/imuemgdatacollect.py`)
- Recorded traces → CNN-LSTM training: trains from (evidence: `Science-Fair-Project2526/training/cnnlstm.py`)
- CNN-LSTM training → Tremor model: saves model (evidence: `Science-Fair-Project2526/training/cnnlstm.py`)
- Recorded traces → DQN training: loads trace (evidence: `Science-Fair-Project2526/training/rl.py`)
- Recorded traces → MPC tuning: tunes from logs (evidence: `Science-Fair-Project2526/training/mpc.py`)
- MPC tuning → Tuned MPC parameters: writes parameters (evidence: `Science-Fair-Project2526/training/mpc.py`)
- Tuned MPC parameters → Pi runtime: loads parameters (evidence: `Science-Fair-Project2526/raspberrypi code/realtime.py`)
