# 987419640/firmware architecture

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

- Interactive diagram: https://gitdiagram.com/987419640/firmware
- Repository: https://github.com/987419640/firmware

## Overview

##### Project Type & Purpose
- PX4 is an embedded flight‐control firmware for drones.
- It comprises:
- A hardware abstraction layer (board & platform drivers)
- A publish-subscribe middleware (“uORB”)
- A suite of modules (flight control, estimation, navigation, communications)
- Communication bridges (MAVLink, UAVCAN, micro-RTPS)
- Build/deployment for both bare-metal (NuttX) and simulation (POSIX SITL)

##### High-Level Component Breakdown
a. Hardware Abstraction
- Boards/Platform directories → board-specific init, bus drivers (I²C, SPI, UART)
- src/drivers → sensor, actuator, telemetry drivers
- RTOS ports: platforms/nuttx & platforms/posix & platforms/qurt

b. Core Middleware
- uORB → publish/subscribe bus (src/modules/uORB)
- Work queue / scheduled tasks (px4_work_queue)
- Parameter server (flashparams, parameters_injected.xml)
- Logging (modules/logger + log_writer)
- Build system & scripts (CMakeLists.txt, Tools/docker_run.sh, .ci, Travis, Jenkins)

c. Application Modules
- Estimation (ekf2, attitude_estimator_q)
- Flight control
– mc_att_control & mc_pos_control (multirotor)
– fw_att_control & fw_pos_control (fixed wing)
– vtol_att_control
- Vehicle management (modules/commander, navigator, dataman)
- Safety & watchdog (circuit_breaker, commander/failure_detector)

d. Communications & External Interfaces
- MAVLink bridge (modules/mavlink) → telemetry links to ground station (e.g. QGroundControl)
- UAVCAN nodes & ESC servers (drivers/uavcan, drivers/uavcanesc)
- micro-RTPS bridge (modules/micrortps_bridge) → ROS2 / PX4-Fmw link
- POSIX SITL launch scripts & simulators (launch/, Tools/sitl_*.sh)

##### Relationships & Data Flow
- Modules subscribe to uORB topics, process data, and publish control outputs
- Actuator drivers consume control outputs (PWM, CAN)
- Communication modules (MAVLink/UAVCAN/RTPS) tap into uORB to forward telemetry/commands
- Scheduler/WorkQueue governs module run timing (rate, priorities)
- Parameter subsystem configures modules at startup and on-the-fly

##### Architectural Patterns & Principles
- Layered architecture: Drivers → Middleware → Modules → External
- Pub/Sub decoupling (uORB) ensures modular, testable modules
- Platform‐abstraction via CMake and “platforms/…” enables NuttX vs. POSIX builds
- Plugin‐style modules auto‐registered via CMake (px4_add_module)
- CI/CD pipelines target SITL tests, hardware builds, code coverage

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "1. Hardware Abstraction"
        HA1["Boards/BSP"]:::hardware
        HA2["Sensor/Actuator Drivers"]:::hardware
        HA3["RTOS Port: NuttX"]:::hardware
        HA4["RTOS Port: POSIX"]:::hardware
        HA5["RTOS Port: QURT"]:::hardware
    end

    subgraph "2. Middleware (Core)"
        MW1["uORB Pub/Sub"]:::middleware
        MW2["Work Queue / Scheduler"]:::middleware
        MW3["Parameter Server (flash)"]:::middleware
        MW4["Injected Params XML"]:::middleware
        MW5["Logging Framework"]:::middleware
    end

    subgraph "3. Application Modules"
        subgraph "Estimation"
            M1["EKF2 Estimator"]:::modules
            M2["Attitude Estimator Q"]:::modules
        end
        subgraph "Flight Control"
            M3["MC Att Control"]:::modules
            M4["MC Pos Control"]:::modules
            M5["FW Att Control"]:::modules
            M6["FW Pos Control (L1)"]:::modules
            M7["VTOL Att Control"]:::modules
        end
        subgraph "Vehicle Management & Safety"
            M8["Commander"]:::modules
            M9["Navigator"]:::modules
            M10["Dataman"]:::modules
            M11["Failure Detector"]:::modules
            M12["Circuit Breaker"]:::modules
        end
    end

    subgraph "4. Communications & Interfaces"
        C1["MAVLink Bridge"]:::comm
        C2["UAVCAN Driver & ESC"]:::comm
        C3["micro-RTPS Bridge"]:::comm
    end

    subgraph "5. Simulation (SITL)"
        S1["POSIX SITL Launch Scripts"]:::hardware
        S2["SITL Board Support (POSIX)"]:::hardware
        S3["SITL Main Code"]:::hardware
    end

    subgraph "6. Build / CI"
        T1["CMake Build System"]:::tools
        T2["Docker Script"]:::tools
        T3["CI Pipelines"]:::tools
    end

    HA2 -->|"publish sensor data"| MW1
    MW1 -->|"uORB data"| M1
    MW1 -->|"uORB data"| M2
    MW1 -->|"uORB data"| M3
    MW1 -->|"uORB data"| M4
    MW1 -->|"uORB data"| M5
    MW1 -->|"uORB data"| M6
    MW1 -->|"uORB data"| M7
    MW1 -->|"uORB data"| M8
    MW1 -->|"uORB data"| M9
    MW1 -->|"uORB data"| M10
    MW1 -->|"uORB data"| M11
    MW1 -->|"uORB data"| M12

    M1 -->|"control outputs"| HA2
    M2 -->|"control outputs"| HA2
    M3 -->|"control outputs"| HA2
    M4 -->|"control outputs"| HA2
    M5 -->|"control outputs"| HA2
    M6 -->|"control outputs"| HA2
    M7 -->|"control outputs"| HA2

    MW2 -->|"schedule"| M1
    MW2 -->|"schedule"| M2
    MW2 -->|"schedule"| M3
    MW2 -->|"schedule"| M4
    MW2 -->|"schedule"| M5
    MW2 -->|"schedule"| M6
    MW2 -->|"schedule"| M7
    MW2 -->|"schedule"| M8
    MW2 -->|"schedule"| M9
    MW2 -->|"schedule"| M10
    MW2 -->|"schedule"| M11
    MW2 -->|"schedule"| M12

    MW3 -->|"configure"| M1
    MW3 -->|"configure"| M2
    MW3 -->|"configure"| M3
    MW3 -->|"configure"| M4
    MW3 -->|"configure"| M5
    MW3 -->|"configure"| M6
    MW3 -->|"configure"| M7
    MW3 -->|"configure"| M8
    MW3 -->|"configure"| M9
    MW3 -->|"configure"| M10
    MW3 -->|"configure"| M11
    MW3 -->|"configure"| M12

    M1 -->|"log messages"| MW5
    M2 -->|"log messages"| MW5
    M3 -->|"log messages"| MW5
    M4 -->|"log messages"| MW5
    M5 -->|"log messages"| MW5
    M6 -->|"log messages"| MW5
    M7 -->|"log messages"| MW5
    M8 -->|"log messages"| MW5
    M9 -->|"log messages"| MW5
    M10 -->|"log messages"| MW5
    M11 -->|"log messages"| MW5
    M12 -->|"log messages"| MW5

    MW1 -->|"telemetry topics"| C1
    MW1 -->|"uavcan topics"| C2
    MW1 -->|"rtps topics"| C3

    S3 -->|"runs on"| HA4

    T1 -->|"build BSP & platforms"| HA1
    T1 -->|"build BSP & platforms"| HA3
    T1 -->|"build BSP & platforms"| HA4
    T1 -->|"build BSP & platforms"| HA5
    T1 -->|"build SITL"| S3
    T2 -->|"env setup"| T1
    T3 -->|"ci tests"| T2
    T3 -->|"ci tests"| S1

    click HA1 "https://github.com/987419640/firmware/tree/master/boards/"
    click HA2 "https://github.com/987419640/firmware/tree/master/src/drivers/"
    click HA3 "https://github.com/987419640/firmware/tree/master/platforms/nuttx/"
    click HA4 "https://github.com/987419640/firmware/tree/master/platforms/posix/"
    click HA5 "https://github.com/987419640/firmware/tree/master/platforms/qurt/"
    click MW1 "https://github.com/987419640/firmware/tree/master/src/modules/uORB/"
    click MW2 "https://github.com/987419640/firmware/tree/master/src/platforms/common/px4_work_queue/"
    click MW3 "https://github.com/987419640/firmware/tree/master/src/lib/parameters/flashparams/"
    click MW4 "https://github.com/987419640/firmware/blob/master/src/lib/parameters/parameters_injected.xml"
    click MW5 "https://github.com/987419640/firmware/tree/master/src/modules/logger/"
    click M1 "https://github.com/987419640/firmware/tree/master/src/modules/ekf2/"
    click M2 "https://github.com/987419640/firmware/tree/master/src/modules/attitude_estimator_q/"
    click M3 "https://github.com/987419640/firmware/tree/master/src/modules/mc_att_control/"
    click M4 "https://github.com/987419640/firmware/tree/master/src/modules/mc_pos_control/"
    click M5 "https://github.com/987419640/firmware/tree/master/src/modules/fw_att_control/"
    click M6 "https://github.com/987419640/firmware/tree/master/src/modules/fw_pos_control_l1/"
    click M7 "https://github.com/987419640/firmware/tree/master/src/modules/vtol_att_control/"
    click M8 "https://github.com/987419640/firmware/tree/master/src/modules/commander/"
    click M9 "https://github.com/987419640/firmware/tree/master/src/modules/navigator/"
    click M10 "https://github.com/987419640/firmware/tree/master/src/modules/dataman/"
    click M11 "https://github.com/987419640/firmware/tree/master/src/modules/commander/failure_detector/"
    click M12 "https://github.com/987419640/firmware/tree/master/src/lib/circuit_breaker/"
    click C1 "https://github.com/987419640/firmware/tree/master/src/modules/mavlink/"
    click C2 "https://github.com/987419640/firmware/tree/master/src/drivers/uavcan/"
    click C2 "https://github.com/987419640/firmware/tree/master/src/drivers/uavcanesc/"
    click C3 "https://github.com/987419640/firmware/tree/master/src/modules/micrortps_bridge/"
    click S1 "https://github.com/987419640/firmware/tree/master/launch/"
    click S2 "https://github.com/987419640/firmware/tree/master/boards/px4/sitl/"
    click S3 "https://github.com/987419640/firmware/blob/master/platforms/posix/src/main.cpp"
    click T1 "https://github.com/987419640/firmware/blob/master/CMakeLists.txt"
    click T2 "https://github.com/987419640/firmware/blob/master/Tools/docker_run.sh"
    click T3 "https://github.com/987419640/firmware/tree/master/.ci/"

    classDef hardware fill:#d3d3d3,stroke:#333,stroke-width:1px
    classDef middleware fill:#add8e6,stroke:#333,stroke-width:1px
    classDef modules fill:#90ee90,stroke:#333,stroke-width:1px
    classDef comm fill:#ffcc99,stroke:#333,stroke-width:1px
    classDef tools fill:#ffff99,stroke:#333,stroke-width:1px
```
