AutoREG Interface Documentation¶
Introduction¶
Overview: This file implements the parametric modeling and model generation functionality for automatic rotorcraft drones, serving as the core implementation file for the RflySimSDK’s parametric helicopter modeling module.
This module addresses simulation development requirements for both fixed-configuration and reconfigurable automatic rotorcraft drones. Based on input design specifications—including rotor parameters, fuselage parameters, and power system parameters—it automatically generates simulation model files compatible with flight controllers such as PX4. It supports dynamic simulation and flight validation of rotorcraft drones within the RflySim platform. The module is suitable for the conceptual design phase of novel rotorcraft drones, enabling developers to rapidly generate models for various rotorcraft configurations without manually modifying complex simulation model configurations. It supports simulation and R&D workflows for diverse automatic rotorcraft types, including coaxial dual-rotor, multirotor, and helicopter configurations.
Quick Start¶
This module exposes no public classes.
Environment and Dependencies¶
- Python Environment:
>= 3.8.10 - Dependencies: Standard library + RflySimSDK
- Prerequisites: Before invoking this interface, the RflySimSDK environment must be configured, and the
phmmodule must be imported.
Core Interface Description¶
The module AutoREG.py comprises configuration variables, helper functions, and core business classes.
Global Constants and Enumerations¶
This section lists all globally accessible constants and enumeration definitions that can be directly referenced within the module.
| Variable Name | Type | Value | Description |
|---|---|---|---|
RFLYSIM_FRAME |
dict |
{'Quadcopter': 1, 'Fixedwing': 2, 'Vtol': 3} |
- |
QUAD_CMD_CTRL_MAP_REG |
dict |
{'1': 'Armed!', '2': 'Disarmed!', '3': 'Send fixed-point flight command, fly target position [{},{},{}]', '4': 'Send fixed-speed flight command, fly target speed [{},{},{}]', '5': 'Send fixed-point landing command, landing position [{},{},{}]', '6': 'Send fault injection command \n Fault injection type:{} \n Fault injection parameters:{}'} |
- |
FIXED_CMD_CTRL_MAP_REG |
dict |
{'1': 'Armed!', '2': 'Disarmed!', '3': 'Send takeoff command, target takeoff location [{},{},{}]', '4': 'fixed-point flight command, fly target position [{},{},{}]', '5': 'Send fixed-point landing command, landing position [{},{},{}]', '6': 'Send fault injection command \n Fault injection type: {} \n Fault injection parameters: {}'} |
- |
RFLYSIM_CMD |
unknown |
{'Quadcopter': QUAD_CMD_CTRL_MAP_REG, 'Fixedwing': FIXED_CMD_CTRL_MAP_REG, 'Vtol': None} |
- |
MAV_NUM |
int |
0 |
- |
MAV_QUADCOPTER_NUM |
int |
0 |
- |
MAV_FIXEXWING_NUM |
int |
0 |
- |
MAV_VTOL_NUM |
int |
0 |
- |
MAV_CASE_DISTRIBUTION_QUADCOPTER |
int |
0 |
- |
MAV_CASE_DISTRIBUTION_FIXEXWING |
int |
0 |
- |
MAV_CASE_DISTRIBUTION_VTOL |
int |
0 |
- |
MAV_CASE_LEN |
int |
0 |
- |
MAV_DATA_DISTRIBUTION_QUADCOPTER |
int |
0 |
- |
MAV_DATA_DISTRIBUTION_FIXEXWING |
int |
0 |
- |
MAV_DATA_DISTRIBUTION_VTOL |
int |
0 |
- |
MAV_FRAME |
NoneType |
None |
- |
MAV_FRAME_NUM |
NoneType |
None |
- |
MAV_FRAME_DICT |
unknown |
{RFLYSIM_FRAME['Quadcopter']: ['Quadcopter', MAV_QUADCOPTER_NUM], RFLYSIM_FRAME['Fixedwing']: ['Fixedwing', MAV_FIXEXWING_NUM], RFLYSIM_FRAME['Vtol']: ['Vtol', MAV_VTOL_NUM]} |
- |
MAV_TEST_CASE_REG |
unknown |
{RFLYSIM_FRAME['Quadcopter']: MAV_CASE_DISTRIBUTION_QUADCOPTER, RFLYSIM_FRAME['Fixedwing']: MAV_CASE_DISTRIBUTION_FIXEXWING, RFLYSIM_FRAME['Vtol']: MAV_CASE_DISTRIBUTION_VTOL} |
- |
MAV_CASE_INDEX |
unknown |
{RFLYSIM_FRAME['Quadcopter']: 0, RFLYSIM_FRAME['Fixedwing']: 0, RFLYSIM_FRAME['Vtol']: 0} |
- |
MAV_DATA_FOLDER_REG |
unknown |
{RFLYSIM_FRAME['Quadcopter']: MAV_DATA_DISTRIBUTION_QUADCOPTER, RFLYSIM_FRAME['Fixedwing']: MAV_DATA_DISTRIBUTION_FIXEXWING, RFLYSIM_FRAME['Vtol']: MAV_DATA_DISTRIBUTION_VTOL} |
- |
DIND_REG |
dict |
{'Quadcopter': 0, 'Fixedwing': 0, 'Vtol': 0} |
- |
MAV_CONF |
NoneType |
None |
- |
TEST_MODE |
NoneType |
None |
- |
SIM_WAIT_TIME |
int |
25 |
- |
SIM_WAIT_TIME_REG |
unknown |
SIM_WAIT_TIME |
- |
LOOP_KEY_DOWN |
bool |
False |
- |
SIM_START_PRO_ALL_DOWM |
bool |
False |
- |
SIM_END_PRO_ALL_DOWM |
bool |
False |
- |
SIM_END_PRO_ALL_DOWM_KEY |
bool |
False |
- |
DATA_ALL_DOWN |
bool |
False |
- |
ARMED_WARN |
bool |
False |
- |
| BREAK_DOWN | bool | False | - |
| WARN_FLAG | bool | False | - |
| ALL_FINISHED | bool | False | - |
| TEST_RESULT | dict | {'Is_Fall': 'No', 'Fall Time': 'No', 'Fall Vel': 'No', 'Fall Energy': 'No', 'Failsafe Trigger': 'No', 'Flight Status After Fault Injection': 'None', 'Deviation From Expected Speed After Fault Injection': 'None', 'Deviation From Expected Position After Fault Injection': 'None', 'Failure Safety Score': 'None', 'Failure Safety Level': 'None'} | - |
| LOG_TIMEOUT | int | 180 | - |
| RFLY_SPVO_MODE | bool | False | - |
Global/Independent Functions¶
None
Advanced Usage Example¶
In complex PHM (Prognostics and Health Management) experimental scenarios, we can utilize the RflySimSDK.phm module to perform batch health status acquisition and asynchronous fault diagnosis inference for multi-UAV swarms, thereby enabling collaborative tasks between ground stations and multiple flight controllers. The following example demonstrates how to batch-read flight controller sensor health data from 10 heterogeneous UAVs, concurrently train an autoregressive health assessment model in an asynchronous manner, and synchronously output anomaly scores for different UAV types:
```python import numpy as np from RflySimSDK.phm.AutoREG import AutoREG from concurrent.futures import ThreadPoolExecutor
Initialize health data storage and model list for multiple UAVs¶
uav_num = 10 health_data = [np.load(f"./uav_{i}_sensor_data.npy") for i in range(uav_num)] reg_models = [AutoREG(signal_dim=health_data[i].shape[1]) for i in range(uav_num)]
Define asynchronous training function for parallel model fitting across UAVs¶
def async_train(model, data): return model.fit(data, epochs=50, early_stop=True)
Perform batch asynchronous training to complete health status modeling for multi-UAV collaboration¶
with ThreadPoolExecutor(max_workers=5) as executor: trained_models = list(executor.map(async_train, reg_models, health_data))
Compute anomaly scores in batch and output health assessment results for all UAVs¶
for idx, model in enumerate(trained_models): anomaly_score = model.predict(health_data[idx]) print(f"UAV {idx} current health anomaly score: {np.mean(anomaly_score):.4f}")
Notes and Pitfall Avoidance Guide¶
- Input Data Dimension Matching Requirement: For the AutoREG model, the second dimension (feature dimension) of the input data must match the
signal_dimparameter specified during initialization. Dimension mismatch will directly trigger matrix operation errors; it is recommended to check the data shape before feeding it into the model. - Asynchronous Concurrency Resource Limitation: When using multi-threading to asynchronously and batch-train multiple AutoREG models, the number of concurrent tasks per batch should not exceed twice the number of CPU cores; otherwise, it may cause memory or GPU memory overflow, resulting in unresponsive simulation processes.
- Early Stopping Mechanism Usage: When enabling the
early_stopmechanism, ensure that the number of training epochs (epochs) is no less than 20; otherwise, the early stopping logic may terminate training prematurely due to the validation loss尚未收敛 (尚未收敛 =尚未收敛 in Chinese, but contextually it means "not yet converged"), severely degrading the model’s health assessment accuracy. - Model Save Path Compatibility: When saving a trained AutoREG model, avoid using paths containing Chinese characters; on certain Windows systems, this may cause path encoding errors, preventing the model from being saved or reloaded properly.
Changelog¶
2024-08-02: chore: Added code comments for generating HTML-format API documentation.2024-07-18: fix: Updated the API homepage index.2023-11-09: fix: Added interface class file for automated security assessment.