DllSimCtrlAPI Interface Documentation¶
Introduction¶
Overview: This file provides the underlying simulation control and data interaction interfaces for the RflySim simulation platform. It encapsulates multiple classes related to simulation control, data management, and model loading, supporting closed-loop co-simulation between third-party code and flight controllers such as PX4.
The RflySim platform requires dynamic link libraries (DLLs) to enable interaction between the Python environment and the simulation core as well as flight controller firmware. This module encapsulates the complete set of interfaces for interfacing with the underlying simulation control library, enabling low-level control and scheduling for various types of UAV simulation tasks. It supports structured management of 3D simulation data and hardware-in-the-loop (HIL) simulation data, and implements RflySim's proprietary comprehensive model control protocol. This allows adaptation to scenarios such as multi-rotor DLL model loading and custom simulation model scheduling, forming the core foundational module for closed-loop simulation control in RflySimSDK.
Quick Start¶
The following example sends integer and float inputs to the CopterSim DLL model via the
inSILIntsandinSILFLoatsinterfaces.
Reference example: [RflySim installation path]\RflySimAPIs\4.RflySimModel\0.ApiExps\11.inSILAPI\1.InSILIntsFloats\3.inSILIntsFloats_py
import numpy as np
from DllSimCtrlAPI import DllSimCtrlAPI
dll = DllSimCtrlAPI()
# Send 8 integers; example sets the first value to 5
silInt = np.zeros(8).astype(int).tolist()
silInt[0] = 5
dll.sendSILIntFloat(silInt)
# Send both 8 integers and 20 floats simultaneously
silFloat = np.zeros(20).astype(float).tolist()
silFloat[0] = 5.0
dll.sendSILIntFloat(silInt, silFloat)
Environment and Dependencies¶
- Python Environment:
>= 3.8.10 - Dependencies:
EarthModel,UE4CtrlAPI,UEMapServe,copy,ctrl.IpManager,ctypes,cv2,math,numpy,os,pymavlink,pymavlink.dialects.v20,shutil,socket,struct,sys,threading,time - Prerequisites: Before calling this interface, ensure that RflySimSDK is correctly installed and environment configuration is completed.
Core Interface Description¶
The module DllSimCtrlAPI.py includes configuration variables, helper functions, and core business classes.
Global Constants and Enumerations¶
This section lists all globally accessible constants and enumerations defined in the module.
Standalone Constants¶
None
Global/Standalone Functions¶
None
Data3D Class¶
Stores state data related to 3D UAV simulation, supports parsing and updating various UAV state information from raw data, suitable for managing and maintaining UAV state data in RflySim simulations.
__init__(copter_data=None, CopterID=-1, ClassID=-1)¶
Function Description: Initializes a Data3D object. If raw UAV data is provided, it automatically calls the update method to parse the data; otherwise, all state members are initialized to default values. The stored states include aircraft ID, 3D style, runtime, velocity, position, attitude (Euler angles and quaternions), motor speeds, acceleration, angular velocity, GPS position, and reserved data.
Parameters (Args):
| Parameter Name | Type | Required | Default | Description |
|---|---|---|---|---|
copter_data |
Any |
No | None |
Raw UAV state data; if provided, state will be automatically parsed and updated |
CopterID |
Any |
No | -1 |
UAV's numeric ID |
ClassID |
Any |
No | -1 |
UAV's class ID |
Returns:
Data3Dinstance object
Raises: - None
update(copter_data, CopterID=-1, ClassID=-1)¶
Function Description: Updates all stored UAV state information in the Data3D object based on the provided UAV ID, class ID, and raw data, including runtime, velocity, position, attitude, motor speeds, and other state data.
Parameters (Args):
| Parameter Name | Type | Required | Default | Description |
|---|---|---|---|---|
copter_data |
Any |
Yes | - | Raw UAV state data to be parsed |
CopterID |
Any |
No | -1 |
UAV's numeric ID |
ClassID |
Any |
No | -1 |
UAV's class ID |
Returns:
- None
Raises:
- None
Example:
# Initialize an empty Data3D object
drone_data = Data3D()
# Update state with raw data
drone_data.update(raw_copter_data, CopterID=1, ClassID=0)
updateUdp(UIV)¶
Function Description: Updates UAV state information from UDP-received data. Parameters (Args):
| Parameter Name | Type | Required | Default | Description |
|---|---|---|---|---|
UIV |
Any |
Yes | - | Raw state data received via UDP to be parsed |
Returns:
- None
Raises:
- None
Example:
drone_data = Data3D()
# Update state from received UDP data
udp_packet = receive_udp_data()
drone_data.updateUdp(udp_packet)
DataHIL Class¶
A top-level data management class for Hardware-in-the-Loop (HIL) simulation. Currently, this class does not define additional member methods or class variables and can serve as a base class for data exchange in HIL simulation.
__init__()¶
Function Description: Initializes an instance of the DataHIL class.
Parameters (Args):
None
Returns:
- An instance of the DataHIL class
Exceptions (Raises):
None
DllSimCtrlAPI Class¶
A utility class for communicating with the RflySim simulation environment via UDP broadcast to control drones in the simulation.
__init__(self, CopterID=1, ip="127.0.0.1")¶
Function Description: Initializes a DllSimCtrlAPI object, creates a UDP socket supporting broadcast, and stores the drone ID and target IP address.
Parameters (Args):
| Parameter Name | Type | Default Value | Description |
|---|---|---|---|
| CopterID | Any | 1 | ID of the target drone to be controlled, used to distinguish among multiple drones in the simulation environment |
| ip | Any | "127.0.0.1" | IP address of the server where the simulation environment resides; for local simulation, the loopback address is used by default |
Returns:
None
Exceptions (Raises):
None
fillList(data, inLen)¶
Function Description: This method accepts an array or list and adjusts its length according to the provided inLen parameter. If the data length is insufficient, it pads with zeros; if too long, it truncates. The logic is as follows: if the input is a NumPy array, it is first converted to a Python list; if it is already a list of the desired length, it is returned directly; if it is a list but of mismatched length, it is padded or truncated accordingly; if the input is not a list, a single value is wrapped into a list and padded to the specified length. Finally, the processed data is returned.
Parameters (Args):
| Parameter Name | Type | Required | Default Value | Description |
|---|---|---|---|---|
| data | Any | Yes | None | Input data requiring length adjustment; can be a NumPy array, Python list, or a single numeric value |
| inLen | int | Yes | None | Target length of the output list |
Returns:
A list of length inLen after processing
Exceptions (Raises):
None
sendCustomData(CopterID=0, data=[0] * 16, checksum=123456, port=50000, IP="127.0.0.1")¶
Function Description: Encapsulates the CustomData structure, packs the data, and sends it via UDP socket to the specified IP address and port. The structure contains an integer checksum, an integer aircraft ID, and 16 double-type data. The method automatically adjusts the input data to a length of 16 (padding with zeros if insufficient), then packs it in ii16d format for transmission. Before calling, ensure that the udp_socket object has been created and configured.
Parameters (Args):
| Parameter Name | Type | Required | Default Value | Description |
|---|---|---|---|---|
| CopterID | int | No | 0 | Target aircraft ID |
| data | list | No | [0] * 16 | 16-dimensional data to be sent |
| checksum | int | No | 123456 | Data checksum |
| port | int | No | 50000 | Target UDP port number |
| IP | str | No | 127.0.0.1 | Target IP address |
Returns: None
Raises: None
sendSILIntFloat(inSILInts=[0] * 8, inSILFLoats=[0] * 20, copterID=-1)¶
Function Description: Sends PX4SILIntFloat structure data via UDP to the inSILInts and inSILFloats input interfaces of the DLL model. The structure includes a checksum, aircraft ID, an 8-dimensional integer array, and a 16-dimensional single-precision float array. The method performs length correction on the input data, packs it in 10i20f format, and sends it via port 30100 + (copterID - 1) * 2. If the input copterID is greater than 0, the provided ID is used; otherwise, the object's own CopterID is used. Before calling, ensure that the udp_socket object has been created and configured, and that the self.ip attribute has been set.
Parameters (Args):
| Parameter Name | Type | Required | Default | Description |
|---|---|---|---|---|
| inSILInts | list | No | [0] * 8 | Input 8-dimensional integer data |
| inSILFLoats | list | No | [0] * 20 | Input 20-dimensional single-precision float data |
| copterID | int | No | -1 | Target aircraft ID; if ≤ 0, the object's own CopterID is used |
Returns: None
Raises: None
sendSILIntDouble(inSILInts=[0] * 8, inSILDoubs=[0] * 20, copterID=-1)¶
Function Description: Sends data via UDP to the inDoubCtrls input interface of the DLL model, compatible with an input format of the first 8 dimensions as integers and the last 20 dimensions as doubles, ultimately transmitted as 28-dimensional double-precision data. The structure is DllInDoubCtrls, containing a checksum, aircraft ID, and a 28-dimensional double-precision array. The method performs length correction on the input data, concatenates the integer and double-precision data, packs it in 2i28d format, and sends it via port 30100 + (copterID - 1) * 2. If the input copterID is greater than 0, the provided ID is used; otherwise, the object's own CopterID is used. Before calling, ensure that the udp_socket object has been created and configured, and that the self.ip attribute has been set.
Parameters (Args):
| Parameter Name | Type | Required | Default | Description |
|---|---|---|---|---|
| inSILInts | list | No | [0] * 8 | Input first 8-dimensional integer data |
| inSILDoubs | list | No | [0] * 20 | Input last 20-dimensional double-precision data |
| copterID | int | No | -1 | Target aircraft ID; if ≤ 0, the object's own CopterID is used |
Returns: None
Raises: None
sendInDoubCtrls(inDoubsCtrls=[0] * 28, copterID=-1)¶
Function Description: Sends 28-dimensional double-precision data via UDP to the DLL model's inDoubCtrls input interface. The data structure is DllInDoubCtrls, which includes a checksum, aircraft ID, and a 28-dimensional double-precision array. The method performs length correction on the input data, packs it in 2i28d format, and sends it via port 30100 + (copterID - 1) * 2. If the input copterID is greater than 0, the provided ID is used; otherwise, the object's own CopterID is used. Before calling this method, ensure that the udp_socket object has been created and configured, and that the self.ip attribute has been set.
Arguments (Args):
| Parameter Name | Type | Required | Default | Description |
|---|---|---|---|---|
| inDoubsCtrls | list | No | [0] * 28 | 28-dimensional double-precision input data to be sent |
| copterID | int | No | -1 | Target aircraft ID; if ≤ 0, the object's own CopterID is used |
Returns: None
Raises: None
sendInCtrlExt(inSILInts=[0] * 8, inSILFLoats=[0] * 20, iDxNum=1, copterID=-1)¶
Function Description: Sends data via UDP to a specified interface among the inCtrlExt 1~5 series of the DLL model. The interface index is determined by iDxNum. Input format consists of 8-dimensional integer data and 20-dimensional single-precision float data, which is ultimately converted into 28-dimensional double format for transmission to the DLL. The checksum is 1234567800 + iDxNum. After length correction, the data is packed in 10i20f format and sent via port 30100 + (copterID - 1) * 2. If the input copterID is greater than 0, the provided ID is used; otherwise, the object's own CopterID is used.
Arguments (Args):
| Parameter Name | Type | Required | Default | Description |
|---|---|---|---|---|
| inSILInts | list | No | [0] * 8 | 8-dimensional integer input data |
| inSILFLoats | list | No | [0] * 20 | 20-dimensional single-precision float input data |
| iDxNum | int | No | 1 | Target inCtrlExt interface index (range: 1–5) |
| copterID | int | No | -1 | Target aircraft ID; if ≤ 0, the object's own CopterID is used |
Returns: None
Raises: None
sendInCtrlExtDoub(inDoubsCtrls=[0] * 28, iDxNum=1, copterID=-1, update=True)¶
Function Description: Sends 28-dimensional double-precision data via UDP to a specified interface among the inCtrlExt 1~5 series of the DLL model. The interface index is determined by iDxNum. The checksum is 1234567800 + iDxNum. After length correction, the data is packed in 2i28d format and sent via port 30100 + (copterID - 1) * 2. If the input copterID is greater than 0, the provided ID is used; otherwise, the object's own CopterID is used. Note: The inCtrlExt interface of the DLL model defaults to float type; using this method requires modifying the interface type to double and regenerating the DLL for it to take effect.
Arguments (Args):
| Parameter Name | Type | Required | Default | Description |
|---|---|---|---|---|
| inDoubsCtrls | list | No | [0] * 28 | 28-dimensional double-precision input data to be sent |
| iDxNum | int | No | 1 | Target inCtrlExt interface index (range: 1–5) |
| copterID | int | No | -1 | Target aircraft ID; if ≤ 0, the object's own CopterID is used |
| update | bool | No | True | Whether to immediately update the data; set to True only for the final segment in batch/segmented transmission |
Returns: None
Raises: None
sendInCtrlExtAll(inDoubsCtrls=[0] * 140, copterID=-1)¶
Function Description: Sends data in bulk to all five inCtrlExt 1~5 interfaces of the DLL model, implemented based on sendInCtrlExtDoub. The input data (up to 140 dimensions) is segmented into chunks of 28 elements each, and sequentially transmitted to inCtrlExt 1 through inCtrlExt 5. The update=True flag is set only for the final segment to trigger an immediate update.
Arguments (Args):
| Parameter Name | Type | Required | Default | Description |
|---|---|---|---|---|
| inDoubsCtrls | list | No | [0] * 140 | Total data to be sent; supports up to 5 interfaces × 28 dimensions = 140 dimensions |
| copterID | int | No | -1 | Target aircraft ID; if ≤ 0, the object's own CopterID is used |
Returns: None
Raises: None
sendModelInParams(Bitmask, InParams, copterID=-1)¶
Function Description: Injects parameters into the DLL model's FaultParamAPI.FaultInParams interface via the PX4ModelInParams structure. A 32-bit unsigned bitmask specifies which parameters are active. After length correction, the data is packed in iI32d format and sent via port 30100 + (copterID - 1) * 2. If the input copterID is greater than 0, the provided ID is used; otherwise, the object's own CopterID is used. The checksum is fixed at 1234567891.
Arguments (Args):
| Parameter Name | Type | Required | Default | Description |
|---|---|---|---|---|
| Bitmask | int | Yes | N/A | 32-bit unsigned bitmask indicating which bits in InParams are active (e.g., 0b01 means only the first bit is valid) |
| InParams | list | Yes | N/A | Up to 32-dimensional double-precision parameters to be injected |
| copterID | int | No | -1 | Target aircraft ID; if ≤ 0, the object's own CopterID is used |
Returns: None
Raises: None
sendInitInParams(Bitmask=0, InParams=[0] * 32, copterID=-1)¶
Function Description: Injects initialization parameters into the DLL model's FaultParamAPI.InitInParams interface by packaging them into the PX4ModelInParams structure and sending them. A 32-bit unsigned bitmask specifies which parameters are active; input parameters are length-adjusted and packed in iI32d format, then transmitted via port 30100 + (copterID - 1) * 2. If the input copterID is greater than 0, the provided ID is used; otherwise, the object's own CopterID is used. The fixed checksum is 1234567892.
Parameters (Args):
| Parameter Name | Type | Required | Default | Description |
|---|---|---|---|---|
| Bitmask | int | No | 0 | 32-bit unsigned bitmask indicating which bits in the input parameters are active; e.g., 0b01 means only the first bit is valid |
| InParams | list | No | [0] * 32 | Up to 32-dimensional double-type initialization parameters to be injected |
| copterID | int | No | -1 | Target aircraft ID; if ≤ 0, the object's own CopterID is used |
Return Value (Returns): None
Exceptions (Raises): None
sendDynModiParams(Bitmask=0, InParams=[0] * 64, copterID=-1)¶
Function Description: Injects dynamic modification parameters into the DLL model's FaultParamAPI.DynModiParams interface by packaging them into the PX4DynModiParams structure and sending them. A 32-bit unsigned bitmask specifies which parameters are active; input parameters are length-adjusted and packed in iI64d format, then transmitted via port 30100 + (copterID - 1) * 2. If the input copterID is greater than 0, the provided ID is used; otherwise, the object's own CopterID is used. The fixed checksum is 1234567893.
Parameters (Args):
| Parameter Name | Type | Required | Default | Description |
|---|---|---|---|---|
| Bitmask | int | No | 0 | 32-bit unsigned bitmask indicating which bits in the input parameters are active; e.g., 0b01 means only the first bit is valid |
| InParams | list | No | [0] * 64 | Up to 64-dimensional double-type dynamic modification parameters to be injected |
| copterID | int | No | -1 | Target aircraft ID; if ≤ 0, the object's own CopterID is used |
Return Value (Returns): None
Exceptions (Raises): None
sendColl20d(Coll20d=[0] * 20, copterID=-1)¶
Function Description: This method encapsulates 20-dimensional collision data for the drone and sends it via UDP to the specified simulator port. Based on the provided collision data and drone ID, it packages the data using struct.pack in the format ii20f (two integers followed by twenty floats) before transmission.
Parameters (Args):
| Parameter Name | Type | Required | Default Value | Description |
|---|---|---|---|---|
| Coll20d | List[float] |
No | [0] * 20 | 20-dimensional collision data, length is 20 |
| copterID | int |
No | -1 | Target drone ID; -1 indicates the command applies to all drones |
Return Value (Returns): No return value
Exceptions (Raises): None
sendTerrIn15d(TerrIn15d=[0] * 15, copterID=-1)¶
Function Description: This method encapsulates 15-dimensional terrain data for the drone and sends it via UDP to the specified simulator port. Based on the provided terrain data and drone ID, it packages the data using struct.pack in the format ii15f (two integers followed by fifteen floats) before transmission.
Parameters (Args):
| Parameter Name | Type | Required | Default Value | Description |
|---|---|---|---|---|
| TerrIn15d | List[float] |
No | [0] * 15 | 15-dimensional terrain data, length is 15 |
| copterID | int |
No | -1 | Target drone ID; -1 indicates the command applies to all drones |
Return Value (Returns): No return value
Exceptions (Raises): None
sendDllTakeoff(takeoffHeight=-10)¶
Function Description: Sends a takeoff command to the PX4 simulator, specifying the target takeoff altitude.
Parameters (Args):
| Parameter Name | Type | Required | Default Value | Description |
|---|---|---|---|---|
| takeoffHeight | float |
No | -10 | Target takeoff altitude, in meters |
Return Value (Returns): No return value
Exceptions (Raises): None
sendDllPosNeD(x=0, y=0, z=0, yaw=0)¶
Function Description: Sends position setpoints and desired yaw angle in the North-East-Down (NED) coordinate system to the flight controller for position control.
Parameters (Args):
| Parameter Name | Type | Required | Default Value | Description |
|---|---|---|---|---|
| x | float |
No | 0 | Position along the x-axis (East direction) in the NED coordinate system, in meters |
| y | float |
No | 0 | Position along the y-axis (North direction) in the NED coordinate system, in meters |
| z | float |
No | 0 | Position along the z-axis (Down direction) in the NED coordinate system, in meters |
| yaw | float |
No | 0 | Desired yaw angle, in radians |
Return Value (Returns): No return value
Exceptions (Raises): None
sendDllPosNedNoYaw(x=0, y=0, z=0)¶
Function Description: Sends position setpoints in the North-East-Down (NED) coordinate system to the flight controller without specifying a desired yaw angle, maintaining the current yaw angle, for position control.
Parameters (Args):
| Parameter Name | Type | Required | Default Value | Description |
|---|---|---|---|---|
| x | float |
No | 0 | Position along the x-axis (East direction) in the NED coordinate system, in meters |
| y | float |
No | 0 | Position along the y-axis (North direction) in the NED coordinate system, in meters |
| z | float |
No | 0 | Position along the z-axis (Down direction) in the NED coordinate system, in meters |
Return Value (Returns): No return value
Exceptions (Raises): None
sendDllVelFRD(vx=0, vy=0, vz=0, yawRate=0)¶
Function Description: Sends velocity setpoints and desired yaw rate in the Front-Right-Down (FRD) body-fixed coordinate system to the flight controller for velocity control.
Parameters (Args):
| Parameter Name | Type | Required | Default Value | Description |
|---|---|---|---|---|
| vx | float |
No | 0 | Velocity along the x-axis (Forward direction) in the FRD coordinate system, in m/s |
| vy | float |
No | 0 | Velocity along the y-axis (Right direction) in the FRD coordinate system, in m/s |
| vz | float |
No | 0 | Velocity along the z-axis (Down direction) in the FRD coordinate system, in m/s |
| yawRate | float |
No | 0 | Desired yaw rate, in rad/s |
Return Value (Returns): No return value
Exceptions (Raises): None
sendDllVelNEDNoYaw(vx=0, vy=0, vz=0)¶
Function Description: Sends velocity setpoints in the North-East-Down (NED) coordinate system to the flight controller without specifying a yaw rate, maintaining the current yaw angle, for velocity control.
Parameters (Args):
| Parameter Name | Type | Required | Default Value | Description |
|---|---|---|---|---|
| vx | float |
No | 0 | Velocity along the x-axis (East direction) in the NED coordinate system, in m/s |
| vy | float |
No | 0 | Velocity along the y-axis (North direction) in the NED coordinate system, in m/s |
| vz | float |
No | 0 | Velocity along the z-axis (Down direction) in the NED coordinate system, in m/s |
Return Value (Returns): No return value
Exceptions (Raises): None
RflySimCP Class¶
RflySim Comprehensive Model Control Protocol, defining various parameter constants for the RflySim control communication protocol.
__init__()¶
Function Description: Initializes an instance of the RflySim Comprehensive Model Control Protocol.
Parameters (Args): None
Return Value (Returns): None
Exceptions (Raises): None
IsBitSet(num, bit)¶
Function Description: Checks whether a specified bit is set in the given integer.
Parameters (Args):
| Parameter Name | Type | Required | Default Value | Description |
|---|---|---|---|---|
| num | int | Yes | N/A | Integer to be checked |
| bit | int | Yes | N/A | Specified bit position |
Return Value (Returns): bool: Returns True if the specified bit is set, otherwise returns False.
Exceptions (Raises): None
IsPosSet(num)¶
Function Description: Checks whether position control is enabled.
Parameters (Args):
| Parameter Name | Type | Required | Default | Description |
|---|---|---|---|---|
| num | int | Yes | N/A | Integer to be checked |
Return Value (Returns): bool: Returns True if position control is enabled; otherwise, returns False.
Exceptions (Raises): None
getPosNED(x=0, y=0, z=0, yaw=0)¶
Function Description: Generates a combined position and yaw control command in the North-East-Down (NED) coordinate frame.
Parameters (Args):
| Parameter Name | Type | Required | Default | Description |
|---|---|---|---|---|
| x | float | No | 0 | Position in the North direction (origin of NED frame is the reference point) |
| y | float | No | 0 | Position in the East direction |
| z | float | No | 0 | Position in the Down direction |
| yaw | float | No | 0 | Desired yaw angle in radians (0 rad points North, increases clockwise) |
Return Value (Returns): Packaged control command values
Exceptions (Raises): None
getPosLocal(x=0, y=0, z=0, yaw=0)¶
Function Description: Generates a combined position and yaw control command in the local coordinate frame.
Parameters (Args):
| Parameter Name | Type | Required | Default | Description |
|---|---|---|---|---|
| x | float | No | 0 | Position in the X direction (origin of ENU frame is the takeoff point) |
| y | float | No | 0 | Position in the Y direction |
| z | float | No | 0 | Position in the Down direction |
| yaw | float | No | 0 | Desired yaw angle in radians (0 rad points North, increases clockwise) |
Return Value (Returns): Packaged control command values
Exceptions (Raises): None
getVelNedNoYaw(northvel=0, eastvel=0, downvel=0)¶
Function Description: Generates a velocity control command in the NED coordinate system without yaw rate.
Parameters (Args):
| Parameter Name | Type | Required | Default | Description |
|---|---|---|---|---|
| northvel | float | No | 0 | Velocity in the North direction |
| eastvel | float | No | 0 | Velocity in the East direction |
| downvel | float | No | 0 | Velocity in the Down direction |
Return Value (Returns): Packaged control command values
Exceptions (Raises): None
getVelNED(northvel=0, eastvel=0, downvel=0, yawRate=0)¶
Function Description: Generates a velocity control command in the NED coordinate system with yaw rate.
Parameters (Args):
| Parameter Name | Type | Required | Default | Description |
|---|---|---|---|---|
| northvel | float | No | 0 | Velocity in the North direction |
| eastvel | float | No | 0 | Velocity in the East direction |
| downvel | float | No | 0 | Velocity in the Down direction |
| yawRate | float | No | 0 | Yaw rate |
Return Value (Returns): Packaged control command values
Exceptions (Raises): None
getVelFRD(fwdvel=0, rightvel=0, downvel=0, yawRate=0)¶
Function Description: Generates a velocity control command in the body-fixed FRD coordinate system with yaw rate.
Parameters (Args):
| Parameter Name | Type | Required | Default | Description |
|---|---|---|---|---|
| fwdvel | float | No | 0 | Velocity in the Forward direction |
| rightvel | float | No | 0 | Velocity in the Right direction |
| downvel | float | No | 0 | Velocity in the Down direction |
| yawRate | float | No | 0 | Yaw rate |
Return Value (Returns): Packaged control command values
Exceptions (Raises): None
getAttRPY(roll=0, pitch=0, yaw=0)¶
Function Description: Generates an attitude control command using Roll-Pitch-Yaw angles.
Parameters (Args):
| Parameter Name | Type | Required | Default | Description |
|---|---|---|---|---|
| roll | float | No | 0 | Roll angle |
| pitch | float | No | 0 | Pitch angle |
| yaw | float | No | 0 | Yaw angle |
Return Value (Returns): Packaged control command values
Exceptions (Raises): None
getThrust(roll=0, pitch=0, yaw=0, thrust=0)¶
Function Description: Generates a thrust control command with attitude angles.
Parameters (Args):
| Parameter Name | Type | Required | Default | Description |
|---|---|---|---|---|
| roll | float | No | 0 | Roll angle |
| pitch | float | No | 0 | Pitch angle |
| yaw | float | No | 0 | Yaw angle |
| thrust | float | No | 0 | Thrust value |
Return Value (Returns): Packaged control command values
Exceptions (Raises): None
SendSynAcc(ax, ay, az)¶
Function Description: Synchronously sends a desired acceleration command with no delay.
Parameters (Args):
| Parameter Name | Type | Required | Default | Description | | :--- |
| Parameter Name | Type | Required | Default | Description |
|---|---|---|---|---|
| inDoubsCtrls | list | No | [0] * 28 | 28-dimensional double-precision input data to be sent |
| copterID | int | No | -1 | Target aircraft ID; if ≤ 0, the object's own CopterID is used |
Returns: None
Raises: None
sendInCtrlExt(inSILInts=[0] * 8, inSILFLoats=[0] * 20, iDxNum=1, copterID=-1)¶
Function Description: Sends data via UDP to a specified interface among the inCtrlExt 1~5 series of the DLL model. The interface index is determined by iDxNum. The input format consists of 8-dimensional integer data and 20-dimensional single-precision float data, which is ultimately converted into 28-dimensional double format for transmission to the DLL. The checksum is 1234567800 + iDxNum. After length correction, the data is packed in 10i20f format and sent via port 30100 + (copterID - 1) * 2. If the input copterID is greater than 0, the provided ID is used; otherwise, the object's own CopterID is used.
Parameters (Args):
| Parameter Name | Type | Required | Default | Description |
|---|---|---|---|---|
| inSILInts | list | No | [0] * 8 | 8-dimensional integer input data |
| inSILFLoats | list | No | [0] * 20 | 20-dimensional single-precision float input data |
| iDxNum | int | No | 1 | Target inCtrlExt interface index (range: 1–5) |
| copterID | int | No | -1 | Target aircraft ID; if ≤ 0, the object's own CopterID is used |
Returns: None
Raises: None
sendInCtrlExtDoub(inDoubsCtrls=[0] * 28, iDxNum=1, copterID=-1, update=True)¶
Function Description: Sends 28-dimensional double-precision data via UDP to a specified interface among the inCtrlExt 1~5 series of the DLL model. The interface index is determined by iDxNum. The checksum is 1234567800 + iDxNum. After length correction, the data is packed in 2i28d format and sent via port 30100 + (copterID - 1) * 2. If the input copterID is greater than 0, the provided ID is used; otherwise, the object's own CopterID is used. Note: The inCtrlExt interface of the DLL model defaults to float type; using this method requires modifying the interface type to double and regenerating the DLL for it to take effect.
Parameters (Args):
| Parameter Name | Type | Required | Default | Description |
|---|---|---|---|---|
| inDoubsCtrls | list | No | [0] * 28 | 28-dimensional double-precision input data to be sent |
| iDxNum | int | No | 1 | Target inCtrlExt interface index (range: 1–5) |
| copterID | int | No | -1 | Target aircraft ID; if ≤ 0, the object's own CopterID is used |
| update | bool | No | True | Whether to immediately update the data; set to True only for the final segment in batch/segmented transmission |
Returns: None
Raises: None
sendInCtrlExtAll(inDoubsCtrls=[0] * 140, copterID=-1)¶
Function Description: Sends data in bulk to all five inCtrlExt 1~5 interfaces of the DLL model, implemented based on sendInCtrlExtDoub. The input data (up to 140 dimensions) is segmented into chunks of 28 elements each, and sequentially transmitted to inCtrlExt 1 through inCtrlExt 5. The update=True flag is set only for the final segment to trigger an immediate update.
Parameters (Args):
| Parameter Name | Type | Required | Default | Description |
|---|---|---|---|---|
| inDoubsCtrls | list | No | [0] * 140 | Total data to be sent; supports up to 5 interfaces × 28 dimensions = 140 dimensions |
| copterID | int | No | -1 | Target aircraft ID; if ≤ 0, the object's own CopterID is used |
Returns: None
Raises: None
sendModelInParams(Bitmask, InParams, copterID=-1)¶
Function Description: Injects parameters into the DLL model's FaultParamAPI.FaultInParams interface via the PX4ModelInParams structure. A 32-bit unsigned bitmask specifies which parameters are active. After length correction, the data is packed in iI32d format and sent via port 30100 + (copterID - 1) * 2. If the input copterID is greater than 0, the provided ID is used; otherwise, the object's own CopterID is used. The checksum is fixed at 1234567891.
Parameters (Args):
| Parameter Name | Type | Required | Default | Description |
|---|---|---|---|---|
| Bitmask | int | Yes | N/A | 32-bit unsigned bitmask indicating which bits in InParams are active (e.g., 0b01 means only the first bit is valid) |
| InParams | list | Yes | N/A | Up to 32-dimensional double-precision parameters to be injected |
| copterID | int | No | -1 | Target aircraft ID; if ≤ 0, the object's own CopterID is used |
Returns: None
Raises: None
sendInitInParams(Bitmask=0, InParams=[0] * 32, copterID=-1)¶
Function Description: Injects initialization parameters into the DLL model's FaultParamAPI.InitInParams interface by packaging them into the PX4ModelInParams structure and sending them. A 32-bit unsigned bitmask specifies which parameters are active; input parameters are length-adjusted and packed in iI32d format, then transmitted via port 30100 + (copterID - 1) * 2. If the input copterID is greater than 0, the provided ID is used; otherwise, the object's own CopterID is used. The fixed checksum is 1234567892.
Parameters (Args):
| Parameter Name | Type | Required | Default | Description |
|---|---|---|---|---|
| Bitmask | int | No | 0 | 32-bit unsigned bitmask indicating which bits in the input parameters are active; e.g., 0b01 means only the first bit is valid |
| InParams | list | No | [0] * 32 | Up to 32-dimensional double-type initialization parameters to be injected |
| copterID | int | No | -1 | Target aircraft ID; if ≤ 0, the object's own CopterID is used |
Returns: None
Raises: None
sendDynModiParams(Bitmask=0, InParams=[0] * 64, copterID=-1)¶
Function Description: Injects dynamic modification parameters into the DLL model's FaultParamAPI.DynModiParams interface by packaging them into the PX4DynModiParams structure and sending them. A 64-bit unsigned bitmask specifies which parameters are active; input parameters are length-adjusted and packed in iiQ64d format, then transmitted via port 30100 + (copterID - 1) * 2. If the input copterID is greater than 0, the provided ID is used; otherwise, the object's own CopterID is used. The fixed checksum is 1234567893.
Parameters (Args):
| Parameter Name | Type | Required | Default | Description |
|---|---|---|---|---|
| Bitmask | int | No | 0 | 64-bit unsigned bitmask indicating which bits in the input parameters are active; e.g., 0b01 means only the first bit is valid |
| InParams | list | No | [0] * 64 | Up to 64-dimensional double-type dynamic parameters to be injected |
| copterID | int | No | -1 | Target aircraft ID; if ≤ 0, the object's own CopterID is used |
Returns: None
Raises: None
sendUE2Coptersim(inFromUE=None, copterID=-1)¶
Function Description: Packages data sent from the UE side into a UEToCopterDataD structure based on the drone ID, and sends it to the DLL model via UDP. The structure contains a fixed checksum of 1234567899, the aircraft ID, and 32-dimensional double data, packed in ii32d format for transmission.
Parameters (Args):
| Parameter Name | Type | Required | Default | Description |
|---|---|---|---|---|
| inFromUE | list | No | None | 32-dimensional double data from UE; defaults to generating a 32-dimensional array of all zeros |
| copterID | int | No | -1 | Target aircraft ID; if ≤ 0, the object's own CopterID is used |
Returns: None
Raises: None
InitTrueDataLoop(TargetCopter=-1)¶
Function Description: Initializes a UDP listening loop to receive real data from CopterSim's 30100 series ports.
Parameters (Args):
| Parameter Name | Type | Required | Default | Description |
|---|---|---|---|---|
| TargetCopter | int | No | -1 | Target drone ID to listen to; if ≤ 0, the object's own CopterID is used |
Returns: None
Raises: None
EndTrueDataLoop()¶
Function Description: Ends the real data reception mode and stops the listening loop.
Parameters (Args): None
Returns: None
Raises: None
getTrueDataMsg()¶
Function Description: Starts a loop listening for real data sent from the 30100 series ports and retrieves the real data message.
Parameters (Args): None
Returns: Received real data message
Raises: None
sendFloatsColl(size, velE=[0, 0, 0], ray=[0, 0, 0, 0, 0, 0], posE=[0, 0, 0], copterID=-1)¶
Function Description: This method encapsulates collision-related data for the drone and sends it via UDP to the specified simulator port. Based on the provided parameters, it packages the data using struct.pack in the format ii13f (two integers followed by thirteen floats) before transmission.
Parameters (Args):
| Parameter Name | Type | Required | Default | Description |
|---|---|---|---|---|
| size | None |
No | 0 | Drone collision volume size |
| velE | List[float] |
No | [0, 0, 0] | Velocity of the drone in the East-North-Down coordinate system, length 3 |
| ray | List[float] |
No | [0, 0, 0, 0, 0, 0] | Ray detection distances in six directions (front, back, left, right, up, down), length 6 |
| posE | List[float] |
No | [0, 0, 0] | Position of the drone in the East-North-Down coordinate system, length 3 |
| copterID | int |
No | -1 | Target drone ID; -1 indicates the command applies to all drones |
Returns: None
Raises: None
sendColl20d(Coll20d=[0] * 20, copterID=-1)¶
Function Description: This method encapsulates 20-dimensional collision data for the drone and sends it via UDP to the specified simulator port. Based on the provided collision data and drone ID, it packages the data using struct.pack in the format ii20f (two integers followed by twenty floats) before transmission.
Parameters (Args):
| Parameter Name | Type | Required | Default | Description |
|---|---|---|---|---|
| Coll20d | List[float] |
No | [0] * 20 | 20-dimensional collision data, length is 20 |
| copterID | int |
No | -1 | Target drone ID; -1 indicates the command applies to all drones |
Returns: None
Raises: None
sendTerrIn15d(TerrIn15d=[0] * 15, copterID=-1)¶
Function Description: This method encapsulates 15-dimensional terrain data for the drone and sends it via UDP to the specified simulator port. Based on the provided terrain data and drone ID, it packages the data using struct.pack in the format ii15f (two integers followed by fifteen floats) before transmission.
Parameters (Args):
| Parameter Name | Type | Required | Default | Description |
|---|---|---|---|---|
| TerrIn15d | List[float] |
No | [0] * 15 | 15-dimensional terrain data, length is 15 |
| copterID | int |
No | -1 | Target drone ID; -1 indicates the command applies to all drones |
Return Value (Returns): No return value
Exceptions (Raises): None
sendDllTakeoff(takeoffHeight=-10)¶
Function Description: Sends a takeoff command to the PX4 simulator, specifying the target takeoff altitude.
Parameters (Args):
| Parameter Name | Type | Required | Default | Description |
|---|---|---|---|---|
| takeoffHeight | float |
No | -10 | Target takeoff altitude, in meters |
Return Value (Returns): No return value
Exceptions (Raises): None
sendDllPosNeD(x=0, y=0, z=0, yaw=0)¶
Function Description: Sends position setpoints and desired yaw angle in the North-East-Down (NED) coordinate system to the flight controller for position control.
Parameters (Args):
| Parameter Name | Type | Required | Default | Description |
|---|---|---|---|---|
| x | float |
No | 0 | Position along the x-axis (East direction) in the NED coordinate system, in meters |
| y | float |
No | 0 | Position along the y-axis (North direction) in the NED coordinate system, in meters |
| z | float |
No | 0 | Position along the z-axis (Down direction) in the NED coordinate system, in meters |
| yaw | float |
No | 0 | Desired yaw angle, in radians |
Return Value (Returns): No return value
Exceptions (Raises): None
sendDllPosNedNoYaw(x=0, y=0, z=0)¶
Function Description: Sends position setpoints in the North-East-Down (NED) coordinate system to the flight controller without specifying a desired yaw angle, maintaining the current yaw angle, for position control.
Parameters (Args):
| Parameter Name | Type | Required | Default | Description |
|---|---|---|---|---|
| x | float |
No | 0 | Position along the x-axis (East direction) in the NED coordinate system, in meters |
| y | float |
No | 0 | Position along the y-axis (North direction) in the NED coordinate system, in meters |
| z | float |
No | 0 | Position along the z-axis (Down direction) in the NED coordinate system, in meters |
Return Value (Returns): No return value
Exceptions (Raises): None
sendDllVelFRD(vx=0, vy=0, vz=0, yawRate=0)¶
Function Description: Sends velocity setpoints and desired yaw rate in the Front-Right-Down (FRD) body-fixed coordinate system to the flight controller for velocity control.
Parameters (Args):
| Parameter Name | Type | Required | Default | Description |
|---|---|---|---|---|
| vx | float |
No | 0 | Velocity along the x-axis (Forward direction) in the FRD coordinate system, in m/s |
| vy | float |
No | 0 | Velocity along the y-axis (Right direction) in the FRD coordinate system, in m/s |
| vz | float |
No | 0 | Velocity along the z-axis (Down direction) in the FRD coordinate system, in m/s |
| yawRate | float |
No | 0 | Desired yaw rate, in rad/s |
Return Value (Returns): No return value
Exceptions (Raises): None
sendDllVelNEDNoYaw(vx=0, vy=0, vz=0)¶
Function Description: Sends velocity setpoints in the North-East-Down (NED) coordinate system to the flight controller without specifying a yaw rate, maintaining the current yaw angle, for velocity control.
Parameters (Args):
| Parameter Name | Type | Required | Default | Description |
|---|---|---|---|---|
| vx | float |
No | 0 | Velocity along the x-axis (East direction) in the NED coordinate system, in m/s |
| vy | float |
No | 0 | Velocity along the y-axis (North direction) in the NED coordinate system, in m/s |
| vz | float |
No | 0 | Velocity along the z-axis (Down direction) in the NED coordinate system, in m/s |
Return Value (Returns): No return value
Exceptions (Raises): None
RflySimCP Class¶
RflySim Comprehensive Model Control Protocol, defining various parameter constants for the RflySim control communication protocol.
__init__()¶
Function Description: Initializes an instance of the RflySim Comprehensive Model Control Protocol.
Parameters (Args): None
Return Value (Returns): None
Exceptions (Raises): None
IsBitSet(num, bit)¶
Function Description: Checks whether a specified bit is set in the given integer.
Parameters (Args):
| Parameter Name | Type | Required | Default | Description |
|---|---|---|---|---|
| num | int | Yes | N/A | Integer to be checked |
| bit | int | Yes | N/A | Specified bit position |
Return Value (Returns): bool: Returns True if the specified bit is set, otherwise returns False.
Exceptions (Raises): None
IsPosSet(num)¶
Function Description: Checks whether position control is enabled.
Parameters (Args):
| Parameter Name | Type | Required | Default | Description |
|---|---|---|---|---|
| num | int | Yes | N/A | Integer to be checked |
Return Value (Returns): bool: Returns True if position control is enabled; otherwise, returns False.
Exceptions (Raises): None
getPosNED(x=0, y=0, z=0, yaw=0)¶
Function Description: Generates a combined position and yaw control command in the North-East-Down (NED) coordinate frame.
Parameters (Args):
| Parameter Name | Type | Required | Default | Description |
|---|---|---|---|---|
| x | float | No | 0 | Position in the North direction (origin of NED frame is the reference point) |
| y | float | No | 0 | Position in the East direction |
| z | float | No | 0 | Position in the Down direction |
| yaw | float | No | 0 | Desired yaw angle in radians (0 rad points North, increases clockwise) |
Return Value (Returns): Packaged control command values
Exceptions (Raises): None
getPosLocal(x=0, y=0, z=0, yaw=0)¶
Function Description: Generates a combined position and yaw control command in the local coordinate frame.
Parameters (Args):
| Parameter Name | Type | Required | Default | Description |
|---|---|---|---|---|
| x | float | No | 0 | Position in the X direction (origin of ENU frame is the takeoff point) |
| y | float | No | 0 | Position in the Y direction |
| z | float | No | 0 | Position in the Down direction |
| yaw | float | No | 0 | Desired yaw angle in radians (0 rad points North, increases clockwise) |
Return Value (Returns): Packaged control command values
Exceptions (Raises): None
getVelNedNoYaw(northvel=0, eastvel=0, downvel=0)¶
Function Description: Generates a desired velocity control command in the North-East-Down (NED) coordinate frame without specifying yaw, maintaining the current yaw.
Parameters (Args):
| Parameter Name | Type | Required | Default | Description |
|---|---|---|---|---|
| northvel | float | No | 0 | Desired velocity in the North direction |
| eastvel | float | No | 0 | Desired velocity in the East direction |
| downvel | float | No | 0 | Desired velocity in the Down direction |
Return Value (Returns): Packaged control command values
Exceptions (Raises): None
getVelNED(vx=0, vy=0, vz=0, yawRate=0)¶
Function Description: Generates a combined desired velocity and yaw rate control command in the North-East-Down (NED) coordinate frame.
Parameters (Args):
| Parameter Name | Type | Required | Default | Description |
|---|---|---|---|---|
| vx | float | No | 0 | Desired velocity in the North direction |
| vy | float | No | 0 | Desired velocity in the East direction |
| vz | float | No | 0 | Desired velocity in the Down direction |
| yawRate | float | No | 0 | Desired yaw rate |
Return Value (Returns): Packaged control command values
Exceptions (Raises): None
getVelFRD(vx=0, vy=0, vz=0, yawRate=0)¶
Function Description: Generates a combined desired velocity and yaw rate control command in the Front-Right-Down (FRD) body-fixed coordinate frame.
Parameters (Args):
| Parameter Name | Type | Required | Default | Description |
|---|---|---|---|---|
| vx | float | No | 0 | Desired velocity in the Forward direction (body FRD frame) |
| vy | float | No | 0 | Desired velocity in the Right direction |
| vz | float | No | 0 | Desired velocity in the Down direction |
| yawRate | float | No | 0 | Desired yaw rate |
Return Value (Returns): Packaged control command values
Exceptions (Raises): None
SendSynAcc(ax, ay, az)¶
Function Description: Synchronously sends a desired acceleration command with no delay.
Parameters (Args):
| Parameter Name | Type | Required | Default | Description | | :--- | :---: | :--- | :--- | | ax | float | Yes | None | Desired acceleration in the X direction | | ay | float | Yes | None | Desired acceleration in the Y direction | | az | float | Yes | None | Desired acceleration in the Z direction |
Return Value (Returns): None
Exceptions (Raises): None
SendSynFull(x, y, z, vx, vy, vz, ax, ay, az, yawRate)¶
Function Description: Synchronously sends a complete command containing desired position, velocity, acceleration, and yaw rate with no delay.
Parameters (Args):
| Parameter Name | Type | Required | Default | Description | | :--- | :---: | :--- | :--- | | x | float | Yes | None | Desired position X component | | y | float | Yes | None | Desired position Y component | | z | float | Yes | None | Desired position Z component | | vx | float | Yes | None | Desired velocity X component | | vy | float | Yes | None | Desired velocity Y component | | vz | float | Yes | None | Desired velocity Z component | | ax | float | Yes | None | Desired acceleration X component | | ay | float | Yes | None | Desired acceleration Y component | | az | float | Yes | None | Desired acceleration Z component | | yawRate | float | Yes | None | Desired yaw rate |
Return Value (Returns): None
Exceptions (Raises): None
SendSynAttThrust(roll, pitch, yaw, thrust)¶
Function Description: Synchronously sends a desired attitude and total thrust command with no delay.
Parameters (Args):
| Parameter Name | Type | Required | Default | Description |
|---|---|---|---|---|
| roll | float | Yes | None | Desired roll angle, in radians |
| pitch | float | Yes | None | Desired pitch angle, in radians |
| yaw | float | Yes | None | Desired yaw angle, in radians |
| thrust | float | Yes | None | Desired total thrust |
Return Value (Returns): None
Exceptions (Raises): None
SendSynAtt(roll, pitch, yaw)¶
Function Description: Synchronously sends a desired attitude command with no delay.
Parameters (Args):
| Parameter Name | Type | Required | Default | Description |
|---|---|---|---|---|
| roll | float | Yes | None | Desired roll angle, in radians |
| pitch | float | Yes | None | Desired pitch angle, in radians |
| yaw | float | Yes | None | Desired yaw angle, in radians |
Return Value (Returns): None
Exceptions (Raises): None
| Parameter Name | Type | Required | Default | Description |
|---|---|---|---|---|
| roll | float | Yes | N/A | Desired roll angle, in radians |
| pitch | float | Yes | N/A | Desired pitch angle, in radians |
| yaw | float | Yes | N/A | Desired yaw angle, in radians |
Return Value (Returns): None
Exceptions (Raises): None
TakeoffSyn(height)¶
Function Description: Synchronously sends a takeoff command with no delay, ascending to the specified height.
Parameters (Args):
| Parameter Name | Type | Required | Default | Description |
|---|---|---|---|---|
| height | float | Yes | N/A | Target takeoff height |
Return Value (Returns): None
Exceptions (Raises): None
ReturnHomeSyn(height)¶
Function Description: Synchronously sends a return-to-home command with no delay; first flies to the home point while maintaining the specified altitude.
Parameters (Args):
| Parameter Name | Type | Required | Default | Description |
|---|---|---|---|---|
| height | float | Yes | N/A | Flight altitude maintained during the return process |
Return Value (Returns): None
Exceptions (Raises): None
LandSyn(height=0)¶
Function Description: Synchronously sends a landing command with no delay, descending to the specified height.
Parameters (Args):
| Parameter Name | Type | Required | Default | Description |
|---|---|---|---|---|
| height | float | No | 0 | Target landing height |
Return Value (Returns): None
Exceptions (Raises): None
SendPosSpeedFWSyn(x, y, z, speed)¶
Function Description: Synchronously sends position and velocity commands for the fixed-wing integrated model, specifying both desired position and desired flight speed, with no command delay.
Parameters (Args):
| Parameter Name | Type | Required | Default | Description |
|---|---|---|---|---|
| x | float | Yes | N/A | Desired X-coordinate of position |
| y | float | Yes | N/A | Desired Y-coordinate of position |
| z | float | Yes | N/A | Desired Z-coordinate of position |
| speed | float | Yes | N/A | Desired flight speed magnitude |
Return Value (Returns): None
Exceptions (Raises): None
ResetSynCmd()¶
Function Description: Resets the state of the synchronous command.
Parameters (Args): No arguments
Return Value (Returns): None
Exceptions (Raises): None
ModelLoad Class¶
A utility class for loading custom aircraft models into the RflySim simulation environment.
__init__(dll_name, CopterID=1, ClassID=-1, MapName="Grasslands", ip="127.0.0.1", LocX=0, LocY=0, Yaw=0, UdpMode=0, useGPS=False, GpsOrin=[0, 0, 0])¶
Function Description: Constructs a model loading object, connects to the simulation environment, and loads the specified aircraft model at the designated location.
Parameters (Args):
| Parameter Name | Type | Default | Description |
|---|---|---|---|
| dll_name | - | None | Filename of the dynamic-link library (DLL) for the model to be loaded |
| CopterID | - | 1 | ID number assigned to the loaded aircraft, used to distinguish between multiple aircraft in multi-vehicle scenarios |
| ClassID | - | -1 | Aircraft class ID; -1 indicates automatic assignment |
| MapName | - | "Grasslands" | Name of the target simulation scene |
| ip | - | "127.0.0.1" | IP address where the simulation service is running |
| LocX | - | 0 | Initial X-coordinate (east direction) in the local East-North-Up (ENU) coordinate system, in meters |
| LocY | - | 0 | Initial Y-coordinate (north direction) in the local East-North-Up (ENU) coordinate system, in meters |
| Yaw | - | 0 | Initial yaw angle of the model, in degrees |
| UdpMode | - | 0 | UDP communication mode; 0 indicates the default mode |
| useGPS | - | False | Whether to enable GPS simulation for this model |
| GpsOrin | - | [0, 0, 0] | Offset of the GPS sensor relative to the body frame origin, in the order of forward/backward, left/right, up/down |
Return Value (Returns): None
Exceptions (Raises): None
CreateVehicle(CopterID=1, ClassID=-1, MapName="Grasslands", ip="127.0.0.1", LocX=0, LocY=0, Yaw=0, UdpMode=0, useGPS=False, GpsOrin=[0, 0, 0])¶
Function Description: Creates a UAV vehicle in the 3D simulation scene.
Parameters (Args):
| Parameter Name | Type | Required | Default Value | Description |
|---|---|---|---|---|
| CopterID | Any | No | 1 | Drone ID number |
| ClassID | Any | No | -1 | Drone model ID; -1 indicates the default model |
| MapName | Any | No | Grasslands | Name of the loaded scene map |
| ip | Any | No | 127.0.0.1 | IP address for connecting to the simulation service |
| LocX | Any | No | 0 | Initial X-coordinate of the drone |
| LocY | Any | No | 0 | Initial Y-coordinate of the drone |
| Yaw | Any | No | 0 | Initial yaw angle of the drone |
| UdpMode | Any | No | 0 | UDP communication mode; 0 indicates the default mode |
| useGPS | Any | No | False | Whether to enable GPS simulation |
| GpsOrin | Any | No | [0, 0, 0] | Initial GPS offset |
Return Value (Returns): None
Exceptions (Raises): None
Updata3Doutput()¶
Function Description: Updates output data for the 3D scene
Parameters (Args): No parameters
Return Value (Returns): None
Exceptions (Raises): None
SendUpdate3DMap(isSetSpeed=False)¶
Function Description: Sends map update information to the 3D simulation scene; optionally sets the simulation speed
Parameters (Args):
| Parameter Name | Type | Required | Default Value | Description |
|---|---|---|---|---|
| isSetSpeed | Any | No | False | Whether to update and set the simulation run speed |
Return Value (Returns): None
Exceptions (Raises): None
get3DDataBuf()¶
Function Description: Retrieves the 3D scene data buffer
Parameters (Args): No parameters
Return Value (Returns): 3D scene data buffer object
Exceptions (Raises): None
Send3DData()¶
Function Description: Sends 3D scene data to the simulation service
Parameters (Args): No parameters
Return Value (Returns): None
Exceptions (Raises): None
SendSimData()¶
Function Description: Sends simulation data to the flight controller
Parameters (Args): No parameters
Return Value (Returns): None
Exceptions (Raises): None
SendHILData()¶
Function Description: Sends Hardware-in-the-Loop (HIL) simulation data
Parameters (Args): No parameters
Return Value (Returns): None
Exceptions (Raises): None
SendOutCopter()¶
Function Description: Sends drone status data output
Parameters (Args): No parameters
Return Value (Returns): None
Exceptions (Raises): None
fillList(data, inLen, fill=0)¶
Function Description: Pads a list to a specified length using a specified value
Parameters (Args):
| Parameter Name | Type | Required | Default Value | Description |
|---|---|---|---|---|
| data | Any | Yes | None | Original list to be padded |
| inLen | Any | Yes | None | Target length after padding |
| fill | Any | No | 0 | Element value used for padding |
Return Value (Returns): List after padding
Exceptions (Raises): None
StartAutUpdate(UpdateFreq=30, speed=-1)¶
Function Description: Starts the automatic update thread for the 3D scene
Parameters (Args):
| Parameter Name | Type | Required | Default Value | Description |
|---|---|---|---|---|
| UpdateFreq | Any | No | 30 | Automatic update frequency, in Hz |
| speed | Any | No | -1 | Simulation run speed multiplier; -1 means not modifying the original speed |
Return Value (Returns): None
Exceptions (Raises): None
StopAutUpdate()¶
Function Description: Stops the automatic update thread for the 3D scene
Parameters (Args): No parameters
Return Value (Returns): None
Exceptions (Raises): None
AutUpdateLoop()¶
Function Description: Loop execution function for automatic updates, called by the thread
Parameters (Args): No parameters
Return Value (Returns): None
Exceptions (Raises): None
StartExtCtrl()¶
Function Description: Starts the external control receiving thread
Parameters (Args): No parameters
Return Value (Returns): None
Exceptions (Raises): None
StopExtCtrl()¶
Function Description: Stops the external control receiving thread
Parameters (Args): No parameters
Return Value (Returns): None
Exceptions (Raises): None
Recv20100Loop()¶
Function Description: Data receiving loop function for port 20100, called by the receiving thread
Parameters (Args): No parameters
Return Value (Returns): None
Exceptions (Raises): None
Recv30100Loop()¶
Function Description: None
Parameters (Args): No parameters
Return Value (Returns): None
Exceptions (Raises): None
DllDestroyModel()¶
Function Description: Destroys the model
Parameters (Args): No parameters
Return Value (Returns): None
Exceptions (Raises): None
DllReInitModel()¶
Function Description: Initializes the model
Parameters (Args): No parameters
Return Value (Returns): None
Exceptions (Raises): None
DllInputSILs(in_ints, in_floats)¶
Function Description: Inputs SIL data
Parameters (Args):
| Parameter Name | Type | Required | Default Value | Description |
|---|---|---|---|---|
| in_ints | None | No | [0] * 8 |
Input integer SIL data |
| in_floats | None | No | [0] * 20 |
Input floating-point SIL data |
Return Value (Returns): None
Exceptions (Raises): None
DllInputColls(in_floats_collision)¶
Function Description: Inputs collision data
Parameters (Args):
| Parameter Name | Type | Required | Default Value | Description |
|---|---|---|---|---|
| in_floats_collision | None | No | [0] * 20 |
Collision input floating-point data |
Return Value (Returns): None
Exceptions (Raises): None
DllTerrainIn15d(terrain15d)¶
Function Description: Inputs terrain height data
Parameters (Args):
| Parameter Name | Type | Required | Default Value | Description |
|---|---|---|---|---|
| terrain15d | None | No | [0] * 15 |
15-dimensional terrain height data |
Return Value (Returns): None
Exceptions (Raises): None
| Parameter Name | Type | Required | Default Value | Description |
|---|---|---|---|---|
| terrain15d | None | No | [0] * 15 |
15-dimensional terrain height data |
Return Value (Returns): None
Exceptions (Raises): None
DllInitGpsPos(gps)¶
Function Description: Inputs the origin coordinates of the GPS position
Parameters (Args):
| Parameter Name | Type | Required | Default Value | Description |
|---|---|---|---|---|
| gps | None | No | [0] * 3 |
GPS origin latitude, longitude, and altitude data |
Return Value (Returns): None
Exceptions (Raises): None
DllInitPosAngState(init_pos_offset, init_ang_offset)¶
Function Description: Initializes position and attitude angle states
Parameters (Args):
| Parameter Name | Type | Required | Default Value | Description |
|---|---|---|---|---|
| init_pos_offset | None | No | [0, 0, 0] |
Initial position offset |
| init_ang_offset | None | No | [0, 0, 0] |
Initial attitude angle offset |
Return Value (Returns): None
Exceptions (Raises): None
DllInputDoubCtrls(in_doub_ctrls)¶
Function Description: Inputs control command data
Parameters (Args):
| Parameter Name | Type | Required | Default Value | Description |
|---|---|---|---|---|
| in_doub_ctrls | None | No | [0] * 28 |
28-dimensional double-precision control command data |
Return Value (Returns): None
Exceptions (Raises): None
DllinSIL28d(in_doub_ctrls)¶
Function Description: Inputs control command data
Parameters (Args):
| Parameter Name | Type | Required | Default Value | Description |
|---|---|---|---|---|
| in_doub_ctrls | None | No | [0] * 28 |
28-dimensional double-precision control command data |
Return Value (Returns): None
Exceptions (Raises): None
DllInCtrlExt(in_ctrl_ext)¶
Function Description: Inputs fault injection data
Parameters (Args):
| Parameter Name | Type | Required | Default Value | Description |
|---|---|---|---|---|
| in_ctrl_ext | None | No | [0] * 140 |
140-dimensional extended control fault injection data |
Return Value (Returns): None
Exceptions (Raises): None
DllInFromUE(in_from_ue)¶
Function Description: Inputs UE data into the DLL
Parameters (Args):
| Parameter Name | Type | Required | Default Value | Description |
|---|---|---|---|---|
| in_from_ue | None | No | [0] * 32 |
32-dimensional input data from UE |
Return Value (Returns): None
Exceptions (Raises): None
DllInputColls(inCll)¶
Function Description: Inputs collision data into the DLL
Parameters (Args):
| Parameter Name | Type | Required | Default Value | Description |
|---|---|---|---|---|
| inCll | None | No | [0] * 20 |
20-dimensional collision input data |
Return Value (Returns): None
Exceptions (Raises): None
DllGetStep0()¶
Function Description: Retrieves the simulation step size
Parameters (Args): None
Return Value (Returns): Simulation step size value
Exceptions (Raises): None
Dllstep()¶
Function Description: Executes one simulation step
Parameters (Args): None
Return Value (Returns): None
Exceptions (Raises): None
ModelUpdate(step_time)¶
Function Description: Executes simulation for step_time seconds
Parameters (Args):
| Parameter Name | Type | Required | Default Value | Description |
|---|---|---|---|---|
| step_time | None | Yes | N/A | Simulation duration to advance, in seconds |
Return Value (Returns): None
Exceptions (Raises): None
DlloutVehileInfo60d()¶
Function Description: Exports 60-dimensional vehicle information data
Parameters (Args): None
Return Value (Returns): None
Exceptions (Raises): None
DllOutCopterData()¶
Function Description: Exports simulation data for multi-rotor aircraft
Parameters (Args): None
Return Value (Returns): None
Exceptions (Raises): None
SendPosNED(x=0, y=0, z=0, yaw=0)¶
Function Description: Sends position and yaw angle commands in the NED coordinate system
Parameters (Args):
| Parameter Name | Type | Required | Default Value | Description |
|---|---|---|---|---|
| x | None | No | 0 | Position coordinate in the North direction in the NED coordinate system |
| y | None | No | 0 | Position coordinate in the East direction in the NED coordinate system |
| z | None | No | 0 | Position coordinate in the Down direction in the NED coordinate system |
| yaw | None | No | 0 | Yaw angle |
Return Value (Returns): None
Exceptions (Raises): None
SendPosLocal(x=0, y=0, z=0, yaw=0)¶
Function Description: Sends position and yaw angle commands in the local coordinate system
Parameters (Args):
| Parameter Name | Type | Required | Default Value | Description |
|---|---|---|---|---|
| x | None | No | 0 | Position coordinate in the x-direction in the local coordinate system |
| y | None | No | 0 | Position coordinate in the y-direction in the local coordinate system |
| z | None | No | 0 | Position coordinate in the z-direction in the local coordinate system |
| yaw | None | No | 0 | Yaw angle |
Return Value (Returns): None
Exceptions (Raises): None
SendVelNED(vx=0, vy=0, vz=0, yawRate=0)¶
Function Description: Sends velocity and yaw rate commands in the NED coordinate system
Parameters (Args):
| Parameter Name | Type | Required | Default Value | Description |
|---|---|---|---|---|
| vx | None | No | 0 | Velocity in the North direction in the NED coordinate system |
| vy | None | No | 0 | Velocity in the East direction in the NED coordinate system |
| vz | None | No | 0 | Velocity in the Down direction in the NED coordinate system |
| yawRate | None | No | 0 | Yaw rate |
Return Value (Returns): None
Exceptions (Raises): None
SendVelFRD(vx=0, vy=0, vz=0, yawRate=0)¶
Function Description: Sends velocity and yaw rate commands in the body-fixed FRD coordinate system
Parameters (Args):
| Parameter Name | Type | Required | Default Value | Description |
|---|---|---|---|---|
| vx | None | No | 0 | Velocity in the Forward direction in the FRD coordinate system |
| vy | None | No | 0 | Velocity in the Right direction in the FRD coordinate system |
| vz | None | No | 0 | Velocity in the Down direction in the FRD coordinate system |
| yawRate | None | No | 0 | Yaw rate |
Return Value (Returns): None
Exceptions (Raises): None
SendVelNEDNoYaw(northvel=0, eastvel=0, downvel=0)¶
Function Description: Sends velocity commands in the NED coordinate system (without yaw rate)
Parameters (Args):
| Parameter Name | Type | Required | Default Value | Description |
|---|---|---|---|---|
| northvel | None | No | 0 | Velocity in the North direction in the NED coordinate system |
| eastvel | None | No | 0 | Velocity in the East direction in the NED coordinate system |
| downvel | None | No | 0 | Velocity in the Down direction in the NED coordinate system |
Return Value (Returns): None
Exceptions (Raises): None
MultiCopterDll Class¶
Multi-rotor UAV simulation model loading class, used to load multi-rotor UAV models in the RflySim simulation environment and complete simulation initialization configuration.
__init__(CopterID=1, ClassID=-1, MapName="Grasslands", ip="127.0.0.1", LocX=0, LocY=0, Yaw=0, UdpMode=0, useGPS=False, GpsOrin=[0, 0, 0])¶
Function Description: Initializes a multi-rotor UAV model instance, loads the UAV model in the simulation environment, and configures basic parameters
Parameters (Args):
| Parameter Name | Type | Required | Default Value | Description |
|---|---|---|---|---|
CopterID |
int |
No | 1 |
ID number of the multi-rotor UAV, used to distinguish different UAVs in the same simulation environment |
ClassID |
int |
No | -1 |
UAV class ID, -1 indicates using the default class configuration |
MapName |
str |
No | "Grasslands" |
Name of the map used in the simulation environment, defaults to the Grasslands map |
ip |
str |
No | "127.0.0.1" |
IP address for connecting to the simulation service, defaults to the local loopback address for local simulation |
LocX |
float |
No | 0 |
East coordinate (X-axis) of the UAV's initial position |
LocY |
float |
No | 0 |
North coordinate (Y-axis) of the UAV's initial position |
Yaw |
float |
No | 0 |
Initial yaw angle of the UAV, in degrees |
UdpMode |
int |
No | 0 |
UDP communication mode configuration, 0 is the default mode; different modes can be selected based on communication requirements |
useGPS |
bool |
No | False |
Whether to enable GPS simulation, True to enable, False to disable |
GpsOrin |
list[float] |
No | [0, 0, 0] |
Offset of the GPS sensor relative to the UAV body frame, format is [x, y, z] |
Return Value (Returns):
MultiCopterDllinstance object
Exceptions (Raises): None
Example:
from RflySimSDK.ctrl import MultiCopterDll
# Load multi-rotor UAV with ID 1, enable GPS, initial position at origin
copter = MultiCopterDll(CopterID=1, useGPS=True, LocX=0, LocY=0)
Advanced Usage Examples¶
The following example directly loads a multi-rotor DLL model without PX4, creates a vehicle, starts a 30 Hz automatic update, and then sequentially sends position, NED velocity, and FRD velocity commands.
Reference example: [RflySim installation path]\RflySimAPIs\4.RflySimModel\0.ApiExps\12.DllModelImport\1.ModelLoadApi
import math
import time
import DllSimCtrlAPI
dll = DllSimCtrlAPI.ModelLoad("MulticopterNOpx4.dll")
dll.CreateVehicle(
CopterID=1,
ClassID=-1,
MapName="Grasslands",
ip="127.0.0.1",
LocX=0,
LocY=0,
Yaw=0,
UdpMode=0,
useGPS=False,
GpsOrin=[0, 0, 0],
)
dll.StartAutUpdate(UpdateFreq=30, speed=1)
dll.SendPosNED(0, 0, -10)
time.sleep(10)
dll.SendPosNED(0, 0, -10, math.pi / 4)
time.sleep(5)
dll.SendVelNED(2, 0, 0)
time.sleep(5)
dll.SendVelFRD(2, 0, 0)
Notes and Pitfall Avoidance Guide¶
- Parameter Initialization Prerequisite: Before calling any control command transmission method of the
DllSimCtrlAPIclass, thefillListmethod must be invoked first to initialize the parameter list; otherwise, empty data will be sent, causing simulation anomalies. - 3D Visualization Update Timing: To enable automatic 3D scene updates,
ModelLoad.StartAutUpdatemust be called. If custom asynchronous updates are used, avoid repeatedly calling bothSend3DDataandStartAutUpdate, as this may result in duplicate data transmission and cause screen lag. - Prerequisite for Pose State Reading: Before invoking state-reading methods such as
getPosNEDandgetVelNEDof theRflySimCPclass, ensure that simulation data synchronization has been completed; otherwise, erroneous zero-valued state data will be returned. - Memory Management for Batch Operations: After batch-creating multiple UAVs, if the simulation needs to be reloaded, existing instance objects must be cleared and
fillListmust be called again; otherwise, residual old parameters may mix into new control commands, leading to control errors.
Changelog¶
2026-03-03: feat: SDK adds IP handling mechanism for compatibility with cloud deployment of the local version2025-12-05: feat: 1. Added NED position and velocity setting interfaces for integrated models; 2. Added asynchronous command execution and message buffer size configuration fordistSimCtrlAPI2024-09-12: feat: Added interface for sending relative positions2024-09-12: feat: AddedSendVelFRDinterface2024-09-06: fix: Added call relationship diagram on API page2024-09-06: fix: Updated API2024-08-31: fix: Updated DLL control library2024-07-26: fix: Updated API homepage2024-07-24: fix: Refactored DLL model-related function descriptions and introductions2024-07-23: fix: Fixed bugs2024-07-22: fix: Fixed broken interfaces2024-06-18: fix: Adjusted API formatting2024-06-12: fix: Updated interface comments2024-06-05: fix: Updated doxygen-generated documentation2024-06-05: fix: Updated comments forDLLSimCtrlAPI