Skip to content

AutoFirmwareAPI Module Documentation

Toolbox: RflySim Swarm

AutoFirmwareAPI Module Appearance

Introduction

One-sentence Description: This module provides a Simulink-side interface compatible with automatically generated firmware for the PX4 flight controller, enabling interaction with custom firmware control inputs.

This module serves as a companion interface within the RflySim Swarm interface library, specifically designed for data exchange in Simulink simulations during custom flight controller firmware development. Its input and output ports must strictly match those of the custom firmware generated via automatic code generation on the PX4 flight controller side, allowing the module to transmit control logic developed in Simulink to the flight controller firmware while simultaneously reading the flight controller’s state information.

Within the RflySim toolchain’s custom flight controller firmware development workflow, this module acts as a bridge between the Simulink environment and the PX4 flight controller firmware. It supports hardware-in-the-loop simulation and firmware functionality validation after automatic code generation, and accommodates interface alignment requirements for multiple drones in cluster development scenarios.

Port Descriptions

Input Ports (Inputs)

Port Name Data Type Dimension Description
ControlInputs double N×1 Custom control input vector; dimension N is determined by the input requirements of the custom flight controller firmware and must match the interface generated via automatic code generation

Output Ports (Outputs)

Port Name Data Type Dimension Description
SensorOutputs double M×1 Flight controller sensor and state output vector; dimension M is determined by the output requirements of the custom flight controller firmware and must match the interface generated via automatic code generation

Parameter Configuration (Parameters)

The following parameters can be configured in the Mask dialog box opened by double-clicking the module:

Parameter Name Type Default Value Available Values/Range Description
CopterID int 1 1~255 ID number of the target drone in multi-drone simulation
InputSize int 4 ≥1 Dimension of the custom control input vector; must match the number of inputs required by the custom firmware
OutputSize int 20 ≥1 Dimension of the flight controller output vector; must match the number of outputs provided by the custom firmware

Parameter Setting Notes

CopterID

In multi-drone cluster simulation scenarios, specifies the drone ID connected to the current interface. Each AutoFirmwareAPI module in a multi-drone setup must be assigned a unique ID to distinguish between devices.

InputSize

Sets the dimension of the input control signals. It must match the number of inputs required by the custom firmware generated on the flight controller side via automatic code generation; otherwise, dimension mismatch errors will occur during simulation.

OutputSize

Sets the dimension of the flight controller’s state/sensor outputs. It must match the number of outputs provided by the custom firmware generated on the flight controller side via automatic code generation; otherwise, dimension mismatch errors will occur during simulation.

Module Characteristics (Block Characteristics)

Characteristic Value
Supported Data Types double, single
Direct Feedthrough Yes
Sample Time Inherited
Code Generation Support No

Data Communication Protocol

This module does not involve network communication.

Module Name Description
SwarmPositionConfig Configures initial position parameters for cluster drone simulation
SwarmScheduler Implements task scheduling and control for multi-drone clusters
PX4OffboardControl Enables offline control data exchange with the PX4 flight controller
RadioControlSwarm Implements remote control input for cluster drone systems

Notes and Common Issues

  • Initialization Order: The flight controller’s automatically generated firmware must be configured and compiled first before connecting and matching the input/output ports of this module. Reversing this order will result in simulation errors due to interface signal mismatches.
  • Sample Time Matching: The sample time of this module must match the control cycle of the automatically generated firmware on the flight controller side. Excessive sample time differences can cause control command desynchronization, leading to divergence in drone attitude and position during simulation.
  • Interface Matching Requirements: All control input port dimensions and data types of this module must strictly match the corresponding interfaces of the custom firmware on the flight controller side. Input ports must not be arbitrarily added or removed, nor can signal formats be modified.
  • Dependency Requirements: This module can only be used in conjunction with RflySim’s flight controller automatic code generation functionality and cannot operate independently as a general-purpose control module in simulations involving non-AutoFirmware-generated flight controller firmware.

Changelog

  • v4.1.0 (2024-12-10): Initial release, introducing the AutoFirmwareAPI module to support matching with automatically generated custom flight controller firmware.