Skip to the content
FixTheRobot Explore Robotics / UAV / Module 6 / M6-T3

UAV Systems Engineering · Module 6

M6-T3: PX4 architecture

A request to “make the drone do X” flows through a defined pipeline of modules. Know the pipeline and you know where to look when it fails.

  • Lesson 3 of 16
  • UAV Software and Flight-Controller Integration
  • Implementation-specific
  • About 6 minutes to read

PX4 splits the problem into modules that exchange messages. Each has one job: estimate, control, allocate, manage modes, log. This modularity is what makes it possible to replace or inspect any step, and it is the map you use to debug any behaviour.

Learning objectives

After this lesson, you should be able to:

  • Name the main PX4 modules in the multicopter control pipeline and what each outputs.
  • Distinguish the flight stack from the middleware and operating-system layers.
  • Trace a position setpoint from the navigator to motor outputs.
  • Explain what the commander and navigator decide and where failsafes originate.

Conceptual explanation

Implementation-specific Module names (for example mc_pos_control, mc_att_control, mc_rate_control, control_allocator, commander, navigator, ekf2) follow recent PX4 releases. Older releases used mixers instead of the control allocator and some names have changed. Check the architecture page of the documentation for your release.

The PX4 documentation describes two layers:

  • The flight stack: the estimation and control algorithms, the navigator and commander, and the drivers.
  • The middleware: the uORB publish/subscribe bus, the MAVLink and DDS communication layers, the logger and the operating-system abstraction (NuttX on flight controllers, POSIX on a PC for simulation).

For a multicopter the control pipeline is a cascade of modules, each subscribing to the output of the previous one: mc_pos_control (position and velocity → attitude and thrust setpoint), mc_att_control (attitude → body-rate setpoint), mc_rate_control (rate → torque and thrust demand) and the control_allocator (demand → motor commands, respecting effectiveness and limits).

PX4 control and estimation pipelineSensor drivers publish raw data; EKF2 produces the state estimate; the position, attitude and rate controllers produce setpoints in sequence; the control allocator turns torque and thrust demands into actuator commands. The commander and navigator decide which setpoints are active.DriverssensorsEKF2statePosition / velocity ctrlmc_pos_controlAttitude / rate ctrlmc_att, mc_rateControl allocatoractuatorsCommander and navigator select modes and setpoints; the logger records the uORB topics.
The multicopter pipeline. Every arrow is a uORB topic that you can list and log.
Animation of a position step travelling through a multicopter control cascade. The position error becomes a velocity setpoint, the velocity error becomes an attitude setpoint, the attitude error becomes a rate setpoint, and the rate error becomes a torque. Five strips show position, velocity setpoint, attitude setpoint, rate setpoint and torque against time for a five metre step; inner signals respond first and fastest, outer ones slowly.
The PX4 multicopter pipeline in miniature: position PP → velocity PID → attitude PP → rate PID → torque (then the control allocator). Each stage gets its setpoint from the stage outside it, with limits (velocity, tilt). Planar single-axis model with illustrative gains; computed. (Looping, about 6 seconds; drawn and computed for this course with illustrative values.)

Engineering intuition

Picture an assembly line. Each station takes the previous station’s output, does one transformation, and hands it on. When the product at the end is wrong you inspect each hand-off: is the position setpoint what the navigator intended? Is the attitude setpoint consistent with it? Do the rate setpoints follow? Are the motor outputs saturated? Because every hand-off is a logged topic, you can answer these questions from a flight log.

The commander and navigator are the supervisors: the commander decides arming state, the active flight mode and failsafe actions from vehicle status, link health and sensor validity; the navigator produces the setpoints for mission, return and land modes. The controllers do not know why they are following a setpoint, only that they are.

Mathematical formulation

The cascade corresponds to the control design of the control lessons. In symbols, with the position error epe_{p} and velocity error eve_{v}, the position controller outputs an acceleration (and from it the thrust vector and attitude setpoint), the attitude controller outputs a rate setpoint ωsp\omega _{\text{sp}} from the attitude error, and the rate controller outputs torque τ\tau :

Outer loops
vsp=Kp(psp−p),asp=PIDv(vsp−v),(Rsp,T)=f(asp,ψsp)\mathbf v_{\text{sp}} = K_p(\mathbf p_{\text{sp}} - \mathbf p), \qquad \mathbf a_{\text{sp}} = \mathrm{PID}_v(\mathbf v_{\text{sp}} - \mathbf v), \qquad (\mathbf R_{\text{sp}}, T) = f(\mathbf a_{\text{sp}}, \psi_{\text{sp}})
Inner loops
ωsp=KR eR(Rsp,R),τ=PIDω(ωsp−ω)\boldsymbol\omega_{\text{sp}} = K_R\,\mathbf e_R(\mathbf R_{\text{sp}}, \mathbf R), \qquad \boldsymbol\tau = \mathrm{PID}_\omega(\boldsymbol\omega_{\text{sp}} - \boldsymbol\omega)

The control allocator solves for actuator commands uu such that B u=[τ, T]⊤B\,u=[\tau ,\,T]^{\top} with BB the effectiveness matrix of the vehicle, subject to actuator limits; when limits are hit it reduces the lower-priority components (priorities follow the documentation of the version in use). The bandwidth separation of the earlier lesson applies stage by stage.

Architecture and data flow

Sensors (SPI/I²C/UART drivers) → sensor_combined, vehicle_gps_position → ekf2 → vehicle_local_position, vehicle_attitude, vehicle_odometry → mc_pos_control → vehicle_attitude_setpoint → mc_att_control → vehicle_rates_setpoint → mc_rate_control → vehicle_torque_setpoint, vehicle_thrust_setpoint → control_allocator → actuator_motors → output drivers. The navigator publishes position_setpoint_triplet and the trajectory setpoint, and the commander publishes vehicle_status and vehicle_control_mode. Topic names follow recent releases; list them with uorb top on your vehicle.

Real-world UAV applications

  • Locating the cause of a tracking problem by comparing setpoints and measurements stage by stage.
  • Replacing one stage, for example sending attitude or rate setpoints from a research controller.
  • Adding a custom module that subscribes to estimator output and publishes diagnostic data.
  • Writing the architecture section of a system design document.

Implementation example

Reading the pipeline from a flight log: load the topics named above with pyulog and compare each stage’s output with its input. This is a reference script (it needs a real .ulg file and pyulog, so the tests only check that it parses). Topic and field names follow recent releases.

from pyulog import ULog
import numpy as np

ulog = ULog('flight.ulg')
def topic(name):
    return next(d for d in ulog.data_list if d.name == name).data
pos = topic('vehicle_local_position'); att = topic('vehicle_attitude'); att_sp = topic('vehicle_attitude_setpoint')
t = pos['timestamp'] * 1e-6
print('estimator output rate: %.1f Hz' % (1.0 / np.median(np.diff(t))))
# tracking at the position level: reference is in the trajectory setpoint topic
try:
    sp = topic('trajectory_setpoint')
    n = min(len(sp['timestamp']), len(pos['timestamp']))
    err = np.hypot(sp['position[0]'][:n] - pos['x'][:n], sp['position[1]'][:n] - pos['y'][:n])
    print('median horizontal tracking error: %.2f m' % np.median(err))
except StopIteration:
    print('no trajectory_setpoint topic in this log (mode without one)')
Reading pipeline topics from a ULog. Verify field names against your release.

Common engineering mistakes

Debugging at the wrong stage

Looking at motor outputs when the position setpoint was already wrong.

Assuming module names are stable

Older releases differ; read the version’s architecture page.

Editing parameters of several stages together

Change one stage at a time, from the inside out.

Ignoring the allocator

Motor saturation and effectiveness errors show up there, not in the controllers.

Confusing the commander’s mode with the controller’s setpoint source

A mode change changes which module supplies the setpoint, not the controllers themselves.

Failure modes

Failure modes, symptoms and causes
Failure modeHow it shows upLikely cause
Setpoint not followedTracking error largeA stage saturated, gains off, or the estimate wrong
Wrong motor mappingFlip on takeoffMotor order or direction misconfigured in the allocator/airframe settings
Unexpected mode changeVehicle changes behaviour mid-flightFailsafe action from the commander (link, battery, estimator)
Missing topicLog lacks a stageLogger topic selection (SDLOG parameters) excludes it

Debugging approach

  1. Plot setpoint against measurement for each stage in the log.
  2. Check vehicle_status and failsafe flags at the time of the event.
  3. Verify that the logged topic list includes all stages (logger profile).
  4. Compare actuator outputs against limits to find saturation.

Practical exercises

  1. Draw the pipeline for your PX4 version from the architecture documentation and mark every topic name.
  2. In SITL, use listener to print one message from each stage.
  3. Find which parameter group configures each controller stage.
  4. In a flight log, find the time the commander changed the mode and list the topics that changed.

Interview questions

Write an answer in your own words, then reveal the model answer. Nothing is sent anywhere.

Question 1

Describe the multicopter control pipeline in PX4.

Model answer

Navigator or offboard setpoint → position/velocity controller (thrust vector and attitude setpoint) → attitude controller (rate setpoint) → rate controller (torque and thrust) → control allocator (motor commands), with EKF2 supplying the state.

Question 2

What is the role of the commander?

Model answer

It manages arming, flight modes and failsafes from vehicle status, link health and sensor validity, deciding which setpoint source is active and what to do when something fails.

Question 3

Why is a modular, message-based architecture useful for a research team?

Model answer

You can replace or tap any stage (for example inject external odometry or send rate setpoints), and every interface is a topic that can be logged and replayed.

References and further reading

Primary papers, official documentation and standards. Each claim above that is specific to a tool or version points here.

What’s next

Mark this lesson

Saved in this browser and synced to your account when you are signed in.

Next lesson

M6-T4: PX4 modules and communication

Explain uORB publish/subscribe messaging, topics and rates, and use topic listing and logging to inspect a running vehicle.