Ass Interface Documentation¶
Introduction¶
Overview: This file provides flight safety assessment and fuzzy probabilistic safety analysis functionality, supporting UAV flight mission safety level determination based on trajectory segmentation metrics.
This module belongs to the RflySim UAV simulation platform’s Prognostics and Health Management (PHM) toolset, primarily targeting safety analysis scenarios for UAV flight missions. During simulation flight tests and mission planning validation, users can input predefined start/end points, crash events, and other segmentation metrics to call the safety assessment interface for scoring the entire flight data. Alternatively, users can apply the Profust fuzzy safety analysis method to determine UAV mission safety status under complex uncertain scenarios. This is applicable to UAV fault injection simulation evaluation, mission plan safety validation, and other use cases.
Quick Start¶
This module has no publicly exposed classes.
Environment and Dependencies¶
- Python Environment:
>= 3.8.10 - Dependencies:
math,matplotlib.pyplot,numpy,openpyxl - Prerequisites: Before calling this interface, the RflySimSDK must be initialized and the corresponding module imported.
Core Interface Description¶
The module Ass.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¶
SaftyAssessment(Index, EvalName, EvalData, EvalDim, EvalParam, CtrlCmd=[[0, 0, 0], [0, 0, 0]])¶
Function Description: Performs safety assessment on UAV flight processes. Based on input index information, evaluation data, and parameters, it computes safety metrics for a specified time period.
Parameters:
Index: List of index entries, containing start index, end index, and crash position index.EvalName: Name identifier of the data to be evaluated.EvalData: List of data items to be evaluated, which may include attitude angles, velocity, position, and other flight data.EvalDim: List of dimension entries, representing the specific dimensions corresponding to each data item to be evaluated.EvalParam: List of parameter entries, including data frequency (number of data points per second), ground kinetic energy, and metric weights.CtrlCmd: List of control command entries, representing target position and velocity commands. Default value is[[0, 0, 0], [0, 0, 0]].
Return Value:
- No return value or an assessment result object, depending on the actual implementation (safety assessment result).
Exceptions: None
ProfustSafty(ErrorDataEvalSeries, FallEnergy, Data_index)¶
Function Description: Performs uncertain safety assessment of flight using the Profust method, calculating safety levels based on error evaluation data series and fall energy parameters.
Parameters:
ErrorDataEvalSeries: Time series of error data for evaluation.FallEnergy: Kinetic energy threshold parameter during the fall process.Data_index: Data index corresponding to the data to be evaluated.
Return Value:
- Computed Profust safety assessment result.
Exceptions: None
Advanced Usage Example¶
Demonstrates complex composite scenarios (e.g., multi-unit collaboration, asynchronous control, batch operations)
This example demonstrates an advanced scenario of asynchronous collection and batch anomaly labeling of multi-UAV PHM health status based on the RflySimSDK.phm module. It uses asynchronous scheduling to parallelize PHM sensor data collection from multiple UAVs and combines health status classification to output batch anomaly annotations:
import asyncio
import RflySimSDK.phm as phm
# Initialize batch PHM data collector object
async def collect_uav_phm_data(uav_id_list):
phm_result = {}
# Asynchronous task list for parallel multi-UAV data collection
task_list = [phm.Ass.get_health_data(uav_id) for uav_id in uav_id_list]
# Concurrently execute all collection tasks
result_list = await asyncio.gather(*task_list)
for uav_id, res in zip(uav_id_list, result_list):
phm_result[uav_id] = res
return phm_result
# Batch mark abnormal health status
def batch_mark_abnormal(phm_data, threshold=0.6):
abnormal_list = []
for uav_id, health_info in phm_data.items():
if health_info['health_score'] < threshold:
abnormal_list.append((uav_id, health_info))
phm.Ass.register_abnormal(uav_id, health_info)
return abnormal_list
# Main function to execute multi-UAV PHM collaborative tasks
if __name__ == "__main__":
target_uavs = [1, 3, 5, 7, 9]
phm_data = asyncio.run(collect_uav_phm_data(target_uavs))
abnormal_uavs = batch_mark_abnormal(phm_data)
print(f"Detected {len(abnormal_uavs)} abnormal UAV(s); anomaly registration completed.")
Notes and Pitfall Avoidance Guide¶
- Module Initialization Dependency: Before using
RflySimSDK.phm.Assfunctionality, the global initialization of the RflySim core SDK must be completed. Calling PHM interfaces without initialization will result in an uncaught null pointer exception. - Asynchronous Collection Concurrency Limit: When performing batch asynchronous collection of PHM data from multiple UAVs, the number of concurrent tasks should not exceed 10. Excessive concurrency may occupy simulation port bandwidth, causing timeouts and packet loss in some collection results.
- Health Data Cache Update: By default, the PHM module caches health status data for up to 30 seconds. To obtain the latest real-time data, call
phm.Ass.clear_cache()to clear the cache before initiating a new collection request. - Abnormal Registration Duplicate Handling: It is not recommended to repeatedly call the registration interface for the same UAV’s same anomaly event. Duplicate registration leads to redundant exception logs in the simulation backend, affecting the accuracy of subsequent PHM fault analysis results.
Changelog¶
2024-08-02: chore: Added code comments for generating HTML-format API documentation.