# auterion/px4-ros2-interface-lib architecture

> Architecture diagram of the GitHub repository auterion/px4-ros2-interface-lib, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-01-20). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/auterion/px4-ros2-interface-lib
- Repository: https://github.com/auterion/px4-ros2-interface-lib

## Overview

##### Layer Organization (top to bottom)

a. Application Layer:
- Example Modes (manual, goto, fw_attitude, etc.)
- Custom User Applications

b. Interface Layer:
- Mode Executor
- Node With Mode
- Health and Arming Checks
- Message Compatibility Check

c. Control Layer:
- Setpoint Types (Direct Actuators, Attitude, Rates, Trajectory)
- Peripheral Actuators

d. Navigation Layer:
- Global Position Interface
- Local Position Interface
- Navigation Interface Base

e. State Management Layer:
- Vehicle Status
- Battery Status
- Home Position
- VTOL Status
- Land Detection

a. Primary Data Flow:
- uORB Messages between PX4 and Library
- ROS 2 Topics/Services
- Mode Commands and Setpoints

b. State Updates:
- Vehicle State Updates
- /Attitude Updates
- Control Feedback

##### Key Integration Points

a. Message Compatibility Layer:
- Compatibility checking mechanism
- Message translation between uORB and ROS 2

b. Mode Registration System:
- Dynamic mode registration
- Mode switching mechanism

##### Important Details

- Frame conversion utilities
- Geodesic calculations
- Health monitoring
- Arming check system
- Manual control input handling

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Define styles
    classDef core fill:#3498db,stroke:#2980b9,color:white
    classDef ros fill:#2ecc71,stroke:#27ae60,color:white
    classDef px4 fill:#e67e22,stroke:#d35400,color:white
    classDef user fill:#f1c40f,stroke:#f39c12,color:black
    classDef util fill:#95a5a6,stroke:#7f8c8d,color:white
    classDef experimental fill:#e74c3c,stroke:#c0392b,color:white

    %% External Systems
    PX4["PX4 Flight Controller"]:::px4
    ROS["ROS 2 Environment"]:::ros
    CC["Companion Computer"]:::ros

    %% Application Layer
    subgraph AppLayer["Application Layer"]
        Examples["Example Modes"]
        CustomApps["Custom User Applications"]
    end

    %% Interface Layer
    subgraph InterfaceLayer["Interface Layer"]
        ModeExec["Mode Executor"]:::core
        NodeMode["Node With Mode"]:::core
        HealthChecks["Health and Arming Checks"]:::core
        MsgCompat["Message Compatibility Check"]:::core
    end

    %% Control Layer
    subgraph ControlLayer["Control Layer"]
        SetpointTypes["Setpoint Types"]:::core
        PeriphActuators["Peripheral Actuators"]:::core
    end

    %% Navigation Layer
    subgraph NavLayer["Navigation Layer"]
        GlobalPos["Global Position Interface"]:::experimental
        LocalPos["Local Position Interface"]:::experimental
        NavBase["Navigation Interface Base"]:::experimental
    end

    %% State Management Layer
    subgraph StateLayer["State Management Layer"]
        VehicleStatus["Vehicle Status"]:::core
        BatteryStatus["Battery Status"]:::core
        HomePos["Home Position"]:::core
        VTOLStatus["VTOL Status"]:::core
        LandDetect["Land Detection"]:::core
    end

    %% Utils Module
    subgraph UtilsModule["Utils Module"]
        FrameConv["Frame Conversion"]:::util
        GeoCalc["Geodesic Calculations"]:::util
        Geometry["Geometry Utils"]:::util
    end

    %% Relationships
    PX4 <--> MsgCompat
    MsgCompat <--> ROS
    ROS <--> CC

    Examples --> ModeExec
    CustomApps --> ModeExec
    ModeExec --> NodeMode
    NodeMode --> HealthChecks
    HealthChecks --> MsgCompat

    ModeExec --> SetpointTypes
    SetpointTypes --> PeriphActuators
    PeriphActuators --> PX4

    NavBase --> GlobalPos
    NavBase --> LocalPos
    GlobalPos --> VehicleStatus
    LocalPos --> VehicleStatus

    VehicleStatus --> StateLayer
    BatteryStatus --> StateLayer
    HomePos --> StateLayer
    VTOLStatus --> StateLayer
    LandDetect --> StateLayer

    StateLayer --> UtilsModule

    %% Click events for component mapping
    click ModeExec "https://github.com/Auterion/px4-ros2-interface-lib/blob/main/px4_ros2_cpp/include/px4_ros2/components/mode_executor.hpp"
    click HealthChecks "https://github.com/Auterion/px4-ros2-interface-lib/blob/main/px4_ros2_cpp/include/px4_ros2/components/health_and_arming_checks.hpp"
    click MsgCompat "https://github.com/Auterion/px4-ros2-interface-lib/blob/main/px4_ros2_cpp/include/px4_ros2/components/message_compatibility_check.hpp"
    click SetpointTypes "https://github.com/Auterion/px4-ros2-interface-lib/tree/main/px4_ros2_cpp/include/px4_ros2/control/setpoint_types/"
    click PeriphActuators "https://github.com/Auterion/px4-ros2-interface-lib/blob/main/px4_ros2_cpp/include/px4_ros2/control/peripheral_actuators.hpp"
    click GlobalPos "https://github.com/Auterion/px4-ros2-interface-lib/blob/main/px4_ros2_cpp/include/px4_ros2/navigation/experimental/global_position_measurement_interface.hpp"
    click LocalPos "https://github.com/Auterion/px4-ros2-interface-lib/blob/main/px4_ros2_cpp/include/px4_ros2/navigation/experimental/local_position_measurement_interface.hpp"
    click NavBase "https://github.com/Auterion/px4-ros2-interface-lib/blob/main/px4_ros2_cpp/include/px4_ros2/navigation/experimental/navigation_interface_base.hpp"
    click VehicleStatus "https://github.com/Auterion/px4-ros2-interface-lib/blob/main/px4_ros2_cpp/include/px4_ros2/vehicle_state/vehicle_status.hpp"
    click BatteryStatus "https://github.com/Auterion/px4-ros2-interface-lib/blob/main/px4_ros2_cpp/include/px4_ros2/vehicle_state/battery.hpp"
    click HomePos "https://github.com/Auterion/px4-ros2-interface-lib/blob/main/px4_ros2_cpp/include/px4_ros2/vehicle_state/home_position.hpp"
    click VTOLStatus "https://github.com/Auterion/px4-ros2-interface-lib/blob/main/px4_ros2_cpp/include/px4_ros2/vehicle_state/vtol_status.hpp"
    click LandDetect "https://github.com/Auterion/px4-ros2-interface-lib/blob/main/px4_ros2_cpp/include/px4_ros2/vehicle_state/land_detected.hpp"
    click FrameConv "https://github.com/Auterion/px4-ros2-interface-lib/blob/main/px4_ros2_cpp/include/px4_ros2/utils/frame_conversion.hpp"
    click GeoCalc "https://github.com/Auterion/px4-ros2-interface-lib/blob/main/px4_ros2_cpp/include/px4_ros2/utils/geodesic.hpp"
    click Geometry "https://github.com/Auterion/px4-ros2-interface-lib/blob/main/px4_ros2_cpp/include/px4_ros2/utils/geometry.hpp"
    click Examples "https://github.com/Auterion/px4-ros2-interface-lib/tree/main/examples/cpp/modes/"
```
