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 matching and interaction with custom firmware control inputs.

This module is a companion interface module in the RflySim Swarm interface library, designed for use with the flight controller automatic code generation functionality. It facilitates data exchange during Simulink simulations when developing custom flight controller firmware. The module's input and output ports must strictly match the custom firmware interface generated via automatic code generation on the PX4 flight controller side. It transmits control logic data developed in Simulink to the flight controller firmware while simultaneously reading the flight controller's state information.

In the custom flight controller firmware development workflow of the RflySim toolchain, this module serves as a bridge between the Simulink environment and the PX4 flight controller firmware. It supports developers in achieving hardware-in-the-loop simulation or firmware functionality validation in conjunction with CopterSim after completing automatic code generation for the flight controller. It can also accommodate interface matching requirements for custom firmware of 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 different devices.

InputSize

Sets the dimension of the input control signals. It must match the number of inputs required by the custom firmware generated via automatic code generation on the flight controller side; 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 via automatic code generation on the flight controller side; 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.