# zeroth-robotics/zeroth-bot architecture

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

- Interactive diagram: https://gitdiagram.com/zeroth-robotics/zeroth-bot
- Repository: https://github.com/zeroth-robotics/zeroth-bot

## Overview

<explanation>
1. Identify the project type and purpose  
   - This is an open‑source robotics platform (“Zeroth Bot”), combining hardware, firmware, simulation, ML models, and user‑level experiment scripts into one monorepo.  
   - Purpose: Provide an end‑to‑end humanoid robot stack—3D‑printed hardware with sensors/actuators, embedded firmware, host‑side SDK, simulation (URDF/meshes), ML inference, and high‑level Python experiments (teleop, plotting, training).

2. Analyze the file structure  
   - Top‑level directories:  
     • buildroot – embedded Linux build for on‑board computer  
     • experiments – Python scripts for running sim and real‑robot experiments (IMU logging, teleop, model evaluation)  
     • kos-zbot – Rust code for the robot SDK & firmware drivers, plus tonic (gRPC) support  
     • models – ML model artifacts and conversion scripts  
     • public – static assets for site/documentation  
     • runtime/firmware – older or auxiliary firmware utilities  
   - Key config and CI: .gitlab‑ci.yml, Dockerfile for toolchain, Cargo.toml  

3. Readme insights  
   - Confirms end‑to‑end sim2real robotics platform, with community SDK, docs, and hardware files (URDF + STL meshes).  

4. Main components to show in the diagram  
   a. Hardware Layer  
      - Actuators (Feetech servos, STS3215, zero‑position drivers)  
      - Sensors (IMU BMI088/BNO055, LED matrix, TPU accelerator)  
      - On‑board compute (embedded Linux via buildroot or microcontroller)  
   b. Firmware & Drivers (Rust & C wrappers)  
      - kos-zbot/src/firmware modules (cvitek, feetech_servo, efuse, servo_driver)  
      - C wrappers under firmware/cviwrapper, efuse, feetech in kos-zbot/firmware  
   c. Middleware & Communication  
      - gRPC interface (tonic folder) between host SDK and on‑board agent  
      - Serial/USB links for real‑robot communication  
   d. Host‑side SDK & Tools  
      - Rust library (kos-zbot/src/lib.rs) and binaries (bin/*) for calibration, scanning, etc.  
      - Python experiment scripts (experiments/run.py, imu.py, model.py, robot.py, teleop/main.py)  
      - URDF, STL meshes for sim in experiments/teleop/urdf  
   e. Simulation & ML  
      - URDF‑based sim environment (mesh assets + ROS/Gazebo or custom sim)  
      - ML models (models/standing.pt, TPU‑MLIR pipeline)  
   f. CI/CD and Toolchain  
      - Docker toolchain (toolchain-docker-img/Dockerfile)  
      - GitLab CI for automated build/test  

5. Relationships and interactions  
   - Host SDK ↔ on‑board firmware: via gRPC or serial commands  
   - Python experiments ↔ Host SDK: through SDK’s CLI or Python bindings (via cffi or subprocess)  
   - Simulation uses URDF and meshes to emulate hardware, feeding back simulated sensor data to experiments  
   - ML inference runs on embedded TPU or on host (depending on configuration)  
   - CI/CD builds Docker images → cross‑compile firmware & Rust SDK → deploy artifacts  

6. Architectural patterns and principles  
   - Layered architecture: hardware → firmware → middleware → SDK → user‑level applications  
   - Clear separation of concerns:  
     • Low‑level drivers in Rust/C  
     • Comm layer (gRPC/serial)  
     • High‑level logic in Python experiments  
   - Extensibility: plugin‑style servo drivers, model conversion scripts, support for multiple IMUs/servos  
   - Sim2Real: same SDK & scripts work in both sim and real hardware  

7. Tailoring the diagram  
   - Emphasize front‑end (Python/experiments) vs. back‑end (Rust SDK & firmware) for a robotics full‑stack app  
   - Show sim environment as a parallel path to real hardware  
   - Highlight the ML inference path (model → TPU → control loop)  

8. Diagram guidelines for the principal engineer  
   - Components as boxes, arranged in layers from bottom (hardware) to top (experiments)  
   - Label each box clearly: “Feetech Servo Driver”, “IMU Driver”, “gRPC Server”, “Python Teleop”  
   - Use directional arrows:  
     • Solid lines for real‑robot data flows (serial → firmware → SDK → Python)  
     • Dashed lines for simulation flows (URDF mesh → sim engine → Python)  
     • Dotted lines for build/CI pipelines  
   - Color‑code by type:  
     • Blue for hardware/drivers  
     • Green for middleware/communication  
     • Orange for SDK/tools  
     • Purple for user‑level scripts & simulation  
   - Group related files under folder icons or swimlanes (e.g., “kos-zbot/” folder → firmware & SDK cluster)  
   - Include callouts for external services: “GitLab CI”, “Docker Registry”, “Docs Site”  

9. Emphasize detail  
   - Capture each major folder as an architectural component  
   - Call out the dual sim/real paths  
   - Show ML model conversion & deployment pipeline  

Following these steps and guidelines will yield a precise, detailed system architecture diagram that reflects the full-stack nature of Zeroth Bot—from 3D‑printed hardware all the way up to Python‑based experiments.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Hardware Layer
    subgraph "Hardware Layer"
        direction TB
        FeetechServo["Feetech Servo Driver"]:::hardware
        STS3215["STS3215 Driver"]:::hardware
        BMI088["IMU BMI088 Driver"]:::hardware
        BNO055["IMU BNO055 Driver"]:::hardware
        LEDMatrix["LED Matrix Driver"]:::hardware
        Compute["Embedded Linux (Buildroot)"]:::hardware
    end

    %% Firmware & Drivers
    subgraph "Firmware & Drivers"
        direction TB
        CWrapper["SoC & Peripheral C Wrappers"]:::firmware
        EfuseC["EFuse C Wrapper"]:::firmware
        FeetechC["Feetech C Wrapper"]:::firmware
        STS3215C["STS3215 C Wrapper"]:::firmware
    end

    %% Middleware & Communication
    subgraph "Middleware & Communication"
        direction TB
        GRPC["gRPC Interface (Tonic)"]:::middleware
        Serial["Serial/USB Link"]:::middleware
    end

    %% Host-side SDK & Tools
    subgraph "Host-side SDK & Tools"
        direction TB
        RustLib["Rust Library"]:::sdk
        RustCLI["Rust CLI Tools"]:::sdk
    end

    %% Experiments & Simulation
    subgraph "Experiments & Simulation"
        direction TB
        PythonRun["run.py"]:::experiments
        PythonIMU["imu.py"]:::experiments
        PythonModel["model.py"]:::experiments
        PythonPlot["plot.py"]:::experiments
        PythonRobot["robot.py"]:::experiments
        TeleopMain["teleop/main.py"]:::experiments
        URDF["URDF (robot_fixed.urdf)"]:::experiments
        Meshes["STL Meshes"]:::experiments
        SimEngine["Simulation Engine"]:::experiments
    end

    %% ML Models & Conversion
    subgraph "ML Models & Conversion"
        direction TB
        MLModel["standing.pt"]:::experiments
        ConvertModel["convert_model.sh"]:::experiments
        TPUPipeline["tpu-mlir"]:::experiments
    end

    %% CI/CD & Toolchain
    subgraph "CI/CD & Toolchain"
        direction TB
        GitLabCI[".gitlab-ci.yml"]:::ci
        Dockerfile["toolchain-docker-img/Dockerfile"]:::ci
    end

    %% Relationships - Real Robot Path
    FeetechServo -->|controls| Compute
    STS3215 -->|controls| Compute
    BMI088 -->|senses| Compute
    BNO055 -->|senses| Compute
    LEDMatrix -->|displays| Compute
    Compute -->|runs| CWrapper
    CWrapper -->|calls| GRPC
    EfuseC -->|calls| GRPC
    FeetechC -->|calls| GRPC
    STS3215C -->|calls| GRPC
    GRPC -->|exposes API| RustLib
    Serial -->|fallback link| RustLib
    RustLib -->|provides bindings| RustCLI
    RustCLI -->|invoked by| PythonRun
    RustCLI -->|invoked by| PythonIMU
    RustCLI -->|invoked by| PythonModel
    RustCLI -->|invoked by| PythonPlot
    RustCLI -->|invoked by| PythonRobot

    %% Relationships - Simulation Path
    URDF -->|feeds| SimEngine
    Meshes -->|feeds| SimEngine
    SimEngine -->|sim data| PythonRun
    SimEngine -->|sim data| PythonIMU
    SimEngine -->|sim data| PythonModel
    SimEngine -->|sim data| PythonPlot
    SimEngine -->|sim data| PythonRobot
    TeleopMain -->|uses| SimEngine

    %% ML Inference Path
    MLModel -->|converted by| ConvertModel
    ConvertModel -->|produces| TPUPipeline
    TPUPipeline -->|deployed on| Compute
    TPUPipeline -->|used by| CWrapper

    %% CI/CD Relationships
    GitLabCI -.->|triggers build| Dockerfile
    Dockerfile -.->|cross-compile| RustLib
    Dockerfile -.->|cross-compile| CWrapper
    GitLabCI -.->|deploys artifacts| Dockerfile

    %% Click Events
    click FeetechServo "https://github.com/zeroth-robotics/zeroth-bot/blob/main/kos-zbot/src/firmware/feetech_servo/mod.rs"
    click STS3215 "https://github.com/zeroth-robotics/zeroth-bot/blob/main/kos-zbot/src/firmware/feetech_servo/sts3215.rs"
    click BMI088 "https://github.com/zeroth-robotics/zeroth-bot/blob/main/kos-zbot/src/imu_bmi088.rs"
    click BNO055 "https://github.com/zeroth-robotics/zeroth-bot/blob/main/kos-zbot/src/imu_bno055.rs"
    click LEDMatrix "https://github.com/zeroth-robotics/zeroth-bot/blob/main/kos-zbot/src/led_matrix.rs"
    click Compute "https://github.com/zeroth-robotics/zeroth-bot/tree/main/buildroot/"
    click CWrapper "https://github.com/zeroth-robotics/zeroth-bot/blob/main/kos-zbot/firmware/cviwrapper/cviwrapper.c"
    click EfuseC "https://github.com/zeroth-robotics/zeroth-bot/blob/main/kos-zbot/firmware/efuse/efuse.c"
    click FeetechC "https://github.com/zeroth-robotics/zeroth-bot/blob/main/kos-zbot/firmware/feetech/feetech.c"
    click STS3215C "https://github.com/zeroth-robotics/zeroth-bot/blob/main/kos-zbot/firmware/sts3215/sts3215.c"
    click GRPC "https://github.com/zeroth-robotics/zeroth-bot/tree/main/kos-zbot/tonic/"
    click RustLib "https://github.com/zeroth-robotics/zeroth-bot/blob/main/kos-zbot/src/lib.rs"
    click RustCLI "https://github.com/zeroth-robotics/zeroth-bot/blob/main/kos-zbot/src/bin/feetech_scan.rs"
    click PythonRun "https://github.com/zeroth-robotics/zeroth-bot/blob/main/experiments/run.py"
    click PythonIMU "https://github.com/zeroth-robotics/zeroth-bot/blob/main/experiments/imu.py"
    click PythonModel "https://github.com/zeroth-robotics/zeroth-bot/blob/main/experiments/model.py"
    click PythonPlot "https://github.com/zeroth-robotics/zeroth-bot/blob/main/experiments/plot.py"
    click PythonRobot "https://github.com/zeroth-robotics/zeroth-bot/blob/main/experiments/robot.py"
    click TeleopMain "https://github.com/zeroth-robotics/zeroth-bot/blob/main/experiments/teleop/main.py"
    click URDF "https://github.com/zeroth-robotics/zeroth-bot/blob/main/experiments/teleop/urdf/robot_fixed.urdf"
    click Meshes "https://github.com/zeroth-robotics/zeroth-bot/tree/main/experiments/teleop/urdf/meshes/"
    click MLModel "https://github.com/zeroth-robotics/zeroth-bot/blob/main/kos-zbot/models/standing.pt"
    click ConvertModel "https://github.com/zeroth-robotics/zeroth-bot/blob/main/kos-zbot/models/convert_model.sh"
    click TPUPipeline "https://github.com/zeroth-robotics/zeroth-bot/tree/main/models/tpu-mlir/"
    click GitLabCI "https://github.com/zeroth-robotics/zeroth-bot/blob/main/.gitlab-ci.yml"
    click Dockerfile "https://github.com/zeroth-robotics/zeroth-bot/tree/main/kos-zbot/toolchain-docker-img/Dockerfile"

    %% Styles
    classDef hardware fill:#AED6F1,stroke:#21618C,color:#1B2631;
    classDef firmware fill:#85C1E9,stroke:#1A5276,color:#1B2631;
    classDef middleware fill:#ABEBC6,stroke:#196F3D,color:#1B2631;
    classDef sdk fill:#F9E79F,stroke:#B9770E,color:#1B2631;
    classDef experiments fill:#D2B4DE,stroke:#6C3483,color:#1B2631;
    classDef ci fill:#E5E7E9,stroke:#566573,color:#1B2631;
```
