# jaeyoung-lim/px4-mpc architecture

> Architecture diagram of the GitHub repository jaeyoung-lim/px4-mpc, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-17). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/jaeyoung-lim/px4-mpc
- Repository: https://github.com/jaeyoung-lim/px4-mpc

## Overview

px4-mpc is a ROS 2/PX4 model-predictive controller for quadrotors and spacecraft. The main workflow is to receive vehicle state and setpoints, select a vehicle-specific MPC mode, solve a finite-horizon control problem, and publish commands to PX4. Spacecraft supports wrench, rate, and direct-allocation modes; the quadrotor uses rate control. RViz setpoints and visualization are documented options. Some links are based on the README or SOURCE INDEX because the relevant implementation was not fully excerpted.

Main entry points: [`px4_mpc/px4_mpc/mpc_spacecraft.py`](https://github.com/jaeyoung-lim/px4-mpc/blob/master/px4_mpc/px4_mpc/mpc_spacecraft.py) (Spacecraft Node), [`px4_mpc/px4_mpc/mpc_quadrotor.py`](https://github.com/jaeyoung-lim/px4-mpc/blob/master/px4_mpc/px4_mpc/mpc_quadrotor.py) (Quadrotor Node), [`px4_mpc/px4_mpc/controllers/multirotor_rate_mpc.py`](https://github.com/jaeyoung-lim/px4-mpc/blob/master/px4_mpc/px4_mpc/controllers/multirotor_rate_mpc.py) (Multirotor Rate MPC), [`px4_mpc/px4_mpc/controllers/spacecraft_rate_mpc.py`](https://github.com/jaeyoung-lim/px4-mpc/blob/master/px4_mpc/px4_mpc/controllers/spacecraft_rate_mpc.py) (Spacecraft Rate MPC)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["ROS 2 Runtime"]
  node_quad_launch["Quadrotor Launch"]
  node_spacecraft_launch["Spacecraft Launch"]
  node_quad_app["Quadrotor Node<br/>[mpc_quadrotor.py]"]
  node_spacecraft_app["Spacecraft Node<br/>[mpc_spacecraft.py]"]
end

subgraph group_controllers["MPC Controllers"]
  node_quad_mpc["Multirotor Rate MPC"]
  node_sc_rate_mpc["Spacecraft Rate MPC"]
  node_sc_wrench_mpc["Spacecraft Wrench MPC"]
  node_sc_direct_mpc["Spacecraft Direct MPC"]
end

subgraph group_models["Vehicle Models"]
  node_quad_model["Multirotor Dynamics"]
  node_sc_rate_model["Spacecraft Rate Dynamics"]
  node_sc_wrench_model["Spacecraft Wrench Dynamics"]
  node_sc_direct_model["Spacecraft Allocation Dynamics"]
end

subgraph group_interfaces["Operator Interfaces"]
  node_rviz["RViz Setpoints<br/>[rviz_pos_marker.py]"]
  node_visualization["Trajectory Visualization<br/>[visualization.py]"]
end

node_operator(("Operator"))
node_px4["PX4 Autopilot"]
node_acados["acados Solver"]

node_operator -->|"launches"| node_quad_launch
node_operator -->|"launches"| node_spacecraft_launch
node_quad_launch -->|"starts"| node_quad_app
node_spacecraft_launch -->|"starts"| node_spacecraft_app
node_quad_app -->|"reads state; publishes commands"| node_px4
node_spacecraft_app -->|"reads state; publishes commands"| node_px4
node_quad_app -->|"invokes"| node_quad_mpc
node_quad_app -->|"configures"| node_quad_model
node_spacecraft_app -->|"selects rate mode"| node_sc_rate_mpc
node_spacecraft_app -->|"selects wrench mode"| node_sc_wrench_mpc
node_spacecraft_app -->|"selects allocation mode"| node_sc_direct_mpc
node_quad_mpc -->|"builds dynamics"| node_quad_model
node_sc_rate_mpc -->|"builds dynamics"| node_sc_rate_model
node_sc_wrench_mpc -->|"builds dynamics"| node_sc_wrench_model
node_sc_direct_mpc -->|"builds dynamics"| node_sc_direct_model
node_quad_mpc -->|"solves OCP"| node_acados
node_sc_rate_mpc -->|"solves OCP"| node_acados
node_sc_wrench_mpc -->|"solves OCP"| node_acados
node_sc_direct_mpc -->|"solves OCP"| node_acados
node_operator -.->|"sets references"| node_rviz
node_rviz -.->|"provides setpoints"| node_spacecraft_app
node_spacecraft_app -.->|"publishes predictions"| node_visualization

click node_quad_launch "https://github.com/jaeyoung-lim/px4-mpc/blob/master/px4_mpc/px4_mpc/launch/mpc_quadrotor_launch.py"
click node_spacecraft_launch "https://github.com/jaeyoung-lim/px4-mpc/blob/master/px4_mpc/px4_mpc/launch/mpc_spacecraft_launch.py"
click node_quad_app "https://github.com/jaeyoung-lim/px4-mpc/blob/master/px4_mpc/px4_mpc/mpc_quadrotor.py"
click node_spacecraft_app "https://github.com/jaeyoung-lim/px4-mpc/blob/master/px4_mpc/px4_mpc/mpc_spacecraft.py"
click node_quad_mpc "https://github.com/jaeyoung-lim/px4-mpc/blob/master/px4_mpc/px4_mpc/controllers/multirotor_rate_mpc.py"
click node_sc_rate_mpc "https://github.com/jaeyoung-lim/px4-mpc/blob/master/px4_mpc/px4_mpc/controllers/spacecraft_rate_mpc.py"
click node_sc_wrench_mpc "https://github.com/jaeyoung-lim/px4-mpc/blob/master/px4_mpc/px4_mpc/controllers/spacecraft_wrench_mpc.py"
click node_sc_direct_mpc "https://github.com/jaeyoung-lim/px4-mpc/blob/master/px4_mpc/px4_mpc/controllers/spacecraft_direct_allocation_mpc.py"
click node_quad_model "https://github.com/jaeyoung-lim/px4-mpc/blob/master/px4_mpc/px4_mpc/models/multirotor_rate_model.py"
click node_sc_rate_model "https://github.com/jaeyoung-lim/px4-mpc/blob/master/px4_mpc/px4_mpc/models/spacecraft_rate_model.py"
click node_sc_wrench_model "https://github.com/jaeyoung-lim/px4-mpc/blob/master/px4_mpc/px4_mpc/models/spacecraft_wrench_model.py"
click node_sc_direct_model "https://github.com/jaeyoung-lim/px4-mpc/blob/master/px4_mpc/px4_mpc/models/spacecraft_direct_allocation_model.py"
click node_rviz "https://github.com/jaeyoung-lim/px4-mpc/blob/master/px4_mpc/px4_mpc/rviz_pos_marker.py"
click node_visualization "https://github.com/jaeyoung-lim/px4-mpc/blob/master/px4_mpc/px4_mpc/visualization.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_quad_launch,node_spacecraft_launch,node_quad_app,node_spacecraft_app toneBlue
class node_quad_mpc,node_sc_rate_mpc,node_sc_wrench_mpc,node_sc_direct_mpc toneAmber
class node_quad_model,node_sc_rate_model,node_sc_wrench_model,node_sc_direct_model toneMint
class node_rviz,node_visualization toneRose
class node_operator,node_px4,node_acados toneIndigo
```

## Components

### ROS 2 Runtime

- [Quadrotor Launch](https://github.com/jaeyoung-lim/px4-mpc/blob/master/px4_mpc/px4_mpc/launch/mpc_quadrotor_launch.py): `px4_mpc/px4_mpc/launch/mpc_quadrotor_launch.py`
- [Spacecraft Launch](https://github.com/jaeyoung-lim/px4-mpc/blob/master/px4_mpc/px4_mpc/launch/mpc_spacecraft_launch.py): `px4_mpc/px4_mpc/launch/mpc_spacecraft_launch.py`
- [Quadrotor Node](https://github.com/jaeyoung-lim/px4-mpc/blob/master/px4_mpc/px4_mpc/mpc_quadrotor.py): `px4_mpc/px4_mpc/mpc_quadrotor.py`
- [Spacecraft Node](https://github.com/jaeyoung-lim/px4-mpc/blob/master/px4_mpc/px4_mpc/mpc_spacecraft.py): `px4_mpc/px4_mpc/mpc_spacecraft.py`

### MPC Controllers

- [Multirotor Rate MPC](https://github.com/jaeyoung-lim/px4-mpc/blob/master/px4_mpc/px4_mpc/controllers/multirotor_rate_mpc.py): `px4_mpc/px4_mpc/controllers/multirotor_rate_mpc.py`
- [Spacecraft Rate MPC](https://github.com/jaeyoung-lim/px4-mpc/blob/master/px4_mpc/px4_mpc/controllers/spacecraft_rate_mpc.py): `px4_mpc/px4_mpc/controllers/spacecraft_rate_mpc.py`
- [Spacecraft Wrench MPC](https://github.com/jaeyoung-lim/px4-mpc/blob/master/px4_mpc/px4_mpc/controllers/spacecraft_wrench_mpc.py): `px4_mpc/px4_mpc/controllers/spacecraft_wrench_mpc.py`
- [Spacecraft Direct MPC](https://github.com/jaeyoung-lim/px4-mpc/blob/master/px4_mpc/px4_mpc/controllers/spacecraft_direct_allocation_mpc.py): `px4_mpc/px4_mpc/controllers/spacecraft_direct_allocation_mpc.py`

### Vehicle Models

- [Multirotor Dynamics](https://github.com/jaeyoung-lim/px4-mpc/blob/master/px4_mpc/px4_mpc/models/multirotor_rate_model.py): `px4_mpc/px4_mpc/models/multirotor_rate_model.py`
- [Spacecraft Rate Dynamics](https://github.com/jaeyoung-lim/px4-mpc/blob/master/px4_mpc/px4_mpc/models/spacecraft_rate_model.py): `px4_mpc/px4_mpc/models/spacecraft_rate_model.py`
- [Spacecraft Wrench Dynamics](https://github.com/jaeyoung-lim/px4-mpc/blob/master/px4_mpc/px4_mpc/models/spacecraft_wrench_model.py): `px4_mpc/px4_mpc/models/spacecraft_wrench_model.py`
- [Spacecraft Allocation Dynamics](https://github.com/jaeyoung-lim/px4-mpc/blob/master/px4_mpc/px4_mpc/models/spacecraft_direct_allocation_model.py): `px4_mpc/px4_mpc/models/spacecraft_direct_allocation_model.py`

### Operator Interfaces

- [RViz Setpoints](https://github.com/jaeyoung-lim/px4-mpc/blob/master/px4_mpc/px4_mpc/rviz_pos_marker.py): `px4_mpc/px4_mpc/rviz_pos_marker.py`
- [Trajectory Visualization](https://github.com/jaeyoung-lim/px4-mpc/blob/master/px4_mpc/px4_mpc/visualization.py): `px4_mpc/px4_mpc/visualization.py`

### Other components

- **Operator**
- **PX4 Autopilot**
- **acados Solver**

## Connections

- Operator → Quadrotor Launch: launches (evidence: `README.md`)
- Operator → Spacecraft Launch: launches (evidence: `README.md`)
- Quadrotor Launch → Quadrotor Node: starts (evidence: `README.md`)
- Spacecraft Launch → Spacecraft Node: starts (evidence: `README.md`)
- Quadrotor Node → PX4 Autopilot: reads state; publishes commands (evidence: `px4_mpc/px4_mpc/mpc_quadrotor.py`)
- Spacecraft Node → PX4 Autopilot: reads state; publishes commands (evidence: `px4_mpc/px4_mpc/mpc_spacecraft.py`)
- Quadrotor Node → Multirotor Rate MPC: invokes (evidence: `px4_mpc/px4_mpc/mpc_quadrotor.py`)
- Quadrotor Node → Multirotor Dynamics: configures (evidence: `px4_mpc/px4_mpc/mpc_quadrotor.py`)
- Spacecraft Node → Spacecraft Rate MPC: selects rate mode (evidence: `px4_mpc/px4_mpc/mpc_spacecraft.py`)
- Spacecraft Node → Spacecraft Wrench MPC: selects wrench mode (evidence: `px4_mpc/px4_mpc/mpc_spacecraft.py`)
- Spacecraft Node → Spacecraft Direct MPC: selects allocation mode (evidence: `px4_mpc/px4_mpc/mpc_spacecraft.py`)
- Multirotor Rate MPC → Multirotor Dynamics: builds dynamics (evidence: `px4_mpc/px4_mpc/controllers/multirotor_rate_mpc.py`)
- Spacecraft Rate MPC → Spacecraft Rate Dynamics: builds dynamics (evidence: `px4_mpc/px4_mpc/controllers/spacecraft_rate_mpc.py`)
- Spacecraft Wrench MPC → Spacecraft Wrench Dynamics: builds dynamics (evidence: `px4_mpc/px4_mpc/controllers/spacecraft_wrench_mpc.py`)
- Spacecraft Direct MPC → Spacecraft Allocation Dynamics: builds dynamics (evidence: `px4_mpc/px4_mpc/controllers/spacecraft_direct_allocation_mpc.py`)
- Multirotor Rate MPC → acados Solver: solves OCP (evidence: `px4_mpc/px4_mpc/controllers/multirotor_rate_mpc.py`)
- Spacecraft Rate MPC → acados Solver: solves OCP (evidence: `px4_mpc/px4_mpc/controllers/spacecraft_rate_mpc.py`)
- Spacecraft Wrench MPC → acados Solver: solves OCP (evidence: `px4_mpc/px4_mpc/controllers/spacecraft_wrench_mpc.py`)
- Spacecraft Direct MPC → acados Solver: solves OCP (evidence: `px4_mpc/px4_mpc/controllers/spacecraft_direct_allocation_mpc.py`)
- Operator → RViz Setpoints: sets references (evidence: `README.md`)
- RViz Setpoints → Spacecraft Node: provides setpoints (evidence: `README.md`)
- Spacecraft Node → Trajectory Visualization: publishes predictions
