# muhammadabdullah-2001/px4_offboard_lowlevel_fbl_controller architecture

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

- Interactive diagram: https://gitdiagram.com/muhammadabdullah-2001/px4_offboard_lowlevel_fbl_controller
- Repository: https://github.com/muhammadabdullah-2001/px4_offboard_lowlevel_fbl_controller

## Overview

##### Project Type and Purpose
- Its purpose (from README) is to demonstrate how to send low‐level commands to PX4 in offboard mode via ROS 2.

##### Key Components (Blocks
a. Simulator & Autopilot Layer
- Gazebo+PX4 SITL (launch: `iris_sitl.launch.py`, `x500_sitl.launch.py`)
- PX4 Firmware (SITL interface, uORB ↔ ROS 2 bridge provided by `px4_ros_com`)
b. ROS 2 Middleware
- ros2 daemon and DDS transport
c. Trajectory Generation
- Node: `circle_trajectory_node.cpp` under `src/TrajectoryPublishers`
- Publishes desired trajectory messages
d. Controller Node
- `controller_node.cpp` + `controller.cpp` / `New_controller.cpp`
- Subscribes to:
– Vehicle state (e.g. `/fmu/out/vehicle_attitude`)
– Trajectory commands
- Computes low‐level setpoints (attitude/thrust or actuator commands)
- Publishes:
– `/fmu/in/vehicle_attitude_setpoint`
– `/fmu/in/vehicle_thrust_setpoint` + torque
– or `/fmu/in/actuator_motors`
e. Parameter Server & Configuration
- ROS 2 parameters loaded via launch files
- YAML configs under `config/` (initial gains, SITL params, UAV params, experiment params)
f. Visualization
- Node: `visualizer.py` / `visuals.cpp`
g. Utility Scripts (offline / identification)
- `identification.py`, `loop_controller.m`, `px4_sitl_quadrotor_x.m`
- Not part of core runtime but support tuning & validation

- TrajectoryPublisher → ControllerNode: desired trajectory
- ControllerNode ← VehicleState from PX4 SITL
- ControllerNode → PX4 SITL: low‐level commands
- PX4 SITL → Gazebo sim: actuates quadrotor
- PX4 SITL → ControllerNode: state updates
- ControllerNode & TrajectoryPublisher → Visualizer: for real‐time plotting
- Configuration (YAML) → ControllerNode & TrajectoryPublisher (at startup)

##### Architectural Patterns & Principles
- Publisher–Subscriber (ROS 2 DDS) decouples modules
- Parameterization via YAML promotes easy tuning & reuse
- Modular nodes: separation of trajectory generation, control logic, visualization
- Launch files orchestrate multi‐node startup and parameter loading

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Simulator & Autopilot Layer
    subgraph "Simulator & Autopilot Layer"
        direction TB
        GazeboPX4["Gazebo + PX4 SITL"]:::sim
        World["empty.world"]:::sim
        DDSTopics["DDS Topics Bridge"]:::sim
        IrisLaunch["iris_sitl.launch.py"]:::launch
        X500Launch["x500_sitl.launch.py"]:::launch
    end

    %% ROS 2 Middleware
    subgraph "ROS 2 Middleware"
        direction TB
        ROS2Daemon["ros2 daemon & DDS"]:::middleware
        VisualizeLaunch["visualize.launch.py"]:::launch
    end

    %% Configuration
    subgraph "Configuration & Parameters"
        direction TB
        InitialGainsIris["initial_gains_iris.yaml"]:::config
        InitialGainsX500["initial_gains_x500.yaml"]:::config
        ExpParams["exp_params.yaml"]:::config
        SITLParams["sitl_params.yaml"]:::config
        UAVParamIris["iris_param.yaml"]:::config
        UAVParamX500["x500_param.yaml"]:::config
    end

    %% Application Nodes
    subgraph "Application Nodes"
        direction TB
        TrajNode["circle_trajectory_node.cpp"]:::node
        ControllerNode["controller_node.cpp"]:::node
        ControllerLogic1["controller.cpp"]:::node
        ControllerLogic2["New_controller.cpp"]:::node
        VisualizerNode["visualizer.py / visuals.cpp"]:::viznode
    end

    %% Utility Scripts
    subgraph "Utility Scripts (offline)"
        direction TB
        Identification["identification.py"]:::util
        LoopController["loop_controller.m"]:::util
        PX4SitlQuad["px4_sitl_quadrotor_x.m"]:::util
    end

    %% Data Flows
    TrajNode -->|"desired trajectory"| ControllerNode
    GazeboPX4 -->|"vehicle state"| ControllerNode
    ControllerNode -->|"VehicleAttitudeSetpoint"| GazeboPX4
    ControllerNode -->|"VehicleThrustSetpoint"| GazeboPX4
    ControllerNode -->|"ActuatorCommands"| GazeboPX4
    GazeboPX4 -->|"state updates"| TrajNode
    ControllerNode -->|"data for viz"| VisualizerNode
    TrajNode -->|"data for viz"| VisualizerNode
    InitialGainsIris --> ControllerNode
    InitialGainsX500 --> ControllerNode
    ExpParams --> ControllerNode
    SITLParams --> GazeboPX4
    UAVParamIris --> ControllerNode
    UAVParamX500 --> ControllerNode
    IrisLaunch --> GazeboPX4
    X500Launch --> GazeboPX4
    VisualizeLaunch --> VisualizerNode
    ROS2Daemon --> TrajNode
    ROS2Daemon --> ControllerNode
    ROS2Daemon --> VisualizerNode

    %% Click Events
    click IrisLaunch "https://github.com/muhammadabdullah-2001/px4_offboard_lowlevel_fbl_controller/blob/main/launch/iris_sitl.launch.py"
    click X500Launch "https://github.com/muhammadabdullah-2001/px4_offboard_lowlevel_fbl_controller/blob/main/launch/x500_sitl.launch.py"
    click World "https://github.com/muhammadabdullah-2001/px4_offboard_lowlevel_fbl_controller/blob/main/px4-resources/empty.world"
    click DDSTopics "https://github.com/muhammadabdullah-2001/px4_offboard_lowlevel_fbl_controller/blob/main/px4-resources/dds_topics.yaml"
    click VisualizeLaunch "https://github.com/muhammadabdullah-2001/px4_offboard_lowlevel_fbl_controller/blob/main/launch/visualize.launch.py"
    click TrajNode "https://github.com/muhammadabdullah-2001/px4_offboard_lowlevel_fbl_controller/blob/main/src/TrajectoryPublishers/circle_trajectory_node.cpp"
    click ControllerNode "https://github.com/muhammadabdullah-2001/px4_offboard_lowlevel_fbl_controller/blob/main/src/controller_node.cpp"
    click ControllerLogic1 "https://github.com/muhammadabdullah-2001/px4_offboard_lowlevel_fbl_controller/blob/main/src/controller.cpp"
    click ControllerLogic2 "https://github.com/muhammadabdullah-2001/px4_offboard_lowlevel_fbl_controller/blob/main/src/New_controller.cpp"
    click InitialGainsIris "https://github.com/muhammadabdullah-2001/px4_offboard_lowlevel_fbl_controller/blob/main/config/controller/initial_gains_iris.yaml"
    click InitialGainsX500 "https://github.com/muhammadabdullah-2001/px4_offboard_lowlevel_fbl_controller/blob/main/config/controller/initial_gains_x500.yaml"
    click ExpParams "https://github.com/muhammadabdullah-2001/px4_offboard_lowlevel_fbl_controller/blob/main/config/exp/exp_params.yaml"
    click SITLParams "https://github.com/muhammadabdullah-2001/px4_offboard_lowlevel_fbl_controller/blob/main/config/sitl/sitl_params.yaml"
    click UAVParamIris "https://github.com/muhammadabdullah-2001/px4_offboard_lowlevel_fbl_controller/blob/main/config/uav_parameters/iris_param.yaml"
    click UAVParamX500 "https://github.com/muhammadabdullah-2001/px4_offboard_lowlevel_fbl_controller/blob/main/config/uav_parameters/x500_param.yaml"
    click Identification "https://github.com/muhammadabdullah-2001/px4_offboard_lowlevel_fbl_controller/blob/main/scripts/identification.py"
    click LoopController "https://github.com/muhammadabdullah-2001/px4_offboard_lowlevel_fbl_controller/blob/main/src/loop_controller.m"
    click PX4SitlQuad "https://github.com/muhammadabdullah-2001/px4_offboard_lowlevel_fbl_controller/blob/main/scripts/px4_sitl_quadrotor_x.m"
    click VisualizerNode "https://github.com/muhammadabdullah-2001/px4_offboard_lowlevel_fbl_controller/blob/main/scripts/visualizer.py"

    %% Styles
    classDef sim fill:#cccccc,stroke:#333,stroke-width:1px
    classDef middleware fill:#ddddff,stroke:#333,stroke-width:1px
    classDef launch fill:#e5ccff,stroke:#333,stroke-width:1px
    classDef config fill:#ccffcc,stroke:#333,stroke-width:1px
    classDef node fill:#cce5ff,stroke:#333,stroke-width:1px
    classDef viznode fill:#ffdd99,stroke:#333,stroke-width:1px
    classDef util fill:#f2f2f2,stroke:#666,stroke-dasharray: 2 2,stroke-width:1px
```
