276 lines
9.9 KiB
C#
276 lines
9.9 KiB
C#
using ThreatSource.Utils;
|
||
using ThreatSource.Jammer;
|
||
using ThreatSource.Simulation;
|
||
using ThreatSource.Missile;
|
||
using System.Diagnostics;
|
||
|
||
namespace ThreatSource.Sensor
|
||
{
|
||
/// <summary>
|
||
/// 红外探测器类,实现了红外辐射的探测和目标识别功能
|
||
/// </summary>
|
||
/// <remarks>
|
||
/// 该类提供了红外探测器的核心功能:
|
||
/// - 红外辐射强度测量
|
||
/// - 目标存在性判断
|
||
/// - 视场角范围探测
|
||
/// - 实时状态更新
|
||
/// 用于末敏子弹的目标探测和跟踪
|
||
/// </remarks>
|
||
public class InfraredDetector : Sensor
|
||
{
|
||
/// <summary>
|
||
/// 定义设备支持的干扰类型
|
||
/// </summary>
|
||
/// <remarks>
|
||
/// 红外探测器支持的干扰类型:
|
||
/// - 红外干扰
|
||
/// </remarks>
|
||
public override IEnumerable<JammingType> SupportedJammingTypes => [JammingType.Infrared];
|
||
|
||
/// <summary>
|
||
/// 探测辐射强度阈值,单位:瓦特/球面度
|
||
/// </summary>
|
||
/// <remarks>
|
||
/// 定义了目标识别的最小辐射强度
|
||
/// 大于此阈值表示探测到有效目标
|
||
/// 用于目标存在性判断
|
||
/// </remarks>
|
||
private const double DetectionRadiationIntensityThreshold = 50;
|
||
|
||
/// <summary>
|
||
/// 获取或设置探测范围,单位:米
|
||
/// </summary>
|
||
/// <remarks>
|
||
/// 定义了探测器的最大作用距离
|
||
/// 影响目标探测的有效范围
|
||
/// </remarks>
|
||
public double MaxDetectionRange { get; set; }
|
||
|
||
/// <summary>
|
||
/// 获取或设置红外波段
|
||
/// </summary>
|
||
public InfraredBand Band { get; set; }
|
||
|
||
/// <summary>
|
||
/// 获取或设置视场角,单位:度
|
||
/// </summary>
|
||
/// <remarks>
|
||
/// 定义了探测器的视场范围
|
||
/// 影响目标探测的空间覆盖
|
||
/// </remarks>
|
||
public double FieldOfView { get; set; } = 10;
|
||
|
||
/// <summary>
|
||
/// 末敏子弹实例
|
||
/// </summary>
|
||
/// <remarks>
|
||
/// 关联的末敏子弹对象
|
||
/// 用于获取位置和姿态信息
|
||
/// </remarks>
|
||
private readonly TerminalSensitiveSubmunition submunition;
|
||
|
||
/// <summary>
|
||
/// 红外探测器数据实例
|
||
/// </summary>
|
||
/// <remarks>
|
||
/// 存储探测器的测量结果
|
||
/// 包含温度和目标探测状态
|
||
/// </remarks>
|
||
private InfraredSensorData sensorData;
|
||
|
||
/// <summary>
|
||
/// 初始化红外探测器的新实例
|
||
/// </summary>
|
||
/// <param name="id">红外探测器的ID</param>
|
||
/// <param name="submunition">末敏子弹实例</param>
|
||
/// <param name="config">红外探测器配置</param>
|
||
/// <param name="simulationManager">仿真管理器实例</param>
|
||
/// <remarks>
|
||
/// 构造过程:
|
||
/// - 设置探测参数
|
||
/// - 关联末敏子弹
|
||
/// - 初始化传感器数据
|
||
/// - 继承基类位置和姿态
|
||
/// </remarks>
|
||
public InfraredDetector(string id, TerminalSensitiveSubmunition submunition, InfraredDetectorConfig config, ISimulationManager simulationManager)
|
||
: base(id, new MotionParameters(submunition.Position, submunition.Orientation, submunition.Speed), simulationManager)
|
||
{
|
||
MaxDetectionRange = config.MaxDetectionRange;
|
||
FieldOfView = config.FieldOfView;
|
||
Band = config.Band;
|
||
this.submunition = submunition;
|
||
sensorData = new InfraredSensorData();
|
||
|
||
// 初始化干扰处理,设置干扰抗性阈值和支持的干扰类型
|
||
InitializeJamming(config.JammingResistanceThreshold, [JammingType.Infrared]);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 激活红外探测器
|
||
/// </summary>
|
||
/// <remarks>
|
||
/// 激活红外探测器,设置传感器数据为活动状态
|
||
/// </remarks>
|
||
public override void Activate()
|
||
{
|
||
base.Activate();
|
||
SimulationManager.SubscribeToEvent<InfraredJammingEvent>(OnInfraredJamming);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 停用红外探测器
|
||
/// </summary>
|
||
/// <remarks>
|
||
/// 停用红外探测器,取消事件订阅
|
||
/// </remarks>
|
||
public override void Deactivate()
|
||
{
|
||
base.Deactivate();
|
||
SimulationManager.UnsubscribeFromEvent<InfraredJammingEvent>(OnInfraredJamming);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 处理红外干扰事件
|
||
/// </summary>
|
||
/// <param name="evt">红外干扰事件数据</param>
|
||
private void OnInfraredJamming(InfraredJammingEvent evt)
|
||
{
|
||
// 检查波长匹配(红外特定逻辑)
|
||
bool isWavelengthCompatible = IsWavelengthCompatible(evt.Wavelength);
|
||
|
||
if (!isWavelengthCompatible)
|
||
{
|
||
System.Diagnostics.Debug.WriteLine($"红外干扰波长 {evt.Wavelength}um 与红外探测器波段 {Band} 不匹配,忽略干扰");
|
||
return;
|
||
}
|
||
|
||
// 创建干扰参数
|
||
var parameters = new JammingParameters
|
||
{
|
||
Type = JammingType.Infrared,
|
||
Power = evt.JammingPower,
|
||
Direction = evt.JammingDirection,
|
||
SourcePosition = evt.JammingSourcePosition,
|
||
AngleRange = evt.JammingAngleRange,
|
||
Mode = evt.JammingMode,
|
||
Duration = evt.Duration
|
||
};
|
||
|
||
ApplyJamming(parameters);
|
||
Debug.WriteLine($"干扰状态 - IsJammed: {IsJammed}");
|
||
}
|
||
|
||
/// <summary>
|
||
/// 检查干扰波长是否与红外探测器波段匹配
|
||
/// </summary>
|
||
/// <param name="wavelength">干扰波长(微米)</param>
|
||
/// <returns>如果波长匹配返回true,否则返回false</returns>
|
||
private bool IsWavelengthCompatible(double wavelength)
|
||
{
|
||
// 根据红外探测器的波段确定能接收的波长范围
|
||
return Band switch
|
||
{
|
||
InfraredBand.Long => wavelength >= 8 && wavelength <= 14,// 远红外波段(约8-14微米)
|
||
InfraredBand.Medium => wavelength >= 3 && wavelength <= 6,// 中红外波段(约3-6微米)
|
||
_ => false,// 未知波段,默认不匹配
|
||
};
|
||
}
|
||
|
||
/// <summary>
|
||
/// 更新红外探测器的工作状态
|
||
/// </summary>
|
||
/// <param name="deltaTime">自上次更新以来的时间间隔,单位:秒</param>
|
||
public override void Update(double deltaTime)
|
||
{
|
||
// 先调用基类的Update方法,处理干扰状态等通用逻辑
|
||
base.Update(deltaTime);
|
||
|
||
// 基类的Update方法会在合适的时候调用UpdateSensor
|
||
}
|
||
|
||
/// <summary>
|
||
/// 更新红外探测器特定功能
|
||
/// </summary>
|
||
/// <param name="deltaTime">时间步长,单位:秒</param>
|
||
protected override void UpdateSensor(double deltaTime)
|
||
{
|
||
// 获取当前位置和朝向(从submunition中)
|
||
Position = submunition.Position;
|
||
Orientation = submunition.Orientation;
|
||
|
||
// 更新辐射强度(目标信号)
|
||
double radiationIntensity = GetCurrentDirectionRadiationIntensity();
|
||
|
||
// 更新传感器数据
|
||
sensorData.Temperature = radiationIntensity; // 使用辐射强度更新温度
|
||
sensorData.IsTargetDetected = radiationIntensity > DetectionRadiationIntensityThreshold;
|
||
sensorData.Timestamp = DateTime.Now;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 获取当前方向上的红外辐射强度
|
||
/// </summary>
|
||
/// <returns>当前方向上的红外辐射强度,单位:瓦特/球面度</returns>
|
||
/// <remarks>
|
||
/// 测量过程:
|
||
/// - 检查目标是否在视场内
|
||
/// - 计算辐射强度
|
||
/// - 返回测量结果
|
||
/// 目标存在时返回100,不存在时返回0
|
||
/// </remarks>
|
||
private double GetCurrentDirectionRadiationIntensity()
|
||
{
|
||
// 获取当前方向上的辐射强度,如果检测到目标,则返回目标的辐射强度,否则返回0
|
||
var result = submunition.DetectTarget(FieldOfView);
|
||
if (result.Angle != null && result.Target != null)
|
||
{
|
||
sensorData.TargetAngle = result.Angle;
|
||
return result.Target.Properties.InfraredRadiationIntensity;
|
||
}
|
||
sensorData.TargetAngle = null;
|
||
return 0;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 获取红外探测器的最新数据
|
||
/// </summary>
|
||
/// <returns>包含探测结果的数据对象</returns>
|
||
/// <remarks>
|
||
/// 返回数据:
|
||
/// - 目标探测状态
|
||
/// - 温度测量结果
|
||
/// - 时间戳信息
|
||
/// </remarks>
|
||
public override SensorData GetSensorData()
|
||
{
|
||
return sensorData;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 处理红外干扰应用
|
||
/// </summary>
|
||
protected override void HandleJammingApplied(JammingParameters parameters)
|
||
{
|
||
base.HandleJammingApplied(parameters);
|
||
if (parameters.Type == JammingType.Infrared)
|
||
{
|
||
Debug.WriteLine($"红外探测器受到干扰,功率:{parameters.Power}瓦特");
|
||
sensorData.IsValid = false;
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 处理红外干扰清除
|
||
/// </summary>
|
||
protected override void HandleJammingCleared(JammingType type)
|
||
{
|
||
base.HandleJammingCleared(type);
|
||
if (type == JammingType.Infrared)
|
||
{
|
||
Debug.WriteLine("红外探测器干扰已清除");
|
||
sensorData.IsValid = true;
|
||
}
|
||
}
|
||
}
|
||
} |