This document outlines the core structural design and hardware-software interaction layers governing the Self-Balancing Robot platform. The architecture is explicitly decoupled, isolating rigid mathematics from variable external inputs to mathematically guarantee chassis stability.
The processing pipeline is segmented functionally into three primary execution domains:
- Sensory & Fusion Layer: Retrieves and cleans raw external environmental data.
- Kinetic Control Layer: The mathematical core translating state disparity into reactionary acceleration vectors.
- Actuation & Hardware Layer: Responsible strictly for generating perfectly uniform discrete electrical outputs.
graph TD
classDef hardware fill:#0b1d30,stroke:#2a5275,stroke-width:2px,color:#ffffff
classDef software fill:#16322b,stroke:#2a5f51,stroke-width:2px,color:#ffffff
classDef network fill:#312015,stroke:#704020,stroke-width:2px,color:#ffffff
subgraph Sensory Layer
IMU[ISM6HG256X IMU]:::hardware -->|I2C 400kHz| FUSION[Mahony AHRS Fusion]:::software
MAG[QMC5883L Compass]:::hardware -->|I2C 400kHz| FUSION
FUSION -->|Cascaded EMA Filter| STATE[Robot State: Pitch, Yaw]:::software
end
subgraph External Inputs
JOY[Joystick Transmitter]:::network -->|ESP-NOW| RECV[ESPNOW Receiver]:::software
TUNE[Bluetooth Serial Tuner]:::network -->|UART| UART_T[Param Parser]:::software
RECV --> TGT[Target Angle / Steering]:::software
UART_T --> C[Tuning Configurations]:::software
end
subgraph Kinetic Control
STATE --> PID_BAL[Balance PID Loop]:::software
STATE --> PID_YAW[Heading PID Loop]:::software
TGT --> PID_BAL
TGT --> PID_YAW
C --> PID_BAL
PID_BAL --> MIX[Kinematic Mixer]:::software
PID_YAW --> MIX
end
subgraph Actuation Layer
MIX -->|Steps/sec| TIMER[Timer ISR Bresenham 20kHz]:::software
TIMER -->|Fast UART| TMC1[Left TMC2208]:::hardware
TIMER -->|Fast UART| TMC2[Right TMC2208]:::hardware
TMC1 --> M1[Left NEMA17 Stepper]:::hardware
TMC2 --> M2[Right NEMA17 Stepper]:::hardware
end
The rigid foundational measurement stems from an ISM6HG256X high-performance 6-axis IMU, supplemented by a QMC5883L magnetometer for absolute heading tracking.
- Raw values enter the
Mahony AHRSmathematical filter. - The 9-DOF quaternion natively generated shields pitch measurements from magnetic interference, rendering a structurally pure 3D map of the chassis orientation.
- Secondary cascaded
Exponential Moving Average (EMA)algorithms surgically scrub remaining electromagnetic noise out of the finalized pitch angle variable before it ever reaches the control loops.
A rigidly constrained microcontroller loop evaluates exactly 200 times per second (
- Identifies external translation requests (from Bluetooth or ESP-NOW Joystick).
- The core Balance PID measures the discrepancy between mathematical upright and actual pitch.
- The Heading PID isolates any lateral variance restricting vehicle travel direction.
- Calculations are aggregated through a limiter capping acceleration change rates.
This layer operates completely detached from the primary logical sequence.
- The physics engine feeds absolute "Steps Per Second" integers exclusively into volatile memory registers.
- A background
Interrupt Service Routinetriggers exactly 20,000 times per second, managing Bresenham Accumulators for each wheel. - When an accumulator boundary is violated, native silicon overrides trigger the electrical step pin immediately, achieving zero-jitter mechanical pulses.
The ESP32 processes two disparate concurrent wireless network environments:
- An ultra-fast, connectionless protocol fundamentally identical to raw WiFi routing.
- The transmitter establishes fixed payload vectors representing intent, not mechanical realities.
- The robot dynamically incorporates this intent as mathematically filtered offsets against its own gravitational setpoint.
- An asynchronous text parser operating on
BluetoothSerial, permitting complex string evaluations. - Translates dynamic textual configuration instructions directly into variable manipulation modifying PID structural constraints natively on the fly without demanding code recompilation.