Skip to content

UDP_40100_RflyPx4Recv Module Documentation

Toolbox: RflySim Model

UDP_40100_RflyPx4Recv Module Appearance

Introduction

Brief Description: This module listens on a specified UDP port to receive custom uORB messages published by the PX4 flight controller.

This module belongs to the RflySim Model interface library and serves as a communication interface for custom flight controller extension development within the RflySim toolchain. It enables users to specify a target aircraft ID in multi-aircraft simulation scenarios to receive custom uORB messages. Typical applications include custom extended control and offline simulation validation of flight control algorithms. Based on the input aircraft ID, the module automatically binds to the corresponding UDP port (40101 + aircraft ID offset), establishes communication with the PX4 flight controller process running in CopterSim, receives and parses custom uORB data published by PX4, and outputs structured data containing checksum, aircraft ID, timestamp, and 8-dimensional control values for use by custom algorithm modules in Simulink. It supports end-to-end simulation validation when used in conjunction with the RflySim3D visualization environment.

Port Descriptions

Input Ports (Inputs)

This module has no input ports.

Output Ports (Outputs)

Port Name Data Type Dimension Description
checksum double 1×1 Message checksum; fixed value is 1234567898
CopterID double 1×1 Drone ID corresponding to the received message
runnedTime double 1×1 Timestamp when the message was sent, in seconds
controls double 1×8 8-dimensional control values from the custom uORB message

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 Target drone ID whose messages are to be listened to
Sample Time (s) double 0.01 >0 Module sampling time, in seconds

Parameter Setting Notes

CopterID

The module listens on the UDP port 40101 + 2*CopterID for the specified ID. The configured ID must match the PX4 flight controller ID that actually sends the custom uORB messages.

Sample Time (s)

Sets the output update interval of the module. It is recommended to set this value consistent with the PX4 flight controller’s control period (typically 0.01 seconds).

Module Characteristics (Block Characteristics)

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

Data Communication Protocol

This module communicates via UDP and listens on port 40101 + CopterID * 2, where CopterID is the aircraft ID configured in the module parameters (starting from 1). The received data format is a custom PX4ExtMsg structure, defined as follows:

struct PX4ExtMsg {
    int checksum;          // Checksum field; fixed value is 1234567898
    int CopterID;          // Aircraft ID identifier
    double runnedTime;     // Current timestamp, in seconds
    float controls[8];     // 8 custom control channels
}
Module Name Description
UDP_4001_OutSensors Sends sensor data to the PX4 flight controller simulation
UDP_40100_RflyPx4Send Sends custom uORB messages to the PX4 flight controller via UDP port
QuadcopterMotorMix Multi-rotor motor mixing output module
PX4ActuatorOutput Reads actuator output data from the PX4 flight controller

Usage Example

For usage examples, refer to the following path:

[RflySim Installation Path]/RflySimAPIs/4.RflySimModel/0.ApiExps/3.ExtCtrlAPI/3.ExtCtrlAPI-UDP40100/Readme.pdf

Please refer to Readme.pdf in the above path for complete example descriptions and operational steps.

Notes and Common Issues

  • Port Binding Rule: The actual listening port of this module is 40101 + 2*CopterID. Ensure that the corresponding port is not occupied by other system processes, and that the custom flight controller’s uORB message sending port on the sender side matches this module’s listening port; otherwise, no data will be received.
  • Initialization Sequence: This module can only bind the UDP port and receive data normally after the RflySim simulation environment is started and the corresponding multi-rotor ID’s PX4 flight controller instance is initialized. Do not send test messages before the flight controller starts, as this may prevent proper UDP connection establishment.
  • Checksum Verification: The module verifies the checksum field of received messages; only messages with a checksum equal to 1234567898 will be correctly parsed and output. When sending custom messages, ensure the checksum field is correct; otherwise, outputs will default to all zeros.
  • Aircraft ID Matching: The CopterID set in the module parameters must match the CopterID of the message published by the PX4 flight controller side; otherwise, the module will filter out mismatched messages and fail to output valid data.
  • Sample Time Matching: It is recommended that the Sample Time (s) set for the module matches the message publishing period of the custom uORB messages on the PX4 flight controller side. It should not exceed twice the message publishing period, otherwise packet loss or delayed data updates may occur.
  • Custom Message Length: This module only supports fixed-length PX4ExtMsg structure messages. Do not send custom UDP packets shorter or longer than this structure, otherwise parsing errors or garbled output may occur.
  • Multi-Aircraft Environment Usage: In multi-aircraft simulation scenarios, each aircraft requires a separate instance of this module with a unique CopterID setting. Do not assign the same ID to multiple modules, otherwise port conflicts and data corruption may occur.
  • Reference: For more information on developing and configuring custom uORB messages, refer to the example project documentation in the installation directory as indicated in the module description to avoid parsing failures due to message format mismatches.

Changelog

  • v4.0.0 (2023-01-01): Initial release,实现了基于UDP 40101+2端口监听读取PX4飞控自定义uORB消息的功能。 (Implemented functionality for listening on UDP port 40101+2 and reading custom uORB messages from the PX4 flight controller.)