Msg2SimulinkAPI Module Documentation¶
Toolbox: RflySim APIs

Introduction¶
One-sentence Description: Parses and encapsulates data from different IDs of the PX4 uORB message
rfly_ctrl, outputting a unified-dimension MsgBus signal.
This module belongs to the RflySim APIs library and is specifically designed to parse custom control messages transmitted from the PX4 side to the Simulink simulation environment via UDP communication. It serves as a key component in the RflySim toolchain for enabling data exchange between external control algorithms in Simulink and the PX4 flight controller. The module concatenates and encapsulates data from three distinct ID messages—rfly_ctrl, rfly_ctrl1, and rfly_ctrl2—into a 48-dimensional MsgBus signal for output, allowing control algorithms in Simulink to access various sensor and state information generated by the flight controller.
Typical applications include external controller tuning and co-simulation of drone control algorithms, commonly used in conjunction with the PX4 flight controller, CopterSim physical simulation engine, and RflySim3D visualization environment. Custom rfly_ctrl uORB messages output by PX4 are transmitted to Simulink via the communication interface; after data parsing and encapsulation by this module, the flight controller-side information can be delivered to custom control algorithms developed in Simulink, supporting the co-simulation development workflow.
Port Descriptions¶
Input Ports (Inputs)¶
This module has no input ports.
Output Ports (Outputs)¶
| Port Name | Data Type | Dimension | Description |
|---|---|---|---|
MsgBus |
double |
1×48 |
Outputs the encapsulated rfly_ctrl MsgBus data, sequentially containing the data contents of the three messages with different IDs: rfly_ctrl, rfly_ctrl1, and rfly_ctrl2 |
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 |
|---|---|---|---|---|
Sample Time(s) |
double |
0.01 |
>0 |
Module sampling time, controlling the update frequency of the output data |
Parameter Setting Description¶
Sample Time(s)¶
This parameter defines the update period of the module’s output data in seconds. A reasonable value should be set based on the simulation model’s step size and task requirements. For typical flight controller control scenarios, a value of 0.01 s is recommended.
Module Characteristics (Block Characteristics)¶
| Characteristic | Value |
|---|---|
| Supported Data Types | double, single |
| Direct Feedthrough | No |
| Sample Time | Discrete |
| Code Generation Support | No |
Data Communication Protocol¶
This module does not involve network communication.
Related Modules¶
| Module Name | Description |
|---|---|
Simulink2MsgAPI |
Input module that encapsulates Simulink-output data into the uORB message format rfly_ctrl |
VehicleStatusGetAPI |
Output module for retrieving PX4 drone status data |
SetControllerAPI |
Input module for sending PX4 drone controller control commands |
OffboardControlAPI |
Module for sending Offboard-mode control commands to the drone |
Usage Example¶
Refer to the following path for related usage examples:
Please refer to
Readme.pdfin the above path for complete example descriptions and operational steps.
Notes and Common Issues¶
- Initialization Order: This module relies on the uORB message communication link of the RflySim simulation environment for initialization. It must be executed after the PX4 firmware has started and the simulation environment’s communication link has been established; otherwise, it will output all-zero data.
- Output Dimension Matching: The module outputs a fixed 48-dimensional MsgBus signal, corresponding to three sets of
rfly_ctrlmessages (rfly_ctrl,rfly_ctrl1,rfly_ctrl2), each with 16 dimensions. When using the output, data must be split and extracted according to this dimensionality. Direct modification of the output dimension is not allowed, as it will cause a signal dimension mismatch error. - Sample Time Matching: The module’s output sample time must match the PX4 firmware’s uORB message update scheduling period. It is recommended to set it to the same value as the PX4 control period, typically between 0.001 s and 0.01 s. If the sample time is significantly larger than the PX4 message update frequency, output data will be delayed; if it is significantly smaller, redundant duplicate data will be generated.
- Message ID Compatibility: This module can only parse
rfly_ctrl-type uORB messages with IDsrfly_ctrl,rfly_ctrl1, andrfly_ctrl2. If custom message IDs or non-rfly_ctrltype messages are used, the module will fail to parse them correctly, resulting in abnormal output data.
Changelog¶
v4.0(2024-08-07): Initial release, implementing the encapsulation and output functionality forrfly_ctrlmessages with different IDs.