# moonlight169/abu_manual_thailand architecture

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

- Interactive diagram: https://gitdiagram.com/moonlight169/abu_manual_thailand
- Repository: https://github.com/moonlight169/abu_manual_thailand

## Overview

This is firmware for a manually driven ABU Robocon robot, split across an ESP32 master and two STM32 slaves. The operator’s PS5 input is converted by the master into UART wheel and arm/box/lift commands; the wheel slave computes mecanum wheel targets and regulates motor output, while the arm slave handles manual motion and encoder-based positioning with limit and timeout safeguards. The README documents the distributed controller roles. Slave implementations are only partially excerpted, so unshown internal behavior is not expanded beyond supported relationships.

Main entry points: [`src/0_master/main.cpp`](https://github.com/moonlight169/abu_manual_thailand/blob/main/src/0_master/main.cpp) (Master control), [`src/2_slave_wheel/main.cpp`](https://github.com/moonlight169/abu_manual_thailand/blob/main/src/2_slave_wheel/main.cpp) (Wheel control), [`src/1_slave_arm/main.cpp`](https://github.com/moonlight169/abu_manual_thailand/blob/main/src/1_slave_arm/main.cpp) (Arm control), [`lib/Wheel/wheel.cpp`](https://github.com/moonlight169/abu_manual_thailand/blob/main/lib/Wheel/wheel.cpp) (Wheel assembly)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_operator["Operator input"]
end

subgraph group_master["Master control"]
  node_master_fw["Master control<br/>[main.cpp]"]
  node_ps5_input["Controller input<br/>[PS5Input.cpp]"]
  node_protocol["UART protocol<br/>[protocol.cpp]"]
  node_relay["Relay outputs<br/>[relay.cpp]"]
end

subgraph group_arm["Arm slave"]
  node_arm_fw["Arm control<br/>[main.cpp]"]
  node_motor_receiver["Command receiver<br/>[protocol.cpp]"]
  node_arm_motor["Arm motors<br/>[motor.cpp]"]
  node_arm_encoder["Arm encoder<br/>[encoder.cpp]"]
end

subgraph group_wheels["Wheel slave"]
  node_wheel_fw["Wheel control<br/>[main.cpp]"]
  node_wheel_receiver["Wheel receiver<br/>[protocol.cpp]"]
  node_kinematics["Mecanum kinematics<br/>[Kinematics.cpp]"]
  node_pid["PID control<br/>[PID.cpp]"]
  node_wheel["Wheel assembly<br/>[wheel.cpp]"]
  node_motor["Motor driver<br/>[motor.cpp]"]
  node_encoder["Wheel encoder<br/>[encoder.cpp]"]
end

node_ps5(("PS5 controller"))

node_ps5 -->|"controls"| node_master_fw
node_master_fw -->|"updates"| node_ps5_input
node_master_fw -->|"encodes commands"| node_protocol
node_master_fw -->|"toggles"| node_relay
node_master_fw -->|"sends UART commands"| node_arm_fw
node_master_fw -->|"sends UART commands"| node_wheel_fw
node_arm_fw -->|"feeds bytes"| node_motor_receiver
node_arm_fw -->|"drives"| node_arm_motor
node_arm_fw -->|"reads counts"| node_arm_encoder
node_wheel_fw -->|"feeds bytes"| node_wheel_receiver
node_wheel_fw -->|"calculates RPM"| node_kinematics
node_wheel_fw -->|"computes PWM"| node_pid
node_wheel_fw -->|"sets wheel speed"| node_wheel
node_wheel -->|"uses"| node_motor
node_wheel -->|"uses"| node_encoder

click node_master_fw "https://github.com/moonlight169/abu_manual_thailand/blob/main/src/0_master/main.cpp"
click node_ps5_input "https://github.com/moonlight169/abu_manual_thailand/blob/main/lib/PS5Input/PS5Input.cpp"
click node_protocol "https://github.com/moonlight169/abu_manual_thailand/blob/main/lib/Protocol/protocol.cpp"
click node_relay "https://github.com/moonlight169/abu_manual_thailand/blob/main/lib/Relay/relay.cpp"
click node_arm_fw "https://github.com/moonlight169/abu_manual_thailand/blob/main/src/1_slave_arm/main.cpp"
click node_motor_receiver "https://github.com/moonlight169/abu_manual_thailand/blob/main/lib/Protocol/protocol.cpp"
click node_arm_motor "https://github.com/moonlight169/abu_manual_thailand/blob/main/lib/Wheel/motor.cpp"
click node_arm_encoder "https://github.com/moonlight169/abu_manual_thailand/blob/main/lib/Wheel/encoder.cpp"
click node_wheel_fw "https://github.com/moonlight169/abu_manual_thailand/blob/main/src/2_slave_wheel/main.cpp"
click node_wheel_receiver "https://github.com/moonlight169/abu_manual_thailand/blob/main/lib/Protocol/protocol.cpp"
click node_kinematics "https://github.com/moonlight169/abu_manual_thailand/blob/main/lib/Kinematics/Kinematics.cpp"
click node_pid "https://github.com/moonlight169/abu_manual_thailand/blob/main/lib/PID/PID.cpp"
click node_wheel "https://github.com/moonlight169/abu_manual_thailand/blob/main/lib/Wheel/wheel.cpp"
click node_motor "https://github.com/moonlight169/abu_manual_thailand/blob/main/lib/Wheel/motor.cpp"
click node_encoder "https://github.com/moonlight169/abu_manual_thailand/blob/main/lib/Wheel/encoder.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_master_fw,node_ps5_input,node_protocol,node_relay toneAmber
class node_arm_fw,node_motor_receiver,node_arm_motor,node_arm_encoder toneMint
class node_wheel_fw,node_wheel_receiver,node_kinematics,node_pid,node_wheel,node_motor,node_encoder toneRose
class node_ps5 toneIndigo
```

## Components

### Master control

- [Master control](https://github.com/moonlight169/abu_manual_thailand/blob/main/src/0_master/main.cpp): `src/0_master/main.cpp`
- [Controller input](https://github.com/moonlight169/abu_manual_thailand/blob/main/lib/PS5Input/PS5Input.cpp): `lib/PS5Input/PS5Input.cpp`
- [UART protocol](https://github.com/moonlight169/abu_manual_thailand/blob/main/lib/Protocol/protocol.cpp): `lib/Protocol/protocol.cpp`
- [Relay outputs](https://github.com/moonlight169/abu_manual_thailand/blob/main/lib/Relay/relay.cpp): `lib/Relay/relay.cpp`

### Arm slave

- [Arm control](https://github.com/moonlight169/abu_manual_thailand/blob/main/src/1_slave_arm/main.cpp): `src/1_slave_arm/main.cpp`
- [Command receiver](https://github.com/moonlight169/abu_manual_thailand/blob/main/lib/Protocol/protocol.cpp): `lib/Protocol/protocol.cpp`
- [Arm motors](https://github.com/moonlight169/abu_manual_thailand/blob/main/lib/Wheel/motor.cpp): `lib/Wheel/motor.cpp`
- [Arm encoder](https://github.com/moonlight169/abu_manual_thailand/blob/main/lib/Wheel/encoder.cpp): `lib/Wheel/encoder.cpp`

### Wheel slave

- [Wheel control](https://github.com/moonlight169/abu_manual_thailand/blob/main/src/2_slave_wheel/main.cpp): `src/2_slave_wheel/main.cpp`
- [Wheel receiver](https://github.com/moonlight169/abu_manual_thailand/blob/main/lib/Protocol/protocol.cpp): `lib/Protocol/protocol.cpp`
- [Mecanum kinematics](https://github.com/moonlight169/abu_manual_thailand/blob/main/lib/Kinematics/Kinematics.cpp): `lib/Kinematics/Kinematics.cpp`
- [PID control](https://github.com/moonlight169/abu_manual_thailand/blob/main/lib/PID/PID.cpp): `lib/PID/PID.cpp`
- [Wheel assembly](https://github.com/moonlight169/abu_manual_thailand/blob/main/lib/Wheel/wheel.cpp): `lib/Wheel/wheel.cpp`
- [Motor driver](https://github.com/moonlight169/abu_manual_thailand/blob/main/lib/Wheel/motor.cpp): `lib/Wheel/motor.cpp`
- [Wheel encoder](https://github.com/moonlight169/abu_manual_thailand/blob/main/lib/Wheel/encoder.cpp): `lib/Wheel/encoder.cpp`

### Other components

- **PS5 controller**

## Connections

- PS5 controller → Master control: controls (evidence: `README.md`)
- Master control → Controller input: updates (evidence: `src/0_master/main.cpp`)
- Master control → UART protocol: encodes commands (evidence: `src/0_master/main.cpp`)
- Master control → Relay outputs: toggles (evidence: `src/0_master/main.cpp`)
- Master control → Arm control: sends UART commands (evidence: `src/0_master/main.cpp`)
- Master control → Wheel control: sends UART commands (evidence: `src/0_master/main.cpp`)
- Arm control → Command receiver: feeds bytes (evidence: `src/1_slave_arm/main.cpp`)
- Arm control → Arm motors: drives (evidence: `src/1_slave_arm/main.cpp`)
- Arm control → Arm encoder: reads counts (evidence: `src/1_slave_arm/main.cpp`)
- Wheel control → Wheel receiver: feeds bytes (evidence: `src/2_slave_wheel/main.cpp`)
- Wheel control → Mecanum kinematics: calculates RPM (evidence: `src/2_slave_wheel/main.cpp`)
- Wheel control → PID control: computes PWM (evidence: `src/2_slave_wheel/main.cpp`)
- Wheel control → Wheel assembly: sets wheel speed (evidence: `src/2_slave_wheel/main.cpp`)
- Wheel assembly → Motor driver: uses
- Wheel assembly → Wheel encoder: uses
