# ntnu-arl/embedded_rio architecture

> Architecture diagram of the GitHub repository ntnu-arl/embedded_rio, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-14). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/ntnu-arl/embedded_rio
- Repository: https://github.com/ntnu-arl/embedded_rio

## Overview

Embedded-RIO is Teensy 4.x firmware for radar-inertial odometry, with an offline log-replay and analysis workflow. Firmware samples the IMU, radar and optional barometer; dispatches measurements to an ESKF; and publishes estimated state over MAVLink or USB while optionally logging sensor data to SD. Replay feeds recorded logs through the shared ESKF for tuning and validation, with plotting, PX4 ULog comparison and ablation analysis. Connections for unsampled analysis internals are limited to README statements and indexed file references.

Main entry points: [`src/main.cpp`](https://github.com/ntnu-arl/embedded_rio/blob/main/src/main.cpp) (Firmware loop), [`tools/replay/src/replay.cpp`](https://github.com/ntnu-arl/embedded_rio/blob/main/tools/replay/src/replay.cpp) (Replay runner), [`src/filter/eskf_node.cpp`](https://github.com/ntnu-arl/embedded_rio/blob/main/src/filter/eskf_node.cpp) (ESKF fusion), [`src/io/sd_logger.cpp`](https://github.com/ntnu-arl/embedded_rio/blob/main/src/io/sd_logger.cpp) (SD card logger)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_sensing["Sensor acquisition"]
  node_firmware["Firmware loop<br/>[main.cpp]"]
  node_imu["BMI088 IMU<br/>[bmi08x.cpp]"]
  node_radar["IWR6843 radar<br/>[xwr6843aop.cpp]"]
  node_barometer["BMP388 barometer<br/>[bmp388.cpp]"]
end

subgraph group_estimation["State estimation"]
  node_eskf["ESKF fusion<br/>[eskf_node.cpp]"]
  node_rio["RIO ESKF library"]
end

subgraph group_output["Outputs and logging"]
  node_telemetry["MAVLink telemetry<br/>[telemetry.cpp]"]
  node_debug["USB diagnostics<br/>[debug.cpp]"]
  node_plotter["Live serial plotter<br/>[serial_plotter.py]"]
  node_sdlog[("SD card logger<br/>[sd_logger.cpp]")]
end

subgraph group_replay["Offline replay and analysis"]
  node_replay["Replay runner<br/>[replay.cpp]"]
  node_logreader["CSV log reader<br/>[log_reader.cpp]"]
  node_ablation["Ablation analysis"]
  node_ulog["PX4 ULog comparison"]
  node_plots["Run plots<br/>[plot_runs.py]"]
  node_plotstyle["Plot conventions<br/>[plot_style.py]"]
end

node_px4(("PX4 flight controller"))
node_sdcard[("SD card")]
node_recording["Recorded sensor log"]

node_firmware -->|"reads samples"| node_imu
node_firmware -->|"drains frames"| node_radar
node_firmware -->|"reads samples"| node_barometer
node_firmware -->|"dispatches measurements"| node_eskf
node_eskf -->|"runs filter"| node_rio
node_eskf -->|"publishes state"| node_telemetry
node_telemetry -->|"streams MAVLink"| node_px4
node_eskf -->|"prints state"| node_debug
node_debug -.->|"streams USB data"| node_plotter
node_eskf -->|"logs samples"| node_sdlog
node_firmware -->|"flushes log"| node_sdlog
node_sdlog -.->|"writes CSV"| node_sdcard
node_recording -->|"reads rows"| node_logreader
node_replay -->|"loads events"| node_logreader
node_replay -->|"runs shared ESKF"| node_rio
node_replay -->|"sweeps configurations"| node_ablation
node_replay -->|"compares estimates"| node_ulog
node_replay -->|"visualizes runs"| node_plots
node_ablation -->|"uses styles"| node_plotstyle
node_ulog -->|"uses styles"| node_plotstyle
node_plots -->|"uses styles"| node_plotstyle

click node_firmware "https://github.com/ntnu-arl/embedded_rio/blob/main/src/main.cpp"
click node_imu "https://github.com/ntnu-arl/embedded_rio/blob/main/src/drivers/bmi08x.cpp"
click node_radar "https://github.com/ntnu-arl/embedded_rio/blob/main/src/drivers/xwr6843aop.cpp"
click node_barometer "https://github.com/ntnu-arl/embedded_rio/blob/main/src/drivers/bmp388.cpp"
click node_eskf "https://github.com/ntnu-arl/embedded_rio/blob/main/src/filter/eskf_node.cpp"
click node_rio "https://github.com/ntnu-arl/embedded_rio/tree/main/lib/rio-lib"
click node_telemetry "https://github.com/ntnu-arl/embedded_rio/blob/main/src/io/telemetry.cpp"
click node_debug "https://github.com/ntnu-arl/embedded_rio/blob/main/src/io/debug.cpp"
click node_plotter "https://github.com/ntnu-arl/embedded_rio/blob/main/scripts/serial_plotter.py"
click node_sdlog "https://github.com/ntnu-arl/embedded_rio/blob/main/src/io/sd_logger.cpp"
click node_replay "https://github.com/ntnu-arl/embedded_rio/blob/main/tools/replay/src/replay.cpp"
click node_logreader "https://github.com/ntnu-arl/embedded_rio/blob/main/tools/replay/src/log_reader.cpp"
click node_ablation "https://github.com/ntnu-arl/embedded_rio/blob/main/tools/replay/scripts/compare_ablation.py"
click node_ulog "https://github.com/ntnu-arl/embedded_rio/blob/main/tools/replay/scripts/compare_with_ulog.py"
click node_plots "https://github.com/ntnu-arl/embedded_rio/blob/main/tools/replay/scripts/plot_runs.py"
click node_plotstyle "https://github.com/ntnu-arl/embedded_rio/blob/main/tools/replay/scripts/plot_style.py"

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_firmware,node_imu,node_radar,node_barometer toneBlue
class node_eskf,node_rio,node_sdcard toneAmber
class node_telemetry,node_debug,node_plotter,node_sdlog toneMint
class node_replay,node_logreader,node_ablation,node_ulog,node_plots,node_plotstyle toneRose
class node_px4,node_recording toneIndigo
```

## Components

### Sensor acquisition

- [Firmware loop](https://github.com/ntnu-arl/embedded_rio/blob/main/src/main.cpp): `src/main.cpp`
- [BMI088 IMU](https://github.com/ntnu-arl/embedded_rio/blob/main/src/drivers/bmi08x.cpp): `src/drivers/bmi08x.cpp`
- [IWR6843 radar](https://github.com/ntnu-arl/embedded_rio/blob/main/src/drivers/xwr6843aop.cpp): `src/drivers/xwr6843aop.cpp`
- [BMP388 barometer](https://github.com/ntnu-arl/embedded_rio/blob/main/src/drivers/bmp388.cpp): `src/drivers/bmp388.cpp`

### State estimation

- [ESKF fusion](https://github.com/ntnu-arl/embedded_rio/blob/main/src/filter/eskf_node.cpp): `src/filter/eskf_node.cpp`
- [RIO ESKF library](https://github.com/ntnu-arl/embedded_rio/tree/main/lib/rio-lib): `lib/rio-lib`

### Outputs and logging

- [MAVLink telemetry](https://github.com/ntnu-arl/embedded_rio/blob/main/src/io/telemetry.cpp): `src/io/telemetry.cpp`
- [USB diagnostics](https://github.com/ntnu-arl/embedded_rio/blob/main/src/io/debug.cpp): `src/io/debug.cpp`
- [Live serial plotter](https://github.com/ntnu-arl/embedded_rio/blob/main/scripts/serial_plotter.py): `scripts/serial_plotter.py`
- [SD card logger](https://github.com/ntnu-arl/embedded_rio/blob/main/src/io/sd_logger.cpp): `src/io/sd_logger.cpp`

### Offline replay and analysis

- [Replay runner](https://github.com/ntnu-arl/embedded_rio/blob/main/tools/replay/src/replay.cpp): `tools/replay/src/replay.cpp`
- [CSV log reader](https://github.com/ntnu-arl/embedded_rio/blob/main/tools/replay/src/log_reader.cpp): `tools/replay/src/log_reader.cpp`
- [Ablation analysis](https://github.com/ntnu-arl/embedded_rio/blob/main/tools/replay/scripts/compare_ablation.py): `tools/replay/scripts/compare_ablation.py`
- [PX4 ULog comparison](https://github.com/ntnu-arl/embedded_rio/blob/main/tools/replay/scripts/compare_with_ulog.py): `tools/replay/scripts/compare_with_ulog.py`
- [Run plots](https://github.com/ntnu-arl/embedded_rio/blob/main/tools/replay/scripts/plot_runs.py): `tools/replay/scripts/plot_runs.py`
- [Plot conventions](https://github.com/ntnu-arl/embedded_rio/blob/main/tools/replay/scripts/plot_style.py): `tools/replay/scripts/plot_style.py`

### Other components

- **PX4 flight controller**
- **SD card**
- **Recorded sensor log**

## Connections

- Firmware loop → BMI088 IMU: reads samples (evidence: `src/main.cpp`)
- Firmware loop → IWR6843 radar: drains frames (evidence: `src/main.cpp`)
- Firmware loop → BMP388 barometer: reads samples (evidence: `src/main.cpp`)
- Firmware loop → ESKF fusion: dispatches measurements (evidence: `src/main.cpp`)
- ESKF fusion → RIO ESKF library: runs filter (evidence: `README.md`)
- ESKF fusion → MAVLink telemetry: publishes state (evidence: `src/filter/eskf_node.cpp`)
- MAVLink telemetry → PX4 flight controller: streams MAVLink (evidence: `README.md`)
- ESKF fusion → USB diagnostics: prints state (evidence: `src/filter/eskf_node.cpp`)
- USB diagnostics → Live serial plotter: streams USB data (evidence: `README.md`)
- ESKF fusion → SD card logger: logs samples (evidence: `src/filter/eskf_node.cpp`)
- Firmware loop → SD card logger: flushes log (evidence: `src/main.cpp`)
- SD card logger → SD card: writes CSV (evidence: `README.md`)
- Recorded sensor log → CSV log reader: reads rows
- Replay runner → CSV log reader: loads events (evidence: `tools/replay/src/replay.cpp`)
- Replay runner → RIO ESKF library: runs shared ESKF (evidence: `README.md`)
- Replay runner → Ablation analysis: sweeps configurations (evidence: `README.md`)
- Replay runner → PX4 ULog comparison: compares estimates (evidence: `README.md`)
- Replay runner → Run plots: visualizes runs (evidence: `README.md`)
- Ablation analysis → Plot conventions: uses styles (evidence: `tools/replay/scripts/compare_ablation.py`)
- PX4 ULog comparison → Plot conventions: uses styles (evidence: `tools/replay/scripts/compare_with_ulog.py`)
- Run plots → Plot conventions: uses styles (evidence: `tools/replay/scripts/plot_runs.py`)
