Papers
Topics
Authors
Recent
Gemini 2.5 Flash
Gemini 2.5 Flash
91 tokens/sec
GPT-4o
12 tokens/sec
Gemini 2.5 Pro Pro
o3 Pro
5 tokens/sec
GPT-4.1 Pro
15 tokens/sec
DeepSeek R1 via Azure Pro
33 tokens/sec
Gemini 2.5 Flash Deprecated
12 tokens/sec
2000 character limit reached

A Neural Network Mode for PX4 on Embedded Flight Controllers (2505.00432v1)

Published 1 May 2025 in cs.RO

Abstract: This paper contributes an open-sourced implementation of a neural-network based controller framework within the PX4 stack. We develop a custom module for inference on the microcontroller while retaining all of the functionality of the PX4 autopilot. Policies trained in the Aerial Gym Simulator are converted to the TensorFlow Lite format and then built together with PX4 and flashed to the flight controller. The policies substitute the control-cascade within PX4 to offer an end-to-end position-setpoint tracking controller directly providing normalized motor RPM setpoints. Experiments conducted in simulation and the real-world show similar tracking performance. We thus provide a flight-ready pipeline for testing neural control policies in the real world. The pipeline simplifies the deployment of neural networks on embedded flight controller hardware thereby accelerating research on learning-based control. Both the Aerial Gym Simulator and the PX4 module are open-sourced at https://github.com/ntnu-arl/aerial_gym_simulator and https://github.com/SindreMHegre/PX4-Autopilot-public/tree/for_paper. Video: https://youtu.be/lY1OKz_UOqM?si=VtzL243BAY3lblTJ.

Summary

  • The paper proposes a custom PX4 module that embeds NN inference on resource-constrained flight controllers to execute end-to-end learned control policies.
  • It introduces a conversion pipeline from PyTorch models to TensorFlow Lite Micro, optimizing NN deployment under tight memory and computation limits.
  • The framework demonstrates high control loop frequencies and low inference times, validating sim-to-real transfer on a Pixracer Pro-based quadcopter.

This paper (2505.00432) presents a practical, open-source approach to deploying neural network (NN) based controllers directly onto embedded flight controllers (FCs) running the PX4 autopilot software. The core problem addressed is the difficulty of integrating trained NNs into the resource-constrained environment of typical FC microcontrollers, which often lack the computational power, memory, and software libraries required for NN inference.

The main contribution is a custom module integrated within the PX4 stack that allows for NN inference on the FC's microcontroller. This module is designed to replace parts of the standard PX4 control cascade, enabling end-to-end control policies learned via reinforcement learning (RL) in simulation to be executed directly onboard.

Implementation Details

The proposed framework leverages several key technologies:

  1. PX4 Autopilot: The implementation is built within the widely-used, open-source PX4 framework. This allows researchers and developers to utilize PX4's robust features like safety checks, state estimation (Extended Kalman Filter), communication middleware (uORB), and broad hardware support, without needing to rebuild these components from scratch.
  2. TensorFlow Lite Micro (TFLM): This library is used for performing NN inference efficiently on embedded devices with limited memory and processing capabilities. TFLM supports converting trained models into a format suitable for microcontrollers and provides optimized kernels for various operations.
  3. Custom PX4 Module: A new C++ module is added to the PX4 firmware. This module subscribes to relevant state information via the uORB middleware (e.g., angular velocity, position setpoints) and publishes actuator commands (e.g., motor RPM setpoints). The module contains the compiled NN model and the logic for running TFLM inference.
  4. Sim-to-Real Pipeline: The paper describes a pipeline starting with training policies in the Aerial Gym Simulator [kulkarni_aerial_2025], an Isaac Gym-based environment. A conversion script takes the trained PyTorch model, converts it to the TFLM format, and then into a C-array. This C-array is then embedded directly into the PX4 module's source code, which is compiled into the final firmware flashed onto the FC.

Specifically, the demonstrated implementation uses an end-to-end position setpoint tracking controller. This NN replaces the entire classical PX4 control stack, from the position controller down through velocity, attitude, body rates, and control allocation (mixer), outputting normalized motor RPM setpoints directly.

The NN architecture used in the experiments is relatively small to fit within memory constraints: 2 hidden layers with 64 and 32 neurons, using ReLU activation. This size is shown to fit within the typical 50KB of RAM available for dynamic allocation on the microcontroller.

The custom module operates as a new flight mode within PX4. This allows pilots/users to arm and take off using standard, reliable PX4 modes (like Position mode) and then switch to the neural control mode mid-flight for testing. The ability to switch back to classical modes enhances safety during development and experimentation. The module is scheduled to run as a callback function whenever the relevant state topic is updated (e.g., angular velocity at 650 Hz on the Pixracer Pro).

Practical Application and Experiments

The framework was tested on a 1.2kg quadcopter platform using a Pixracer Pro FC, which features an STM32H743 microcontroller (460 MHz M7, 2MB Flash, 1MB RAM). The experimental setup used an external motion capture system to provide high-frequency pose updates to the FC, simulating a reliable state estimate source.

The experiments involved tracking a square trajectory. Results showed similar position and velocity tracking performance between simulation and real-world flights. The inference time for the deployed NN was measured at approximately 93.4 μs93.4~\mu\textrm{s}, with the total control loop taking about 137.6 μs137.6~\mu\textrm{s}. This low inference time allows for high control loop frequencies.

A discrepancy was observed in the motor commands between simulation and reality, which the authors attribute to inaccuracies in the simulation model's motor time constants. This highlights a practical challenge in sim-to-real transfer: the fidelity of the simulation model, particularly for low-level dynamics, is critical for end-to-end policies directly commanding actuators.

Benefits for Practitioners

This work significantly lowers the barrier to entry for researchers wanting to test learning-based control policies on real drone hardware.

  • Simplified Deployment: The provided pipeline handles the conversion and integration into the PX4 build system. Developers can focus on training their policies rather than building custom firmware or hardware interfaces.
  • Leverages Existing PX4 Features: Safety checks, state estimation, drivers, and message passing are readily available, reducing the need for reimplementation.
  • Onboard Inference: Running the NN directly on the FC microcontroller eliminates the communication latency and complexity associated with using a separate, more powerful companion computer for inference.
  • Flexibility: The module can be adapted to replace different parts of the control cascade, allowing for experimentation with various levels of NN control (e.g., only attitude control, or only control allocation).
  • Open-Source: The code for the PX4 module and the simulator conversion script is open-sourced [https://github.com/SindreMHegre/PX4-Autopilot-public/tree/for\_paper, https://github.com/ntnu-arl/aerial\_gym\_simulator], providing a ready-to-use base for others.

Implementation Considerations

  • Model Size: The primary constraint is the limited RAM and Flash memory on the microcontroller. NNs must be small enough to fit. This might require model quantization or architectural choices tailored for embedded deployment.
  • Computational Cost: While the STM32H743 is relatively powerful for an FC, complex NNs or high inference frequencies can still strain the processor. The measured inference time of 93.4 μs93.4~\mu\textrm{s} is promising for this specific small network.
  • Sim-to-Real Transfer: While position tracking transferred well, fidelity in low-level commands (like motor outputs) depends heavily on the accuracy of the simulation model, especially for parameters like motor dynamics. Careful system identification is crucial.
  • Integration with PX4: Developers need to understand the PX4 build system and uORB middleware to effectively integrate and customize the module. The paper mentions ongoing work to improve documentation and potentially merge into the main PX4 repository.

Conclusion

The paper successfully demonstrates a practical method for integrating NN control into the PX4 autopilot running on resource-constrained embedded hardware. By using TFLM and a custom PX4 module, it provides an open-source pipeline that simplifies the deployment of learning-based control policies for aerial robots, accelerating research and enabling new types of controllers to run directly on standard FCs. The approach's viability is shown through successful sim-to-real transfer experiments for position tracking.