# olyptea/kia architecture

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

- Interactive diagram: https://gitdiagram.com/olyptea/kia
- Repository: https://github.com/olyptea/kia

## Overview

Kia Arm Controller combines ESP32 firmware for local robot control with Kia Studio, a desktop application for teleoperation, calibration, visualization, and telemetry. The principal workflow runs from a Studio command over USB/BLE through firmware communications and motion control to servo outputs; sensor inputs and safety monitoring affect operation. Firmware also supports manual potentiometer control, persistent calibration, mode management, telemetry, and OTA. The graph uses README claims for documented capabilities and sampled source for boot wiring and selected calls; unsampled subsystem links are omitted where their callers are not shown.

Main entry points: [`2-Firmware/main/main.c`](https://github.com/olyptea/kia/blob/main/2-Firmware/main/main.c) (Firmware boot), [`2-Firmware/components/svc_motion/svc_motion.c`](https://github.com/olyptea/kia/blob/main/2-Firmware/components/svc_motion/svc_motion.c) (Motion control), [`3-Software/kia_studio/ui/main_window.py`](https://github.com/olyptea/kia/blob/main/3-Software/kia_studio/ui/main_window.py) (Studio window), [`3-Software/kia_studio/ui/widgets/viewport_gl.py`](https://github.com/olyptea/kia/blob/main/3-Software/kia_studio/ui/widgets/viewport_gl.py) (3D viewports)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_firmware["Firmware runtime"]
  node_main["Firmware boot<br/>[main.c]"]
  node_fsm["Mode state machine<br/>[app_mode_fsm.c]"]
  node_motion["Motion control<br/>[svc_motion.c]"]
  node_calibration["Calibration<br/>[app_calibration.c]"]
  node_storage[("Calibration storage<br/>[svc_storage.c]")]
  node_safety["Safety monitor<br/>[svc_safety.c]"]
  node_ota["OTA updates<br/>[svc_ota.c]"]
  node_telemetry["Telemetry<br/>[svc_telemetry.c]"]
  node_comm["Command router<br/>[comm_router.c]"]
end

subgraph group_hardware["Hardware interfaces"]
  node_pots["Potentiometer driver<br/>[drv_pot.c]"]
  node_servos["Servo driver<br/>[drv_servo.c]"]
  node_ina["INA219 monitor<br/>[drv_ina219.c]"]
  node_buttons["Button driver<br/>[drv_buttons.c]"]
end

subgraph group_studio["Kia Studio"]
  node_studio_window["Studio window<br/>[main_window.py]"]
  node_qt_client["Qt client adapter<br/>[qt_client.py]"]
  node_panels["Teleop and calibration UI<br/>[calib_panel.py]"]
  node_viewport["3D viewports<br/>[viewport_gl.py]"]
  node_mesh_config["Mesh configuration<br/>[mesh_config.py]"]
end

subgraph group_protocol["Protocol and transport"]
  node_client["Protocol client<br/>[client.py]"]
  node_codec["Frame codec<br/>[codec.py]"]
  node_opcodes["Protocol operations<br/>[opcodes.py]"]
  node_transport["USB and BLE transport"]
end

subgraph group_robot_math["Robot modeling"]
  node_kinematics["Kinematics<br/>[kinematics.py]"]
  node_joints["Joint model<br/>[joints.py]"]
  node_trajectory["Trajectory model<br/>[trajectory.py]"]
  node_mesh_loader["STL mesh loader<br/>[mesh_loader.py]"]
end

node_operator(("Operator"))
node_pc(("Studio user"))

node_operator -.->|"triggers modes"| node_buttons
node_operator -.->|"sets manual targets"| node_pots
node_pc -.->|"operates"| node_studio_window
node_studio_window -->|"sends commands"| node_qt_client
node_studio_window -->|"hosts panels"| node_panels
node_studio_window -->|"selects viewport"| node_viewport
node_qt_client -->|"adapts callbacks"| node_client
node_client -->|"encodes frames"| node_codec
node_client -->|"uses operations"| node_opcodes
node_client -.->|"transmits frames"| node_transport
node_transport -.->|"delivers commands"| node_comm
node_comm -.->|"routes motion"| node_motion
node_main -->|"initializes"| node_storage
node_main -->|"initializes"| node_safety
node_main -->|"initializes"| node_motion
node_main -->|"initializes"| node_fsm
node_main -->|"initializes"| node_ota
node_main -->|"initializes"| node_telemetry
node_main -->|"initializes"| node_comm
node_motion -->|"reads targets"| node_pots
node_motion -->|"sets angles"| node_servos
node_motion -.->|"solves poses"| node_kinematics
node_motion -.->|"interpolates motion"| node_trajectory
node_safety -.->|"monitors current"| node_ina
node_calibration -.->|"saves offsets"| node_storage
node_storage -->|"loads calibration"| node_servos
node_storage -->|"loads calibration"| node_pots
node_panels -->|"uses solver"| node_kinematics
node_viewport -->|"computes link frames"| node_kinematics
node_viewport -->|"renders meshes"| node_mesh_loader
node_viewport -->|"uses calibration"| node_mesh_config
node_kinematics -->|"uses joint model"| node_joints

click node_main "https://github.com/olyptea/kia/blob/main/2-Firmware/main/main.c"
click node_fsm "https://github.com/olyptea/kia/blob/main/2-Firmware/components/app_mode_fsm/app_mode_fsm.c"
click node_motion "https://github.com/olyptea/kia/blob/main/2-Firmware/components/svc_motion/svc_motion.c"
click node_calibration "https://github.com/olyptea/kia/blob/main/2-Firmware/components/app_calibration/app_calibration.c"
click node_storage "https://github.com/olyptea/kia/blob/main/2-Firmware/components/svc_storage/svc_storage.c"
click node_safety "https://github.com/olyptea/kia/blob/main/2-Firmware/components/svc_safety/svc_safety.c"
click node_ota "https://github.com/olyptea/kia/blob/main/2-Firmware/components/svc_ota/svc_ota.c"
click node_telemetry "https://github.com/olyptea/kia/blob/main/2-Firmware/components/svc_telemetry/svc_telemetry.c"
click node_comm "https://github.com/olyptea/kia/blob/main/2-Firmware/components/svc_comm/comm_router.c"
click node_pots "https://github.com/olyptea/kia/blob/main/2-Firmware/components/drv_pot/drv_pot.c"
click node_servos "https://github.com/olyptea/kia/blob/main/2-Firmware/components/drv_servo/drv_servo.c"
click node_ina "https://github.com/olyptea/kia/blob/main/2-Firmware/components/drv_ina219/drv_ina219.c"
click node_buttons "https://github.com/olyptea/kia/blob/main/2-Firmware/components/drv_buttons/drv_buttons.c"
click node_studio_window "https://github.com/olyptea/kia/blob/main/3-Software/kia_studio/ui/main_window.py"
click node_qt_client "https://github.com/olyptea/kia/blob/main/3-Software/kia_studio/ui/qt_client.py"
click node_panels "https://github.com/olyptea/kia/blob/main/3-Software/kia_studio/ui/widgets/calib_panel.py"
click node_viewport "https://github.com/olyptea/kia/blob/main/3-Software/kia_studio/ui/widgets/viewport_gl.py"
click node_mesh_config "https://github.com/olyptea/kia/blob/main/3-Software/kia_studio/ui/mesh_config.py"
click node_client "https://github.com/olyptea/kia/blob/main/3-Software/kia_studio/proto/client.py"
click node_codec "https://github.com/olyptea/kia/blob/main/3-Software/kia_studio/proto/codec.py"
click node_opcodes "https://github.com/olyptea/kia/blob/main/3-Software/kia_studio/proto/opcodes.py"
click node_transport "https://github.com/olyptea/kia/blob/main/2-Firmware/components/svc_comm/transport_usb_cdc.c"
click node_kinematics "https://github.com/olyptea/kia/blob/main/3-Software/kia_studio/core/kinematics.py"
click node_joints "https://github.com/olyptea/kia/blob/main/3-Software/kia_studio/core/joints.py"
click node_trajectory "https://github.com/olyptea/kia/blob/main/3-Software/kia_studio/core/trajectory.py"
click node_mesh_loader "https://github.com/olyptea/kia/blob/main/3-Software/kia_studio/core/mesh_loader.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_main,node_fsm,node_motion,node_calibration,node_storage,node_safety,node_ota,node_telemetry,node_comm,node_pc toneBlue
class node_pots,node_servos,node_ina,node_buttons toneAmber
class node_studio_window,node_qt_client,node_panels,node_viewport,node_mesh_config toneMint
class node_client,node_codec,node_opcodes,node_transport toneRose
class node_kinematics,node_joints,node_trajectory,node_mesh_loader,node_operator toneIndigo
```

## Components

### Firmware runtime

- [Firmware boot](https://github.com/olyptea/kia/blob/main/2-Firmware/main/main.c): `2-Firmware/main/main.c`
- [Mode state machine](https://github.com/olyptea/kia/blob/main/2-Firmware/components/app_mode_fsm/app_mode_fsm.c): `2-Firmware/components/app_mode_fsm/app_mode_fsm.c`
- [Motion control](https://github.com/olyptea/kia/blob/main/2-Firmware/components/svc_motion/svc_motion.c): `2-Firmware/components/svc_motion/svc_motion.c`
- [Calibration](https://github.com/olyptea/kia/blob/main/2-Firmware/components/app_calibration/app_calibration.c): `2-Firmware/components/app_calibration/app_calibration.c`
- [Calibration storage](https://github.com/olyptea/kia/blob/main/2-Firmware/components/svc_storage/svc_storage.c): `2-Firmware/components/svc_storage/svc_storage.c`
- [Safety monitor](https://github.com/olyptea/kia/blob/main/2-Firmware/components/svc_safety/svc_safety.c): `2-Firmware/components/svc_safety/svc_safety.c`
- [OTA updates](https://github.com/olyptea/kia/blob/main/2-Firmware/components/svc_ota/svc_ota.c): `2-Firmware/components/svc_ota/svc_ota.c`
- [Telemetry](https://github.com/olyptea/kia/blob/main/2-Firmware/components/svc_telemetry/svc_telemetry.c): `2-Firmware/components/svc_telemetry/svc_telemetry.c`
- [Command router](https://github.com/olyptea/kia/blob/main/2-Firmware/components/svc_comm/comm_router.c): `2-Firmware/components/svc_comm/comm_router.c`

### Hardware interfaces

- [Potentiometer driver](https://github.com/olyptea/kia/blob/main/2-Firmware/components/drv_pot/drv_pot.c): `2-Firmware/components/drv_pot/drv_pot.c`
- [Servo driver](https://github.com/olyptea/kia/blob/main/2-Firmware/components/drv_servo/drv_servo.c): `2-Firmware/components/drv_servo/drv_servo.c`
- [INA219 monitor](https://github.com/olyptea/kia/blob/main/2-Firmware/components/drv_ina219/drv_ina219.c): `2-Firmware/components/drv_ina219/drv_ina219.c`
- [Button driver](https://github.com/olyptea/kia/blob/main/2-Firmware/components/drv_buttons/drv_buttons.c): `2-Firmware/components/drv_buttons/drv_buttons.c`

### Kia Studio

- [Studio window](https://github.com/olyptea/kia/blob/main/3-Software/kia_studio/ui/main_window.py): `3-Software/kia_studio/ui/main_window.py`
- [Qt client adapter](https://github.com/olyptea/kia/blob/main/3-Software/kia_studio/ui/qt_client.py): `3-Software/kia_studio/ui/qt_client.py`
- [Teleop and calibration UI](https://github.com/olyptea/kia/blob/main/3-Software/kia_studio/ui/widgets/calib_panel.py): `3-Software/kia_studio/ui/widgets/calib_panel.py`
- [3D viewports](https://github.com/olyptea/kia/blob/main/3-Software/kia_studio/ui/widgets/viewport_gl.py): `3-Software/kia_studio/ui/widgets/viewport_gl.py`
- [Mesh configuration](https://github.com/olyptea/kia/blob/main/3-Software/kia_studio/ui/mesh_config.py): `3-Software/kia_studio/ui/mesh_config.py`

### Protocol and transport

- [Protocol client](https://github.com/olyptea/kia/blob/main/3-Software/kia_studio/proto/client.py): `3-Software/kia_studio/proto/client.py`
- [Frame codec](https://github.com/olyptea/kia/blob/main/3-Software/kia_studio/proto/codec.py): `3-Software/kia_studio/proto/codec.py`
- [Protocol operations](https://github.com/olyptea/kia/blob/main/3-Software/kia_studio/proto/opcodes.py): `3-Software/kia_studio/proto/opcodes.py`
- [USB and BLE transport](https://github.com/olyptea/kia/blob/main/2-Firmware/components/svc_comm/transport_usb_cdc.c): `2-Firmware/components/svc_comm/transport_usb_cdc.c`

### Robot modeling

- [Kinematics](https://github.com/olyptea/kia/blob/main/3-Software/kia_studio/core/kinematics.py): `3-Software/kia_studio/core/kinematics.py`
- [Joint model](https://github.com/olyptea/kia/blob/main/3-Software/kia_studio/core/joints.py): `3-Software/kia_studio/core/joints.py`
- [Trajectory model](https://github.com/olyptea/kia/blob/main/3-Software/kia_studio/core/trajectory.py): `3-Software/kia_studio/core/trajectory.py`
- [STL mesh loader](https://github.com/olyptea/kia/blob/main/3-Software/kia_studio/core/mesh_loader.py): `3-Software/kia_studio/core/mesh_loader.py`

### Other components

- **Operator**
- **Studio user**

## Connections

- Operator → Button driver: triggers modes
- Operator → Potentiometer driver: sets manual targets
- Studio user → Studio window: operates
- Studio window → Qt client adapter: sends commands (evidence: `3-Software/kia_studio/ui/main_window.py`)
- Studio window → Teleop and calibration UI: hosts panels (evidence: `3-Software/kia_studio/ui/main_window.py`)
- Studio window → 3D viewports: selects viewport (evidence: `3-Software/kia_studio/ui/main_window.py`)
- Qt client adapter → Protocol client: adapts callbacks (evidence: `3-Software/kia_studio/ui/qt_client.py`)
- Protocol client → Frame codec: encodes frames (evidence: `3-Software/kia_studio/proto/client.py`)
- Protocol client → Protocol operations: uses operations (evidence: `3-Software/kia_studio/proto/client.py`)
- Protocol client → USB and BLE transport: transmits frames
- USB and BLE transport → Command router: delivers commands
- Command router → Motion control: routes motion
- Firmware boot → Calibration storage: initializes (evidence: `2-Firmware/main/main.c`)
- Firmware boot → Safety monitor: initializes (evidence: `2-Firmware/main/main.c`)
- Firmware boot → Motion control: initializes (evidence: `2-Firmware/main/main.c`)
- Firmware boot → Mode state machine: initializes (evidence: `2-Firmware/main/main.c`)
- Firmware boot → OTA updates: initializes (evidence: `2-Firmware/main/main.c`)
- Firmware boot → Telemetry: initializes (evidence: `2-Firmware/main/main.c`)
- Firmware boot → Command router: initializes (evidence: `2-Firmware/main/main.c`)
- Motion control → Potentiometer driver: reads targets (evidence: `2-Firmware/components/svc_motion/svc_motion.c`)
- Motion control → Servo driver: sets angles (evidence: `2-Firmware/components/svc_motion/svc_motion.c`)
- Motion control → Kinematics: solves poses
- Motion control → Trajectory model: interpolates motion
- Safety monitor → INA219 monitor: monitors current
- Calibration → Calibration storage: saves offsets
- Calibration storage → Servo driver: loads calibration (evidence: `2-Firmware/components/svc_storage/svc_storage.c`)
- Calibration storage → Potentiometer driver: loads calibration (evidence: `2-Firmware/components/svc_storage/svc_storage.c`)
- Teleop and calibration UI → Kinematics: uses solver (evidence: `3-Software/kia_studio/ui/widgets/calib_panel.py`)
- 3D viewports → Kinematics: computes link frames (evidence: `3-Software/kia_studio/ui/widgets/viewport_gl.py`)
- 3D viewports → STL mesh loader: renders meshes (evidence: `3-Software/kia_studio/ui/widgets/viewport_gl.py`)
- 3D viewports → Mesh configuration: uses calibration (evidence: `3-Software/kia_studio/ui/widgets/viewport_gl.py`)
- Kinematics → Joint model: uses joint model (evidence: `3-Software/kia_studio/core/kinematics.py`)
