# chanjoon/mpcc architecture

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

- Interactive diagram: https://gitdiagram.com/chanjoon/mpcc
- Repository: https://github.com/chanjoon/mpcc

## Overview

- ROS Interface & Launch System:
- The “launch” directory contains several launch files (e.g., quadrotor_gazebo.launch, test_circle.launch, test_lemniscate.launch) that initialize the simulation environment and control processes.
- You may include key ROS-related components like the ROS nodes and topics for state estimation, control commands, and trajectory information.

- MPC Controller Core:
- The “include/mpcc” and “src” directories contain the MPCC core implementation (e.g., mpcc_wrapper.cpp, mpcc_test.cpp, astar.cpp).
- Workflow from state input to cost function evaluation, where the MPC uses the quadrotor dynamic model (found in “model/quadrotor_model_thrustrates.cpp”) and computes optimal control actions.

- Quadrotor Dynamic Model & Cost Function:
- The “model” directory contains various files including the quadrotor model, ACADO interface files, and code generation scripts.

- QP Solver Integration:
- The “qp_solver/qpoases” directory houses the qpOASES implementation that is invoked to solve the quadratic program defined by the controller.
- QpOASES as a component that takes the formulated quadratic cost and constraint matrices (from ACADO) and returns the computed control inputs.

- Utility Libraries & Configuration:
- The “include/utils” directory is used for auxiliary functions (e.g., grid map, raycast, wind disturbance) that support the control and simulation.
- That parameter files (found in “config” and “parameters” directories) and scripts (in “scripts”) provide supporting configurations and testing aids.

- Simulation Environment:
- Integrate external simulation and hardware-in-the-loop components including PX4 and Gazebo (as referenced by the launch files).

##### Important architectural patterns and design principles
- Modularity: Separate components for the ROS interface, the core predictive control algorithm, the dynamic model, and the QP solver.
- Layered architecture: Distinguish between higher-level simulation and visualization (PX4, Gazebo) and lower-level, real-time control algorithms (ACADO interfacing and QP solving).
- Integration: Pay special attention to how the ACADO-generated code (embedded in “model/quadrotor_mpcc” and related files) is statically included in the repository, which means you do not need external ACADO dependencies for compiled code.

##### Following elements
- Clear labels for each component (e.g., “ROS Launch & Interface”, “Quadrotor Dynamic Model”, “MPC Controller (ACADO based)”, “QP Solver (qpOASES)”, “Utility & Config Files”).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Simulation Environment
    subgraph "Simulation Environment"
        SIM("PX4 & Gazebo Simulation"):::sim
    end

    %% ROS Integration Layer
    subgraph "ROS Integration"
        ROSIF("ROS Launch & Interface"):::ros
    end

    %% MPC Computation Layer
    subgraph "MPC Computation"
        MPC("MPC Controller Core"):::mpc
        DM("Quadrotor Dynamic Model & Cost Function"):::model
        QP("QP Solver (qpOASES)"):::qp
    end

    %% Utility & Configuration Layer
    subgraph "Utility & Configuration"
        UTIL("Utility Libraries & Configurations"):::util
    end

    %% Dataflow Connections
    SIM -->|"sensor_data"| ROSIF
    ROSIF -->|"state_estimation"| MPC
    MPC -->|"use_model_cost"| DM
    MPC -->|"formulate_QP"| QP
    QP -->|"control_inputs"| MPC
    MPC -->|"send_commands"| ROSIF
    ROSIF -->|"actuation_commands"| SIM
    UTIL -->|"parameters"| ROSIF
    UTIL -->|"parameters"| MPC

    %% Click Events for ROS Launch & Interface
    click ROSIF "https://github.com/chanjoon/mpcc/blob/master/launch/quadrotor_gazebo.launch"
    click ROSIF "https://github.com/chanjoon/mpcc/blob/master/launch/test_circle.launch"
    click ROSIF "https://github.com/chanjoon/mpcc/blob/master/launch/test_lemniscate.launch"
    click ROSIF "https://github.com/chanjoon/mpcc/blob/master/launch/mpcc_iris_test.launch"
    click ROSIF "https://github.com/chanjoon/mpcc/blob/master/launch/mpcc_typhoon_h480_test.launch"

    %% Click Events for MPC Controller Core
    click MPC "https://github.com/chanjoon/mpcc/tree/master/include/mpcc"
    click MPC "https://github.com/chanjoon/mpcc/tree/master/src"

    %% Click Events for Quadrotor Dynamic Model & Cost Function
    click DM "https://github.com/chanjoon/mpcc/blob/master/model/quadrotor_model_thrustrates.cpp"
    click DM "https://github.com/chanjoon/mpcc/tree/master/model/quadrotor_mpcc"

    %% Click Event for QP Solver Integration
    click QP "https://github.com/chanjoon/mpcc/tree/master/qp_solver/qpoases"

    %% Click Events for Utility Libraries & Configuration
    click UTIL "https://github.com/chanjoon/mpcc/tree/master/include/utils"
    click UTIL "https://github.com/chanjoon/mpcc/tree/master/config"
    click UTIL "https://github.com/chanjoon/mpcc/blob/master/parameters/default.yaml"
    click UTIL "https://github.com/chanjoon/mpcc/blob/master/scripts/test_circle.py"
    click UTIL "https://github.com/chanjoon/mpcc/blob/master/scripts/test_lemniscate.py"
    click UTIL "https://github.com/chanjoon/mpcc/blob/master/scripts/path_publisher.py"
    click UTIL "https://github.com/chanjoon/mpcc/blob/master/scripts/gt_vision_pose.py"

    %% Styles and Colors
    classDef ros fill:#ADD8E6,stroke:#000,stroke-width:1px;
    classDef mpc fill:#90EE90,stroke:#000,stroke-width:1px;
    classDef model fill:#FFB6C1,stroke:#000,stroke-width:1px;
    classDef qp fill:#FFA07A,stroke:#000,stroke-width:1px;
    classDef util fill:#FFFFE0,stroke:#000,stroke-width:1px;
    classDef sim fill:#DDA0DD,stroke:#000,stroke-width:1px;
```
