# ottodiy/ottodiylib architecture

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

- Interactive diagram: https://gitdiagram.com/ottodiy/ottodiylib
- Repository: https://github.com/ottodiy/ottodiylib

## Overview

OttoDIYLib is an Arduino runtime library for controlling a four-servo biped and its expressive outputs. The main workflow is a sketch initializing Otto with servo pins and calibration, then requesting motion, sound, gestures, or matrix output. The README documents additional example-driven workflows for Bluetooth commands, touch modes, obstacle avoidance, sensor readings, and melodies. Relationships involving unsampled examples are limited to those explicitly described; source excerpts establish the core motion, oscillator, and matrix implementation.

Main entry points: [`src/Otto.cpp`](https://github.com/ottodiy/ottodiylib/blob/main/src/Otto.cpp) (Otto API), [`examples`](https://github.com/ottodiy/ottodiylib/tree/main/examples) (Robot demo sketches), [`src/Otto_matrix.cpp`](https://github.com/ottodiy/ottodiylib/blob/main/src/Otto_matrix.cpp) (Matrix driver), [`src/Oscillator.cpp`](https://github.com/ottodiy/ottodiylib/blob/main/src/Oscillator.cpp) (Servo oscillator)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_robot_control["Robot control"]
  node_otto_api["Otto API<br/>[Otto.cpp]"]
  node_motion["Gaits and motion<br/>[Otto.cpp]"]
  node_oscillator["Servo oscillator<br/>[Oscillator.cpp]"]
  node_servos["Servo hardware"]
  node_calibration["Servo calibration<br/>[Otto.cpp]"]
end

subgraph group_expression["Expression"]
  node_gesture["Gesture sequences<br/>[Otto.cpp]"]
  node_gesture_data["Gesture definitions<br/>[Otto_gestures.h]"]
  node_sound["Songs and tones<br/>[Otto.cpp]"]
  node_sound_data["Sound definitions<br/>[Otto_sounds.h]"]
  node_mouth_data["Mouth patterns<br/>[Otto_mouths.h]"]
  node_matrix_driver["Matrix driver<br/>[Otto_matrix.cpp]"]
  node_matrix_hardware["LED matrix"]
end

subgraph group_interfaces["Interfaces and demos"]
  node_serial_parser["Serial command parser<br/>[SerialCommand.cpp]"]
  node_demo_sketches["Robot demo sketches"]
  node_sensors["Sensors and controls"]
end

node_sketch(("Arduino sketch"))
node_serial_client(("Bluetooth or serial sender"))

node_sketch -->|"initializes and commands"| node_otto_api
node_otto_api -->|"executes motions"| node_motion
node_motion -->|"refreshes servos"| node_oscillator
node_oscillator -->|"writes positions"| node_servos
node_otto_api -->|"loads and saves trims"| node_calibration
node_gesture -->|"combines movement"| node_motion
node_gesture -->|"combines sounds"| node_sound
node_gesture -.->|"shows expression"| node_matrix_driver
node_gesture -->|"uses gesture definitions"| node_gesture_data
node_otto_api -->|"plays songs and tones"| node_sound
node_sound -->|"uses sound names"| node_sound_data
node_otto_api -->|"controls display"| node_matrix_driver
node_otto_api -->|"renders mouth patterns"| node_mouth_data
node_matrix_driver -->|"drives display"| node_matrix_hardware
node_serial_client -.->|"sends commands"| node_serial_parser
node_serial_parser -->|"dispatches handlers"| node_sketch
node_sketch -->|"uses example workflows"| node_demo_sketches
node_demo_sketches -.->|"demonstrates robot actions"| node_otto_api
node_demo_sketches -.->|"reads sensor inputs"| node_sensors

click node_otto_api "https://github.com/ottodiy/ottodiylib/blob/main/src/Otto.cpp"
click node_motion "https://github.com/ottodiy/ottodiylib/blob/main/src/Otto.cpp"
click node_oscillator "https://github.com/ottodiy/ottodiylib/blob/main/src/Oscillator.cpp"
click node_calibration "https://github.com/ottodiy/ottodiylib/blob/main/src/Otto.cpp"
click node_gesture "https://github.com/ottodiy/ottodiylib/blob/main/src/Otto.cpp"
click node_gesture_data "https://github.com/ottodiy/ottodiylib/blob/main/src/Otto_gestures.h"
click node_sound "https://github.com/ottodiy/ottodiylib/blob/main/src/Otto.cpp"
click node_sound_data "https://github.com/ottodiy/ottodiylib/blob/main/src/Otto_sounds.h"
click node_mouth_data "https://github.com/ottodiy/ottodiylib/blob/main/src/Otto_mouths.h"
click node_matrix_driver "https://github.com/ottodiy/ottodiylib/blob/main/src/Otto_matrix.cpp"
click node_serial_parser "https://github.com/ottodiy/ottodiylib/blob/main/src/SerialCommand.cpp"
click node_demo_sketches "https://github.com/ottodiy/ottodiylib/tree/main/examples"

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_otto_api,node_motion,node_oscillator,node_servos,node_calibration toneBlue
class node_gesture,node_gesture_data,node_sound,node_sound_data,node_mouth_data,node_matrix_driver,node_matrix_hardware toneAmber
class node_serial_parser,node_demo_sketches,node_sensors toneMint
class node_sketch,node_serial_client toneIndigo
```

## Components

### Robot control

- [Otto API](https://github.com/ottodiy/ottodiylib/blob/main/src/Otto.cpp): `src/Otto.cpp`
- [Gaits and motion](https://github.com/ottodiy/ottodiylib/blob/main/src/Otto.cpp): `src/Otto.cpp`
- [Servo oscillator](https://github.com/ottodiy/ottodiylib/blob/main/src/Oscillator.cpp): `src/Oscillator.cpp`
- **Servo hardware**
- [Servo calibration](https://github.com/ottodiy/ottodiylib/blob/main/src/Otto.cpp): `src/Otto.cpp`

### Expression

- [Gesture sequences](https://github.com/ottodiy/ottodiylib/blob/main/src/Otto.cpp): `src/Otto.cpp`
- [Gesture definitions](https://github.com/ottodiy/ottodiylib/blob/main/src/Otto_gestures.h): `src/Otto_gestures.h`
- [Songs and tones](https://github.com/ottodiy/ottodiylib/blob/main/src/Otto.cpp): `src/Otto.cpp`
- [Sound definitions](https://github.com/ottodiy/ottodiylib/blob/main/src/Otto_sounds.h): `src/Otto_sounds.h`
- [Mouth patterns](https://github.com/ottodiy/ottodiylib/blob/main/src/Otto_mouths.h): `src/Otto_mouths.h`
- [Matrix driver](https://github.com/ottodiy/ottodiylib/blob/main/src/Otto_matrix.cpp): `src/Otto_matrix.cpp`
- **LED matrix**

### Interfaces and demos

- [Serial command parser](https://github.com/ottodiy/ottodiylib/blob/main/src/SerialCommand.cpp): `src/SerialCommand.cpp`
- [Robot demo sketches](https://github.com/ottodiy/ottodiylib/tree/main/examples): `examples`
- **Sensors and controls**

### Other components

- **Arduino sketch**
- **Bluetooth or serial sender**

## Connections

- Arduino sketch → Otto API: initializes and commands (evidence: `README.md`)
- Otto API → Gaits and motion: executes motions (evidence: `src/Otto.cpp`)
- Gaits and motion → Servo oscillator: refreshes servos (evidence: `src/Otto.cpp`)
- Servo oscillator → Servo hardware: writes positions (evidence: `src/Oscillator.cpp`)
- Otto API → Servo calibration: loads and saves trims (evidence: `README.md`)
- Gesture sequences → Gaits and motion: combines movement (evidence: `README.md`)
- Gesture sequences → Songs and tones: combines sounds (evidence: `README.md`)
- Gesture sequences → Matrix driver: shows expression
- Gesture sequences → Gesture definitions: uses gesture definitions (evidence: `src/Otto.cpp`)
- Otto API → Songs and tones: plays songs and tones (evidence: `README.md`)
- Songs and tones → Sound definitions: uses sound names
- Otto API → Matrix driver: controls display (evidence: `src/Otto.cpp`)
- Otto API → Mouth patterns: renders mouth patterns (evidence: `src/Otto.cpp`)
- Matrix driver → LED matrix: drives display (evidence: `src/Otto_matrix.cpp`)
- Bluetooth or serial sender → Serial command parser: sends commands
- Serial command parser → Arduino sketch: dispatches handlers (evidence: `src/SerialCommand.cpp`)
- Arduino sketch → Robot demo sketches: uses example workflows (evidence: `README.md`)
- Robot demo sketches → Otto API: demonstrates robot actions
- Robot demo sketches → Sensors and controls: reads sensor inputs
