# rl-tools/px4 architecture

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

- Interactive diagram: https://gitdiagram.com/rl-tools/px4
- Repository: https://github.com/rl-tools/px4

## Overview

This repository adds RLtools control modules and supporting workflows to PX4. In flight, the policy consumes vehicle state and commands, produces motor outputs, and the multiplexer selects between those outputs and the original controller. The README also documents command/trajectory control, inference benchmarking, external position-reference forwarding, and system-identification analysis. The graph includes these major capabilities; some links for unsampled modules are dashed because their runtime wiring is not shown in the excerpts.

Main entry points: [`external_modules/src/modules/rl_tools_policy/RLtoolsPolicy.cpp`](https://github.com/rl-tools/px4/blob/master/external_modules/src/modules/rl_tools_policy/RLtoolsPolicy.cpp) (RLtools policy), [`external_modules/src/modules/actuator_motors_multiplexer/actuator_motors_multiplexer.cpp`](https://github.com/rl-tools/px4/blob/master/external_modules/src/modules/actuator_motors_multiplexer/actuator_motors_multiplexer.cpp) (Motor multiplexer), [`sysid/static/main.js`](https://github.com/rl-tools/px4/blob/master/sysid/static/main.js) (Analysis UI), [`external_modules/src/modules/rl_tools_commander/RLtoolsCommander.cpp`](https://github.com/rl-tools/px4/blob/master/external_modules/src/modules/rl_tools_commander/RLtoolsCommander.cpp) (RLtools commander)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_flight["Flight control"]
  node_policy["RLtools policy<br/>[RLtoolsPolicy.cpp]"]
  node_policy_model["Policy adapter"]
  node_motor_output["RL motor output"]
  node_multiplexer["Motor multiplexer"]
end

subgraph group_tools["Control tools"]
  node_commander["RLtools commander"]
  node_trajectory["Trajectory setpoints"]
  node_benchmark["Inference benchmark"]
  node_benchmark_model["Benchmark model<br/>[model.h]"]
end

subgraph group_sysid["System identification"]
  node_sysid_analysis["Log analysis<br/>[analyze.py]"]
  node_sysid_processing["Browser processing<br/>[process.py]"]
  node_sysid_loader["ULog loader<br/>[load_ulg.py]"]
  node_sysid_ui["Analysis UI<br/>[main.js]"]
end

subgraph group_position["Position feedback"]
  node_ros_forwarder["ROS to MAVLink"]
  node_px4_position["PX4 position estimate"]
end

node_pilot(("Pilot / QGC"))
node_vehicle_state(("Vehicle state"))
node_original_controller["PX4 controller"]
node_actuator_output["Selected motor output"]
node_ulog["PX4 flight logs"]
node_mocap(("Motion capture"))

node_vehicle_state -->|"provides state"| node_policy
node_policy -.->|"uses adapter"| node_policy_model
node_policy -->|"publishes motors"| node_motor_output
node_motor_output -->|"feeds motors"| node_multiplexer
node_original_controller -->|"provides motors"| node_multiplexer
node_multiplexer -->|"publishes selection"| node_actuator_output
node_pilot -->|"activates policy"| node_multiplexer
node_pilot -->|"issues commands"| node_commander
node_commander -->|"publishes setpoints"| node_trajectory
node_trajectory -.->|"supplies commands"| node_policy
node_benchmark -->|"evaluates model"| node_benchmark_model
node_ulog -.->|"analyzes logs"| node_sysid_analysis
node_sysid_ui -->|"loads processing"| node_sysid_processing
node_sysid_ui -->|"loads ULog loader"| node_sysid_loader
node_mocap -->|"sends position"| node_ros_forwarder
node_ros_forwarder -->|"forwards MAVLink"| node_px4_position

click node_policy "https://github.com/rl-tools/px4/blob/master/external_modules/src/modules/rl_tools_policy/RLtoolsPolicy.cpp"
click node_policy_model "https://github.com/rl-tools/px4/blob/master/external_modules/src/modules/rl_tools_policy/rl_tools_adapter.cpp"
click node_multiplexer "https://github.com/rl-tools/px4/blob/master/external_modules/src/modules/actuator_motors_multiplexer/actuator_motors_multiplexer.cpp"
click node_commander "https://github.com/rl-tools/px4/blob/master/external_modules/src/modules/rl_tools_commander/RLtoolsCommander.cpp"
click node_benchmark "https://github.com/rl-tools/px4/blob/master/external_modules/src/modules/rl_tools_benchmark/RLtoolsBenchmark.cpp"
click node_benchmark_model "https://github.com/rl-tools/px4/blob/master/external_modules/src/modules/rl_tools_benchmark/model.h"
click node_sysid_analysis "https://github.com/rl-tools/px4/blob/master/sysid/analyze.py"
click node_sysid_processing "https://github.com/rl-tools/px4/blob/master/sysid/process.py"
click node_sysid_loader "https://github.com/rl-tools/px4/blob/master/sysid/load_ulg.py"
click node_sysid_ui "https://github.com/rl-tools/px4/blob/master/sysid/static/main.js"
click node_ros_forwarder "https://github.com/rl-tools/px4/blob/master/tools/external_position_reference/forward_ros_to_mavlink.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_policy,node_policy_model,node_motor_output,node_multiplexer toneBlue
class node_commander,node_trajectory,node_benchmark,node_benchmark_model toneAmber
class node_sysid_analysis,node_sysid_processing,node_sysid_loader,node_sysid_ui toneMint
class node_ros_forwarder,node_px4_position toneRose
class node_pilot,node_vehicle_state,node_original_controller,node_actuator_output,node_ulog,node_mocap toneIndigo
```

## Components

### Flight control

- [RLtools policy](https://github.com/rl-tools/px4/blob/master/external_modules/src/modules/rl_tools_policy/RLtoolsPolicy.cpp): `external_modules/src/modules/rl_tools_policy/RLtoolsPolicy.cpp`
- [Policy adapter](https://github.com/rl-tools/px4/blob/master/external_modules/src/modules/rl_tools_policy/rl_tools_adapter.cpp): `external_modules/src/modules/rl_tools_policy/rl_tools_adapter.cpp`
- **RL motor output**
- [Motor multiplexer](https://github.com/rl-tools/px4/blob/master/external_modules/src/modules/actuator_motors_multiplexer/actuator_motors_multiplexer.cpp): `external_modules/src/modules/actuator_motors_multiplexer/actuator_motors_multiplexer.cpp`

### Control tools

- [RLtools commander](https://github.com/rl-tools/px4/blob/master/external_modules/src/modules/rl_tools_commander/RLtoolsCommander.cpp): `external_modules/src/modules/rl_tools_commander/RLtoolsCommander.cpp`
- **Trajectory setpoints**
- [Inference benchmark](https://github.com/rl-tools/px4/blob/master/external_modules/src/modules/rl_tools_benchmark/RLtoolsBenchmark.cpp): `external_modules/src/modules/rl_tools_benchmark/RLtoolsBenchmark.cpp`
- [Benchmark model](https://github.com/rl-tools/px4/blob/master/external_modules/src/modules/rl_tools_benchmark/model.h): `external_modules/src/modules/rl_tools_benchmark/model.h`

### System identification

- [Log analysis](https://github.com/rl-tools/px4/blob/master/sysid/analyze.py): `sysid/analyze.py`
- [Browser processing](https://github.com/rl-tools/px4/blob/master/sysid/process.py): `sysid/process.py`
- [ULog loader](https://github.com/rl-tools/px4/blob/master/sysid/load_ulg.py): `sysid/load_ulg.py`
- [Analysis UI](https://github.com/rl-tools/px4/blob/master/sysid/static/main.js): `sysid/static/main.js`

### Position feedback

- [ROS to MAVLink](https://github.com/rl-tools/px4/blob/master/tools/external_position_reference/forward_ros_to_mavlink.py): `tools/external_position_reference/forward_ros_to_mavlink.py`
- **PX4 position estimate**

### Other components

- **Pilot / QGC**
- **Vehicle state**
- **PX4 controller**
- **Selected motor output**
- **PX4 flight logs**
- **Motion capture**

## Connections

- Vehicle state → RLtools policy: provides state (evidence: `external_modules/src/modules/rl_tools_policy/RLtoolsPolicy.cpp`)
- RLtools policy → Policy adapter: uses adapter
- RLtools policy → RL motor output: publishes motors (evidence: `external_modules/src/modules/rl_tools_policy/RLtoolsPolicy.cpp`)
- RL motor output → Motor multiplexer: feeds motors
- PX4 controller → Motor multiplexer: provides motors
- Motor multiplexer → Selected motor output: publishes selection (evidence: `external_modules/src/modules/actuator_motors_multiplexer/actuator_motors_multiplexer.cpp`)
- Pilot / QGC → Motor multiplexer: activates policy (evidence: `README.MD`)
- Pilot / QGC → RLtools commander: issues commands (evidence: `README.MD`)
- RLtools commander → Trajectory setpoints: publishes setpoints (evidence: `external_modules/src/modules/rl_tools_commander/RLtoolsCommander.cpp`)
- Trajectory setpoints → RLtools policy: supplies commands
- Inference benchmark → Benchmark model: evaluates model (evidence: `external_modules/src/modules/rl_tools_benchmark/RLtoolsBenchmark.cpp`)
- PX4 flight logs → Log analysis: analyzes logs
- Analysis UI → Browser processing: loads processing (evidence: `sysid/static/main.js`)
- Analysis UI → ULog loader: loads ULog loader (evidence: `sysid/static/main.js`)
- Motion capture → ROS to MAVLink: sends position (evidence: `README.MD`)
- ROS to MAVLink → PX4 position estimate: forwards MAVLink (evidence: `README.MD`)
