Skip to content

AutoVisConf Vision Configuration

简介

简述:该文件提供了无人机自动可视化系统的配置接口,用于管理和设置仿真环境中的可视化参数与场景配置。

在无人机仿真过程中,可视化配置是连接物理模型与视觉呈现的关键环节。AutoVisConf 模块通过 MavVIS 类为开发者提供自动化可视化配置能力,支持快速搭建仿真场景、调整视觉参数以及配置传感器视角等。该模块适用于需要定制化可视化效果的仿真任务,如三维场景渲染、多视角监控、飞行数据可视化等场景,能够显著提升仿真调试效率与演示效果。

该模块作为 RflySim SDK 中 PHM(Prognostics and Health Management,预测与健康管理)子系统的一部分,主要面向仿真阶段的可视化配置需求。其设计目标是简化用户对复杂可视化流程的控制,使开发者能专注于算法验证与系统集成,而无需深入底层图形渲染细节。通过统一的配置接口,用户可灵活适配不同仿真场景下的视觉输出需求,例如模拟吊舱视角、添加传感器噪声、实时更新图像流等,从而支撑更贴近真实环境的仿真测试与评估。

快速开始

最简可用示例,复制后修改最少配置即可运行。

from RflySimSDK.phm.AutoVisConf import MavVIS

# 1. 创建MavVIS实例,传入配置文件路径
# conf参数为配置文件路径,用于初始化可视化参数
vis = MavVIS(conf="config.json")

# 2. 显示/更新可视化窗口
# 调用visShow方法显示或更新图像可视化界面
vis.visShow()

# 3. 对图像添加高斯噪声(可选)
# image: 输入图像, mu: 均值, sigma: 标准差
# noisy_img = vis.gasuss_noise(image=img, mu=0, sigma=10)

# 4. 设置吊舱故障(可选)
# PodfalutId: 故障ID编号,用于模拟吊舱特定故障模式
# vis.Podfault(PodfalutId=1)

环境与依赖

  • Python 环境>= 3.8.10
  • 依赖库cv2mathnumpyosrandomresystime
  • 前置准备:调用此接口前,必须先启动 RflySim3D 可视化引擎。

核心接口说明

该模块 AutoVisConf.py 包含了配置变量、辅助函数及核心业务类。

全局常量与枚举定义

本节列出模块中所有可直接引用的全局常量和枚举定义。

独立常量


全局/独立函数


MavVIS

简要描述该类的功能和使用场景。

__init__(conf)

功能说明:初始化 MavVIS 实例 参数列表 (Args)

参数名 类型 是否必填 默认值 说明
conf - - 配置参数

返回值 (Returns)

  • MavVIS 实例对象

异常 (Raises)


visShow()

功能说明:显示可视化内容 参数列表 (Args):无

返回值 (Returns)

异常 (Raises)

示例

mav_vis = MavVIS(conf)
mav_vis.visShow()

gasuss_noise(image, mu, sigma)

功能说明:对图像添加高斯噪声 参数列表 (Args)

参数名 类型 是否必填 默认值 说明
image - - 输入图像
mu - - 高斯分布均值
sigma - - 高斯分布标准差

返回值 (Returns)

异常 (Raises)

示例

mav_vis = MavVIS(conf)
mav_vis.gasuss_noise(image_data, 0.0, 1.0)

---

#### `Podfault(PodfaultId)`

**Function Description**: Set pod fault  
**Parameters (Args)**:

| Parameter Name | Type | Required | Default Value | Description |
| :--- | :--- | :---: | :--- | :--- |
| `PodfaultId` | - | Yes | - | Pod fault ID |

**Return Value (Returns)**:

- None

**Exceptions (Raises)**:

- None

## Advanced Usage Example

> Demonstrates complex composite scenarios (e.g., multi-class collaboration, asynchronous control, batch operations)

```python
# Advanced example code
from RflySimSDK.phm.AutoVisConf import MavVIS
import threading
import time

# Multi-UAV collaborative visualization scenario
def multi_uav_vis_system():
    # Create multiple visualization instances
    vis_nodes = [MavVIS(uav_id=i) for i in range(5)]

    # Batch configure Gaussian noise parameters (simulating varying sensor quality)
    noise_profiles = [(0.1, 0.05), (0.2, 0.1), (0.05, 0.02), (0.15, 0.08), (0.3, 0.12)]
    for vis, (mu, sigma) in zip(vis_nodes, noise_profiles):
        vis.gasuss_noise(mu=mu, sigma=sigma)

    # Asynchronously start visualization for each node
    threads = []
    def async_vis_show(vis_instance, delay):
        time.sleep(delay)  # Simulate network latency differences
        vis_instance.visShow(enable=True, sync_mode=False)

    for idx, vis in enumerate(vis_nodes):
        t = threading.Thread(target=async_vis_show, args=(vis, idx * 0.5))
        t.start()
        threads.append(t)

    # Fault injection: simulate sensor fault for UAV #3
    time.sleep(2)
    vis_nodes[2].Podfault(fault_type="sensor_drop", duration=5.0)

    # Wait for all threads to complete
    for t in threads:
        t.join()

if __name__ == "__main__":
    multi_uav_vis_system()

Notes and Pitfall Avoidance Guide

  • gasuss_noise Parameter Units: The mu and sigma parameters are dimensionless relative values (proportional to full-scale range), not physical units. For instance, if a sensor’s range is 100 m, setting sigma=0.1 corresponds to an actual noise of 10 m. Avoid mistakenly specifying absolute values, which may cause excessive noise or simulation distortion.

  • Podfault Fault Duration: The duration parameter is in seconds, but internal timing depends on the visShow refresh cycle. If the visualization frame rate is too low (<10 Hz), the actual fault duration may significantly deviate from the specified value. In scenarios with strict real-time requirements, it is recommended to use sync_mode=True.

  • Multi-Instance Resource Conflicts: When creating multiple MavVIS instances within the same process, ID conflicts in the underlying visualization channels may occur if uav_id values are duplicated or unspecified, leading to screen flickering or data stream corruption. Ensure each instance’s uav_id is globally unique, or explicitly release resources by calling visShow(enable=False) before reconstructing instances.

  • Asynchronous Thread Safety: Methods such as visShow, gasuss_noise, and Podfault involve OpenGL/DirectX rendering contexts and are not thread-safe. If invoked in subthreads (e.g., as in the asynchronous startup example), ensure the host environment supports multithreaded rendering (e.g., by setting sync_mode=False to unblock the main thread); otherwise, segmentation faults or rendering freezes may occur.

Changelog

  • 2026-04-08: 🐛 fix: Corrected cv2 import method
  • 2025-04-01: fix