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¶
Minimal working example: copy and modify only the minimal required configuration to run. Ensure that RflySim SDK is correctly installed and the PX4 flight controller has been started.
from RflySimSDK.ctrl.DllSimCtrlAPI import ModelLoad
import time
# 1. Initialize the model loading object, load the simulation control interface, use the default grassland map, local IP, and the first UAV
sim_ctrl = ModelLoad(
dll_name=None, # Use the built-in simulation DLL by default
CopterID=1, # UAV ID, default is 1
MapName="Grasslands", # Use the default grassland map
ip="127.0.0.1" # Local simulation address
)
# 2. Create a UAV, default initial position (0, 0), initial yaw 0 degrees, no GPS
sim_ctrl.CreateVehicle(
CopterID=1,
useGPS=False
)
# 3. Start the simulation loop, periodically updating the 3D simulation view
for i in range(100):
# Update UAV state output
sim_ctrl.Updata3Doutput()
# Send update information to the 3D visualization interface
sim_ctrl.SendUpdate3DMap()
# Control simulation frame rate, approximately 50Hz
time.sleep(0.02)
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 includes an integer checksum, an integer drone ID, and 16 double-precision floating-point values. This method automatically adjusts the input data to a length of 16 (padding with zeros if necessary), then packs and sends it using the `ii16d` format. Ensure that the `udp_socket` object has been created and configured before calling this method.
**Parameters (Args)**:
| Parameter Name | Type | Required | Default Value | Description |
| :------------- | :--- | :------: | :------------ | :---------- |
| CopterID | int | No | 0 | Target drone 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
**Exceptions (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, drone ID, an 8-dimensional integer array, and a 16-dimensional single-precision float array. This method corrects the input data lengths, concatenates them, and packs them using the `10i20f` format before sending via port `30100 + (copterID - 1) * 2`. If the input `copterID` is greater than 0, it is used; otherwise, the object's own `CopterID` is used. Ensure that the `udp_socket` object has been created and configured, and that the `self.ip` attribute has been set before calling this method.
**Parameters (Args)**:
| Parameter Name | Type | Required | Default Value | Description |
| :------------- | :--- | :------: | :------------ | :---------- |
| inSILInts | list | No | [0] * 8 | 8-dimensional integer input data |
| inSILFLoats | list | No | [0] * 20 | 20-dimensional single-precision float input data |
| copterID | int | No | -1 | Target drone ID; if ≤ 0, the object's own `CopterID` is used |
**Returns**:
None
**Exceptions (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 8 integers followed by 20 double-precision floats, ultimately sending as a 28-dimensional double-precision array. The structure is `DllInDoubCtrls`, containing a checksum, drone ID, and a 28-dimensional double-precision array. This method corrects the input data lengths, concatenates the integer and double-precision data, and packs them using the `2i28d` format before sending via port `30100 + (copterID - 1) * 2`. If the input `copterID` is greater than 0, it is used; otherwise, the object's own `CopterID` is used. Ensure that the `udp_socket` object has been created and configured, and that the `self.ip` attribute has been set before calling this method.
**Parameters (Args)**:
| Parameter Name | Type | Required | Default Value | Description |
| :------------- | :--- | :------: | :------------ | :---------- |
| inSILInts | list | No | [0] * 8 | First 8-dimensional integer input data |
| inSILDoubs | list | No | [0] * 20 | Next 20-dimensional double-precision input data |
| copterID | int | No | -1 | Target drone ID; if ≤ 0, the object's own `CopterID` is used |
**Returns**:
None
**Exceptions (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 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 |
**Return Value (Returns)**: None
**Exceptions (Raises)**: None
---
#### `sendUE2Coptersim(inFromUE=None, copterID=-1)`
**Function Description**: Packages data received from UE into the `UEToCopterDataD` structure based on the UAV ID and sends it via UDP to the DLL model. The structure includes a fixed checksum of 1234567899, the aircraft ID, and 32-dimensional double data, packed in `ii32d` format and transmitted.
**Parameters (Args)**:
| Parameter Name | Type | Required | Default | Description |
| :--- | :--- | :---: | :--- | :--- |
| inFromUE | list | No | None | 32-dimensional double data sent from UE; defaults to a 32-dimensional zero vector |
| copterID | int | No | -1 | Target aircraft ID; if ≤ 0, the object's own `CopterID` is used |
**Return Value (Returns)**: None
**Exceptions (Raises)**: None
---
#### `InitTrueDataLoop(TargetCopter=-1)`
**Function Description**: Initializes a UDP listening loop to receive real-time data from CopterSim's 30100-series ports.
**Parameters (Args)**:
| Parameter Name | Type | Required | Default | Description |
| :--- | :--- | :---: | :--- | :--- |
| TargetCopter | int | No | -1 | Target UAV ID to listen for; if ≤ 0, the object's own `CopterID` is used |
**Return Value (Returns)**: None
**Exceptions (Raises)**: None
---
#### `EndTrueDataLoop()`
**Function Description**: Terminates the real-data reception mode and stops the listening loop.
**Parameters (Args)**: None
**Return Value (Returns)**: None
**Exceptions (Raises)**: None
---
#### `getTrueDataMsg()`
**Function Description**: Starts a listening loop to receive real-time data from the 30100-series ports and retrieves the received real data message.
**Parameters (Args)**: None
**Return Value (Returns)**: Received real data message
**Exceptions (Raises)**: None
---
#### `sendFloatsColl(size, velE=[0, 0, 0], ray=[0, 0, 0, 0, 0, 0], posE=[0, 0, 0], copterID=-1)`
**Function Description**: Encapsulates collision-related data for the UAV and sends it via UDP to the specified simulator port. After packaging the data based on the provided parameters, it uses `struct.pack` to format the data in `ii13f` (two integers and thirteen floats) and transmits it.
**Parameters (Args)**:
| Parameter Name | Type | Required | Default | Description |
| :--- | :--- | :---: | :--- | :--- |
| size | `None` | No | 0 | UAV collision volume size |
| velE | `List[float]` | No | [0, 0, 0] | Velocity in the East-North-Down (E-N-D) coordinate system; length = 3 |
| ray | `List[float]` | No | [0, 0, 0, 0, 0, 0] | Ray detection distances for six directions (front, back, left, right, up, down); length = 6 |
| posE | `List[float]` | No | [0, 0, 0] | Position in the East-North-Down (E-N-D) coordinate system; length = 3 |
| copterID | `int` | No | -1 | Target UAV ID; -1 indicates the command applies to all UAVs |
**Return Value (Returns)**: None
**Exceptions (Raises)**: None
---
#### `sendColl20d(Coll20d=[0] * 20, copterID=-1)`
**Function Description**: Encapsulates 20-dimensional collision data for the UAV and sends it via UDP to the specified simulator port. After packaging the data based on the provided collision data and UAV ID, it uses `struct.pack` to format the data in `ii20f` (two integers and twenty floats) and transmits it.
**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 |
**Returns**: No return value
**Raises**: No exceptions
---
#### `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.
**Arguments**:
| 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 |
**Returns**: No return value
**Raises**: No exceptions
---
#### `sendDllTakeoff(takeoffHeight=-10)`
**Function Description**: Sends a takeoff command to the PX4 simulator, specifying the target takeoff altitude.
**Arguments**:
| Parameter Name | Type | Required | Default Value | Description |
| :--- | :--- | :---: | :--- | :--- |
| takeoffHeight | `float` | No | -10 | Target takeoff altitude, in meters |
**Returns**: No return value
**Raises**: No exceptions
---
#### `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.
**Arguments**:
| 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 |
**Returns**: No return value
**Raises**: No exceptions
---
#### `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.
**Arguments**:
| 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 |
**Returns**: No return value
**Raises**: No exceptions
---
#### `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.
**Arguments**:
| 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 |
**Returns**: No return value
**Raises**: No exceptions
---
#### `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.
**Arguments**:
| 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 |
**Returns**: No return value
**Raises**: No exceptions
### `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.
**Arguments**: None
**Returns**: None
**Raises**: No exceptions
#### `IsBitSet(num, bit)`
**Function Description**: Checks whether a specified bit is set in the given integer.
**Arguments**:
| Parameter Name | Type | Required | Default Value | Description |
| :--- | :--- | :---: | :--- | :--- |
| num | int | Yes | None | Integer to be checked |
| bit | int | Yes | None | Specified bit position |
**Returns**: bool: Returns `True` if the specified bit is set, otherwise returns `False`.
**Raises**: No exceptions
---
#### `IsPosSet(num)`
**Function Description**: Checks whether position control is enabled.
**Arguments (Args)**:
| Parameter Name | Type | Required | Default Value | Description |
| :--- | :--- | :---: | :--- | :--- |
| num | int | Yes | None | 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.
**Arguments (Args)**:
| Parameter Name | Type | Required | Default Value | 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.
**Arguments (Args)**:
| Parameter Name | Type | Required | Default Value | 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 North-East-Down (NED) coordinate frame without specifying yaw; maintains the current yaw.
**Arguments (Args)**:
| Parameter Name | Type | Required | Default Value | 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 velocity and yaw rate control command in the North-East-Down (NED) coordinate frame.
**Arguments (Args)**:
| Parameter Name | Type | Required | Default Value | 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 velocity and yaw rate control command in the Forward-Right-Down (FRD) body-fixed coordinate frame.
**Arguments (Args)**:
| Parameter Name | Type | Required | Default Value | 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 an acceleration command with no delay.
**Arguments (Args)**:
| Parameter Name | Type | Required | Default Value | 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 full control command including position, velocity, acceleration, and yaw rate with no delay.
**Arguments (Args)**:
| Parameter Name | Type | Required | Default Value | Description |
| :--- | :---: | :--- | :--- |
| x | float | Yes | None | Desired position component in X |
| y | float | Yes | None | Desired position component in Y |
| z | float | Yes | None | Desired position component in Z |
| vx | float | Yes | None | Desired velocity component in X |
| vy | float | Yes | None | Desired velocity component in Y |
| vz | float | Yes | None | Desired velocity component in Z |
| ax | float | Yes | None | Desired acceleration component in X |
| ay | float | Yes | None | Desired acceleration component in Y |
| az | float | Yes | None | Desired acceleration component in Z |
| 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.
**Arguments (Args)**:
| Parameter Name | Type | Required | Default Value | 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 |
**Returns**: None
**Raises**: None
---
#### `SendSynAtt(roll, pitch, yaw)`
**Function Description**: Synchronously sends a desired attitude command with no delay.
**Arguments (Args)**:
| Parameter Name | Type | Required | Default Value | 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 |
**Returns**: None
**Raises**: None
---
#### `TakeoffSyn(height)`
**Function Description**: Synchronously sends a takeoff command with no delay, ascending to the specified height.
**Arguments (Args)**:
| Parameter Name | Type | Required | Default Value | Description |
| :--- | :---: | :--- | :--- |
| height | float | Yes | None | Target takeoff height |
**Returns**: None
**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.
**Arguments (Args)**:
| Parameter Name | Type | Required | Default Value | Description |
| :--- | :---: | :--- | :--- |
| height | float | Yes | None | Flight altitude maintained during the return process |
**Returns**: None
**Raises**: None
---
#### `LandSyn(height=0)`
**Function Description**: Synchronously sends a landing command with no delay, descending to the specified height.
**Arguments (Args)**:
| Parameter Name | Type | Required | Default Value | Description |
| :--- | :---: | :--- | :--- |
| height | float | No | 0 | Target landing height |
**Returns**: None
**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.
**Arguments (Args)**:
| Parameter Name | Type | Required | Default Value | Description |
| :--- | :---: | :--- | :--- |
| x | float | Yes | None | Desired X-coordinate of position |
| y | float | Yes | None | Desired Y-coordinate of position |
| z | float | Yes | None | Desired Z-coordinate of position |
| speed | float | Yes | None | Desired flight speed magnitude |
**Returns**: None
**Raises**: None
---
#### `ResetSynCmd()`
**Function Description**: Resets the state of the synchronous command.
**Arguments (Args)**: No arguments
**Returns**: None
**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.
**Arguments (Args)**:
| Parameter Name | Type | Default Value | 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 |
**Returns**: None
**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.
**Arguments (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 |
|
**Returns**: None
**Raises**: None
---
#### `Updata3Doutput()`
**Function Description**: Updates output data for the 3D scene
**Args**: No parameters
**Returns**: None
**Raises**: None
---
#### `SendUpdate3DMap(isSetSpeed=False)`
**Function Description**: Sends map update information to the 3D simulation scene; optionally sets the simulation speed
**Args**:
| Parameter Name | Type | Required | Default Value | Description |
| :--- | :--- | :---: | :--- | :--- |
| isSetSpeed | Any | No | False | Whether to update and set the simulation run speed |
|
**Returns**: None
**Raises**: None
---
#### `get3DDataBuf()`
**Function Description**: Retrieves the 3D scene data buffer
**Args**: No parameters
**Returns**: 3D scene data buffer object
**Raises**: None
---
#### `Send3DData()`
**Function Description**: Sends 3D scene data to the simulation service
**Args**: No parameters
**Returns**: None
**Raises**: None
---
#### `SendSimData()`
**Function Description**: Sends simulation data to the flight controller
**Args**: No parameters
**Returns**: None
**Raises**: None
---
#### `SendHILData()`
**Function Description**: Sends Hardware-in-the-Loop (HIL) simulation data
**Args**: No parameters
**Returns**: None
**Raises**: None
---
#### `SendOutCopter()`
**Function Description**: Sends drone status data output
**Args**: No parameters
**Returns**: None
**Raises**: None
---
#### `fillList(data, inLen, fill=0)`
**Function Description**: Pads a list to a specified length using a specified value
**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 | Value used for padding |
|
**Returns**: Padded list
**Raises**: None
---
#### `StartAutUpdate(UpdateFreq=30, speed=-1)`
**Function Description**: Starts the automatic update thread for the 3D scene
**Args**:
| Parameter Name | Type | Required | Default Value | Description |
| :--- | :--- | :---: | :--- | :--- |
| UpdateFreq | Any | No | 30 | Automatic update frequency, in Hz |
| speed | Any | No | -1 | Simulation speed multiplier; -1 indicates no change to the original speed |
|
**Returns**: None
**Raises**: None
---
#### `StopAutUpdate()`
**Function Description**: Stops the automatic update thread for the 3D scene
**Args**: No parameters
**Returns**: None
**Raises**: None
---
#### `AutUpdateLoop()`
**Function Description**: Loop function for automatic updates, invoked by a thread
**Args**: No parameters
**Returns**: None
**Raises**: None
---
#### `StartExtCtrl()`
**Function Description**: Starts the external control reception thread
**Args**: No parameters
**Returns**: None
**Raises**: None
---
#### `StopExtCtrl()`
**Function Description**: Stops the external control reception thread
**Args**: No parameters
**Returns**: None
**Raises**: None
---
#### `Recv20100Loop()`
**Function Description**: Data reception loop function for port 20100, invoked by a reception thread
**Args**: No parameters
**Returns**: None
**Raises**: None
#### `Recv30100Loop()`
**Function Description**: None
**Args**: No parameters
**Returns**: None
**Raises**: None
---
#### `DllDestroyModel()`
**Function Description**: Destroys the model
**Args**: No parameters
**Returns**: None
**Raises**: None
---
#### `DllReInitModel()`
**Function Description**: Re-initializes the model
**Args**: No parameters
**Returns**: None
**Raises**: None
---
#### `DllInputSILs(in_ints, in_floats)`
**Function Description**: Inputs SIL (Software-in-the-Loop) data
**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 |
**Returns**: None
**Raises**: None
---
#### `DllInputColls(in_floats_collision)`
**Function Description**: Input collision data
**Arguments**:
| Parameter Name | Type | Required | Default Value | Description |
| :--- | :--- | :---: | :--- | :--- |
| in_floats_collision | None | No | `[0] * 20` | Input floating-point collision data |
**Returns**: None
**Raises**: None
---
#### `DllTerrainIn15d(terrain15d)`
**Function Description**: Input terrain height data
**Arguments**:
| Parameter Name | Type | Required | Default Value | Description |
| :--- | :--- | :---: | :--- | :--- |
| terrain15d | None | No | `[0] * 15` | 15-dimensional terrain height data |
**Returns**: None
**Raises**: None
---
#### `DllInitGpsPos(gps)`
**Function Description**: Input the origin coordinates of the GPS position
**Arguments**:
| Parameter Name | Type | Required | Default Value | Description |
| :--- | :--- | :---: | :--- | :--- |
| gps | None | No | `[0] * 3` | GPS origin latitude, longitude, and altitude data |
**Returns**: None
**Raises**: None
---
#### `DllInitPosAngState(init_pos_offset, init_ang_offset)`
**Function Description**: Initialize position and attitude angle states
**Arguments**:
| 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 |
**Returns**: None
**Raises**: None
---
#### `DllInputDoubCtrls(in_doub_ctrls)`
**Function Description**: Input control command data
**Arguments**:
| Parameter Name | Type | Required | Default Value | Description |
| :--- | :--- | :---: | :--- | :--- |
| in_doub_ctrls | None | No | `[0] * 28` | 28-dimensional double-precision control command data |
**Returns**: None
**Raises**: None
---
#### `DllinSIL28d(in_doub_ctrls)`
**Function Description**: Input control command data
**Arguments**:
| Parameter Name | Type | Required | Default Value | Description |
| :--- | :--- | :---: | :--- | :--- |
| in_doub_ctrls | None | No | `[0] * 28` | 28-dimensional double-precision control command data |
**Returns**: None
**Raises**: None
---
#### `DllInCtrlExt(in_ctrl_ext)`
**Function Description**: Input fault injection data
**Arguments**:
| Parameter Name | Type | Required | Default Value | Description |
| :--- | :--- | :---: | :--- | :--- |
| in_ctrl_ext | None | No | `[0] * 140` | 140-dimensional extended control fault injection data |
**Returns**: None
**Raises**: None
---
#### `DllInFromUE(in_from_ue)`
**Function Description**: Input UE data into the DLL
**Arguments**:
| Parameter Name | Type | Required | Default Value | Description |
| :--- | :--- | :---: | :--- | :--- |
| in_from_ue | None | No | `[0] * 32` | 32-dimensional input data from UE |
**Returns**: None
**Raises**: None
---
#### `DllInputColls(inCll)`
**Function Description**: Input collision data into the DLL
**Arguments**:
| Parameter Name | Type | Required | Default Value | Description |
| :--- | :--- | :---: | :--- | :--- |
| inCll | None | No | `[0] * 20` | 20-dimensional collision input data |
**Returns**: None
**Raises**: None
---
#### `DllGetStep0()`
**Function Description**: Retrieve the simulation step size
**Arguments**: None
**Returns**: Simulation step size value
**Raises**: None
---
#### `Dllstep()`
**Function Description**: Execute one simulation step
**Arguments**: None
**Returns**: None
**Raises**: None
---
#### `ModelUpdate(step_time)`
**Function Description**: Execute simulation for `step_time` seconds
**Arguments**:
| Parameter Name | Type | Required | Default Value | Description |
| :--- | :--- | :---: | :--- | :--- |
| step_time | None | Yes | N/A | Simulation duration to advance, in seconds |
**Returns**: None
**Raises**: None
---
#### `DlloutVehileInfo60d()`
**Function Description**: Export 60-dimensional vehicle information data
**Parameters (Args)**: None
**Returns**: None
**Raises**: None
---
#### `DllOutCopterData()`
**Function Description**: Export simulation data for multi-rotor aircraft
**Parameters (Args)**: None
**Returns**: None
**Raises**: None
---
#### `SendPosNED(x=0, y=0, z=0, yaw=0)`
**Function Description**: Send position and yaw angle commands in the NED coordinate system
**Parameters (Args)**:
| Parameter Name | Type | Required | Default Value | Description |
| :--- | :--- | :---: | :--- | :--- |
| x | None | No | 0 | North direction position coordinate in NED coordinate system |
| y | None | No | 0 | East direction position coordinate in NED coordinate system |
| z | None | No | 0 | Down direction position coordinate in NED coordinate system |
| yaw | None | No | 0 | Yaw angle |
**Returns**: None
**Raises**: None
---
#### `SendPosLocal(x=0, y=0, z=0, yaw=0)`
**Function Description**: Send 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 x-direction in local coordinate system |
| y | None | No | 0 | Position coordinate in y-direction in local coordinate system |
| z | None | No | 0 | Position coordinate in z-direction in local coordinate system |
| yaw | None | No | 0 | Yaw angle |
**Returns**: None
**Raises**: None
---
#### `SendVelNED(vx=0, vy=0, vz=0, yawRate=0)`
**Function Description**: Send 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 north direction in NED coordinate system |
| vy | None | No | 0 | Velocity in east direction in NED coordinate system |
| vz | None | No | 0 | Velocity in down direction in NED coordinate system |
| yawRate | None | No | 0 | Yaw rate |
**Returns**: None
**Raises**: None
---
#### `SendVelFRD(vx=0, vy=0, vz=0, yawRate=0)`
**Function Description**: Send 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 forward direction in FRD coordinate system |
| vy | None | No | 0 | Velocity in right direction in FRD coordinate system |
| vz | None | No | 0 | Velocity in down direction in FRD coordinate system |
| yawRate | None | No | 0 | Yaw rate |
**Returns**: None
**Raises**: None
---
#### `SendVelNEDNoYaw(northvel=0, eastvel=0, downvel=0)`
**Function Description**: Send 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 north direction in NED coordinate system |
| eastvel | None | No | 0 | Velocity in east direction in NED coordinate system |
| downvel | None | No | 0 | Velocity in down direction in NED coordinate system |
**Returns**: None
**Raises**: None
### `MultiCopterDll` Class
Multi-rotor UAV simulation model loading class, used to load multi-rotor UAV models and perform simulation initialization configuration within the RflySim simulation environment.
#### `__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**: Initialize a multi-rotor UAV model instance and complete model loading and basic parameter configuration in the simulation environment
**Parameters (Args)**:
| Parameter Name | Type | Required | Default Value | Description |
| :--- | :--- | :---: | :--- | :--- |
| `CopterID` | `int` | No | `1` | Multi-rotor UAV identifier, used to distinguish different UAVs within the same simulation environment |
| `ClassID` | `int` | No | `-1` | UAV category ID; -1 indicates using default category configuration |
| `MapName` | `str` | No | `"Grasslands"` | Map name used in the simulation environment; defaults to the Grasslands grassland map |
| `ip` | `str` | No | `"127.0.0.1"` | IP address for connecting to the simulation service; defaults to localhost for local simulation |
| `LocX` | `float` | No | `0` | Eastward (X-axis) initial position coordinate of the UAV |
| `LocY` | `float` | No | `0` | Northward (Y-axis) initial position coordinate of the UAV |
| `Yaw` | `float` | No | `0` | Initial heading angle of the UAV, in degrees |
| `UdpMode` | `int` | No | `0` | UDP communication mode configuration; 0 indicates default mode, other modes can be selected based on communication requirements |
| `useGPS` | `bool` | No | `False` | Whether to enable GPS simulation; True enables it, False disables it |
| `GpsOrin` | `list[float]` | No | `[0, 0, 0]` | Offset of the GPS sensor relative to the UAV body, in format [x, y, z] |
**Returns**:
- `MultiCopterDll` instance object
**Raises**: None
**Example**:
```python
from RflySimSDK.ctrl import MultiCopterDll
# Load the No. 1 multi-rotor drone, enable GPS, and set the initial position at the origin
copter = MultiCopterDll(CopterID=1, useGPS=True, LocX=0, LocY=0)
---
## Advanced Usage Examples
> Demonstrates complex composite scenarios (e.g., multi-class collaboration, asynchronous control, batch operations)
```python
import RflySimSDK.ctrl as rfly_ctrl
import threading
# Example of batch networked asynchronous control for multiple UAVs
def batch_vehicle_control(vehicle_configs):
# 1. Batch-create multiple UAVs
model_loader = rfly_ctrl.ModelLoad()
vehicle_list = []
for config in vehicle_configs:
veh = model_loader.CreateVehicle(config["model_path"], config["init_pos"])
vehicle_list.append(veh)
# Populate the model input parameter list
sim_ctrl = rfly_ctrl.DllSimCtrlAPI()
sim_ctrl.fillList()
# Send initialization parameters
sim_ctrl.sendInitInParams(config["init_params"])
# 2. Asynchronously update 3D scene visualization without blocking control logic
def async_update_visual():
data_3d = rfly_ctrl.Data3D()
while True:
output_buf = model_loader.get3DDataBuf()
model_loader.Updata3Doutput(output_buf)
data_3d.updateUdp()
model_loader.SendUpdate3DMap()
update_thread = threading.Thread(target=async_update_visual, daemon=True)
update_thread.start()
# 3. Multi-class collaboration for heterogeneous control: fixed-wing and multi-rotor simultaneously send differently formatted control commands
rfly_cp = rfly_ctrl.RflySimCP()
for idx, veh in enumerate(vehicle_list):
if veh.type == "multicopter":
# Send multi-rotor extended double-precision control commands
sim_ctrl.sendInCtrlExtDoub(idx, veh.thrust, veh.attitude)
else:
# Send fixed-wing mixed integer and floating-point control commands
sim_ctrl.sendSILIntFloat(idx, veh.mode, veh.aileron, veh.elevator)
# Synchronize aircraft state data
pos = rfly_cp.getPosNED(veh.id)
vel = rfly_cp.getVelNED(veh.id)
rfly_cp.SendSynFull(veh.id, pos, vel, rpy=veh.attitude)
if __name__ == "__main__":
# Configure a networked mission with 3 UAVs
configs = [
{"model_path": "copter_x.param", "init_pos": [0,0,0], "init_params": {}},
{"model_path": "plane_a.param", "init_pos": [5,0,0], "init_params": {}},
{"model_path": "copter_y.param", "init_pos": [0,5,0], "init_params": {}}
]
batch_vehicle_control(configs)
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