# arduino-libraries/madgwickahrs architecture

> Architecture diagram of the GitHub repository arduino-libraries/madgwickahrs, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-21). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/arduino-libraries/madgwickahrs
- Repository: https://github.com/arduino-libraries/madgwickahrs

## Overview

MadgwickAHRS is a small Arduino C++ library that estimates orientation from accelerometer and gyroscope readings, with an optional magnetometer for the AHRS update. A caller configures the sample frequency, supplies sensor samples to update() or updateIMU(), then reads roll, pitch, or yaw in degrees or radians. The implementation maintains quaternion state, computes angles lazily, and falls back to the IMU algorithm when magnetometer input is zero. The README mentions this capability; the graph focuses on the two core source files and the documented sensor-to-orientation workflow.

Main entry points: [`src/MadgwickAHRS.h`](https://github.com/arduino-libraries/madgwickahrs/blob/master/src/MadgwickAHRS.h) (Madgwick API), [`src/MadgwickAHRS.cpp`](https://github.com/arduino-libraries/madgwickahrs/blob/master/src/MadgwickAHRS.cpp) (AHRS and IMU update)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_library["Orientation library"]
  node_api["Madgwick API<br/>[MadgwickAHRS.h]"]
end

subgraph group_algorithm["Estimation internals"]
  node_fusion["AHRS and IMU update<br/>[MadgwickAHRS.cpp]"]
  node_orientation["Orientation angles<br/>[MadgwickAHRS.cpp]"]
end

node_caller(("Arduino caller"))

node_caller -->|"configures and supplies samples"| node_api
node_api -->|"updates state"| node_fusion
node_caller -->|"reads angles"| node_api
node_api -->|"computes on demand"| node_orientation
node_fusion -->|"derives from quaternion"| node_orientation

click node_api "https://github.com/arduino-libraries/madgwickahrs/blob/master/src/MadgwickAHRS.h"
click node_fusion "https://github.com/arduino-libraries/madgwickahrs/blob/master/src/MadgwickAHRS.cpp"
click node_orientation "https://github.com/arduino-libraries/madgwickahrs/blob/master/src/MadgwickAHRS.cpp"

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_api toneBlue
class node_fusion,node_orientation toneAmber
class node_caller toneIndigo
```

## Components

### Orientation library

- [Madgwick API](https://github.com/arduino-libraries/madgwickahrs/blob/master/src/MadgwickAHRS.h): `src/MadgwickAHRS.h`

### Estimation internals

- [AHRS and IMU update](https://github.com/arduino-libraries/madgwickahrs/blob/master/src/MadgwickAHRS.cpp): `src/MadgwickAHRS.cpp`
- [Orientation angles](https://github.com/arduino-libraries/madgwickahrs/blob/master/src/MadgwickAHRS.cpp): `src/MadgwickAHRS.cpp`

### Other components

- **Arduino caller**

## Connections

- Arduino caller → Madgwick API: configures and supplies samples (evidence: `src/MadgwickAHRS.h`)
- Madgwick API → AHRS and IMU update: updates state (evidence: `src/MadgwickAHRS.cpp`)
- Arduino caller → Madgwick API: reads angles (evidence: `src/MadgwickAHRS.h`)
- Madgwick API → Orientation angles: computes on demand (evidence: `src/MadgwickAHRS.h`)
- AHRS and IMU update → Orientation angles: derives from quaternion (evidence: `src/MadgwickAHRS.cpp`)
