ThreatSourceLibaray/docs/articles/intro.md

500 lines
14 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 使用说明
**版本1.1.22**
## 安装和使用
### C#/.NET 版本
#### 1. 下载和部署
1. 下载 ThreatSourceLibrary 包并解压
2. 按照以下标准结构部署文件:
```
MyApplication/
├── MyApp.exe # 您的应用程序
├── lib/ # DLL库目录
│ ├── ThreatSource.dll # 主要的库文件
│ ├── ThreatSource.deps.json # 依赖配置文件
│ ├── ThreatSource.xml # API 文档文件
│ └── AirTransmission.dll # 依赖库
└── data/ # 配置数据目录
├── missiles/ # 导弹配置文件
│ ├── laser_semi_active/
│ ├── laser_beam_rider/
│ ├── ir_command/
│ ├── ir_imaging/
│ ├── mmw/
│ ├── terminal_sensitive/
│ └── composite/
├── indicators/ # 指示器配置文件
│ ├── laser_designators/
│ ├── laser_beam_riders/
│ └── ir_trackers/
├── equipments/ # 目标设备配置文件
├── jammers/ # 干扰机配置文件
├── weathers/ # 天气配置文件
└── warners/ # 告警器配置文件
```
3. 在 Visual Studio 中添加引用:
- 右键项目 -> 添加 -> 引用
- 浏览 -> 选择 lib/ThreatSource.dll
#### 2. 数据配置管理
威胁源库使用智能路径解析系统会自动在DLL上级目录查找 `data` 文件夹。您也可以手动指定数据路径:
```csharp
// 使用自动路径解析(推荐)
var dataManager = new ThreatSourceDataManager();
// 或手动指定数据路径
var dataManager = new ThreatSourceDataManager("C:/MyApp/configs");
```
#### 3. 基本使用示例
```csharp
using ThreatSource.Simulation;
using ThreatSource.Data;
using ThreatSource.Equipment;
using ThreatSource.Utils;
class Program
{
static void Main()
{
try
{
// 1. 创建仿真管理器
var simulationManager = new SimulationManager();
// 2. 创建数据管理器和工厂
var dataManager = new ThreatSourceDataManager();
var factory = new ThreatSourceFactory(dataManager, simulationManager);
// 3. 创建目标
var targetInitialState = new KinematicState
{
Position = new Vector3D(1000, 0, 100),
Orientation = new Orientation(0, 0, 0),
Speed = 0
};
var targetProperties = new EquipmentProperties
{
InfraredRadiationIntensity = 100.0,
MillimeterWaveRadiationIntensity = 50.0
};
var target = new Tank("target1", targetProperties, targetInitialState, simulationManager);
// 4. 创建导弹(使用工厂模式)
var launchParams = new KinematicState
{
Position = new Vector3D(0, 0, 0),
Orientation = new Orientation(0, 0, 0),
Speed = 100
};
// 使用配置文件中的导弹型号
var missile = factory.CreateMissile("missile1", "lsgm_001", "target1", launchParams);
// 5. 注册实体到仿真管理器
simulationManager.RegisterEntity(target.Id, target);
simulationManager.RegisterEntity(missile.Id, missile);
// 6. 激活实体
target.Activate();
missile.Activate();
// 7. 发射导弹
missile.Fire();
// 8. 启动仿真
simulationManager.StartSimulation(0.01); // 10ms时间步长
// 9. 仿真主循环
double totalTime = 0;
double maxTime = 60; // 最大仿真时间60秒
while (missile.IsActive && totalTime < maxTime)
{
simulationManager.Update(0.01);
totalTime += 0.01;
// 可选:输出状态信息
if ((int)(totalTime * 100) % 100 == 0) // 每秒输出一次
{
Console.WriteLine($"时间: {totalTime:F1}s, 导弹位置: {missile.KState.Position}");
}
}
// 10. 停止仿真
simulationManager.StopSimulation();
}
catch (Exception ex)
{
Console.WriteLine($"错误: {ex.Message}");
}
}
}
```
### C++版本
C++项目有两种使用方式:
#### 方式一:动态加载(推荐)
这种方式适合纯C++项目不需要配置CLR支持。
1. 下载 ThreatSourceNative 包并解压
2. 将 bin 目录下的所有 DLL 文件复制到程序目录
3. 将 include/threat_source.h 添加到项目中
4. 按照标准结构部署数据文件
示例代码:
```cpp
#include "threat_source.h"
#include <stdio.h>
int main() {
// 初始化仿真
if (TS_CreateSimulation() != THREATSOURCE_SUCCESS) {
printf("Failed to create simulation\n");
return 1;
}
// 创建导弹(使用配置文件)
const char* missile_id = "missile1";
const char* missile_model = "lsgm_001"; // 激光半主动制导导弹
const char* target_id = "target1";
int result = TS_CreateMissileFromConfig(
missile_id,
missile_model,
target_id,
0, 0, 0, // 初始位置
0, 0, 0 // 初始朝向
);
if (result != THREATSOURCE_SUCCESS) {
char error[256];
TS_GetLastError(error, sizeof(error));
printf("Failed to create missile: %s\n", error);
return 1;
}
// 激活并发射导弹
TS_ActivateMissile(missile_id);
TS_FireMissile(missile_id);
// 仿真主循环
double deltaTime = 0.01;
int is_active = 1;
while (is_active) {
TS_UpdateSimulation(deltaTime);
TS_IsMissileActive(missile_id, &is_active);
}
// 清理
TS_DestroySimulation();
return 0;
}
```
#### 方式二CLR 集成
如果需要使用 .NET 的完整功能,可以选择 CLR 集成方式:
1. 配置项目属性:
- C/C++ -> 常规 -> 公共语言运行时支持:/clr
- 常规 -> 平台工具集Visual Studio 2022 (v143)
- 常规 -> .NET目标框架net8.0
2. 引用 ThreatSource.dll
示例代码:
```cpp
using namespace System;
using namespace ThreatSource::Simulation;
using namespace ThreatSource::Data;
int main() {
try {
// 创建仿真管理器和数据管理器
auto manager = gcnew SimulationManager();
auto dataManager = gcnew ThreatSourceDataManager();
auto factory = gcnew ThreatSourceFactory(dataManager, manager);
// 创建发射参数
auto launchParams = gcnew KinematicState();
launchParams->Position = Vector3D(0, 0, 0);
launchParams->Orientation = Orientation(0, 0, 0);
launchParams->Speed = 100;
// 使用工厂创建导弹
auto missile = factory->CreateMissile("missile1", "lsgm_001", "target1", launchParams);
manager->RegisterEntity(missile->Id, missile);
// 激活并发射导弹
missile->Activate();
missile->Fire();
// 仿真主循环
double deltaTime = 0.01;
while (missile->IsActive) {
manager->Update(deltaTime);
}
return 0;
}
catch (Exception^ e) {
Console::WriteLine("错误: {0}", e->Message);
return 1;
}
}
```
## 支持的导弹类型
威胁源库支持以下导弹类型:
### 1. 激光半主动制导导弹 (LaserSemiActiveGuidance)
- **工作原理**:利用目标反射的激光能量进行制导
- **配置文件**`data/missiles/laser_semi_active/`
- **制导特点**:需要激光目标指示器持续照射目标
### 2. 激光驾束制导导弹 (LaserBeamRiderGuidance)
- **工作原理**:沿着激光束路径飞行
- **配置文件**`data/missiles/laser_beam_rider/`
- **制导特点**跟踪激光束中心线使用PID控制
### 3. 红外指令制导导弹 (InfraredCommandGuidance)
- **工作原理**:通过红外信号接收指令进行制导
- **配置文件**`data/missiles/ir_command/`
- **制导特点**:导弹发射红外信号,地面测角仪跟踪并发送指令
### 4. 红外成像末制导导弹 (InfraredImagingTerminalGuidance)
- **工作原理**:末段使用红外成像进行自主制导
- **配置文件**`data/missiles/ir_imaging/`
- **制导特点**:自主目标识别和跟踪
### 5. 毫米波末制导导弹 (MillimeterWaveTerminalGuidance)
- **工作原理**:末段使用毫米波雷达进行自主制导
- **配置文件**`data/missiles/mmw/`
- **制导特点**:全天候作战能力,抗干扰性强
### 6. 末敏弹 (TerminalSensitiveMissile)
- **工作原理**:母弹释放子弹,子弹螺旋扫描攻击目标
- **配置文件**`data/missiles/terminal_sensitive/`
- **制导特点**:多传感器融合,智能目标识别
### 7. 复合制导导弹 (CompositeGuidance)
- **工作原理**:集成多种制导方式,可串行或并行工作
- **配置文件**`data/missiles/composite/`
- **制导特点**:高可靠性,多重制导保障
## 配置文件格式
威胁源库使用TOML格式的配置文件。以下是激光半主动制导导弹的配置示例
```toml
# 激光半主动制导导弹配置示例
Type = "LaserSemiActiveGuidance"
[Name]
zh = "激光半主动制导导弹-001"
en = "Laser Semi-Active Guidance Missile-001"
[Properties]
Type = "LaserSemiActiveGuidance"
MaxSpeed = 800.0 # 最大速度 (m/s)
MaxFlightTime = 60.0 # 最大飞行时间 (秒)
MaxFlightDistance = 4000.0 # 最大飞行距离 (米)
MaxAcceleration = 50.0 # 最大加速度 (m/s²)
ProportionalNavigationCoefficient = 3.0 # 比例导引系数
LaunchAcceleration = 100.0 # 发射加速度 (m/s²)
MaxEngineBurnTime = 0.1 # 发动机燃烧时间 (秒)
CruiseTime = 5.0 # 巡航时间 (秒)
Mass = 22.0 # 质量 (kg)
ExplosionRadius = 5.0 # 爆炸半径 (米)
HitProbability = 0.9 # 命中概率
SelfDestructHeight = 0.0 # 自毁高度 (米)
[LaserSemiActiveGuidanceConfig]
MaxDetectionRange = 5000.0 # 最大探测距离 (米)
FieldOfViewAngle = 30.0 # 视场角 (度)
LockThreshold = 1.0e-12 # 锁定阈值 (瓦特)
ReflectionCoefficient = 0.2 # 反射系数
TargetReflectiveArea = 1.0 # 目标反射面积 (平方米)
```
## 基本用法
### 初始化仿真系统
```csharp
// 创建仿真管理器
var simulationManager = new SimulationManager();
// 创建数据管理器(自动路径解析)
var dataManager = new ThreatSourceDataManager();
// 创建工厂
var factory = new ThreatSourceFactory(dataManager, simulationManager);
```
### 创建和配置实体
```csharp
// 创建目标
var targetState = new KinematicState
{
Position = new Vector3D(1000, 0, 100),
Orientation = new Orientation(0, 0, 0),
Speed = 0
};
var targetProperties = new EquipmentProperties
{
InfraredRadiationIntensity = 100.0,
MillimeterWaveRadiationIntensity = 50.0
};
var target = new Tank("target1", targetProperties, targetState, simulationManager);
// 创建导弹(从配置文件)
var launchParams = new KinematicState
{
Position = new Vector3D(0, 0, 0),
Orientation = new Orientation(0, 0, 0),
Speed = 100
};
var missile = factory.CreateMissile("missile1", "lsgm_001", "target1", launchParams);
```
### 运行仿真
```csharp
// 注册实体
simulationManager.RegisterEntity(target.Id, target);
simulationManager.RegisterEntity(missile.Id, missile);
// 激活实体
target.Activate();
missile.Activate();
// 发射导弹
missile.Fire();
// 启动仿真
simulationManager.StartSimulation(0.01);
// 仿真循环
while (missile.IsActive)
{
simulationManager.Update(0.01);
}
// 停止仿真
simulationManager.StopSimulation();
```
### 事件处理
```csharp
// 订阅导弹命中事件
simulationManager.SubscribeToEvent<TargetHitEvent>(evt =>
{
Console.WriteLine($"目标 {evt.TargetId} 被导弹 {evt.SenderId} 命中");
});
// 订阅导弹爆炸事件
simulationManager.SubscribeToEvent<MissileExplodeEvent>(evt =>
{
Console.WriteLine($"导弹在位置 {evt.Position} 爆炸");
});
```
## 数据管理
### 获取可用配置
```csharp
var dataManager = new ThreatSourceDataManager();
// 获取所有可用的导弹型号
var availableMissiles = dataManager.GetAvailableMissiles();
foreach (var missileId in availableMissiles)
{
Console.WriteLine($"可用导弹: {missileId}");
}
// 获取特定导弹的配置
var missileData = dataManager.GetMissile("lsgm_001");
Console.WriteLine($"导弹类型: {missileData.Type}");
Console.WriteLine($"最大速度: {missileData.Properties.MaxSpeed} m/s");
```
### 自定义数据路径
```csharp
// 指定自定义数据路径
var customDataManager = new ThreatSourceDataManager("/path/to/custom/data");
// 或在运行时切换
var dataManager = new ThreatSourceDataManager();
// 数据会自动从 DLL上级目录/data 加载
```
## 部署要求
### 最低系统要求
- .NET 8.0 或更高版本
- Windows 10 或更高版本(推荐)
- 至少 100MB 可用磁盘空间
### 依赖项
- Tomlyn (TOML解析库)
- AirTransmission (空气传播计算库)
### 部署检查清单
1. ✅ 确保DLL文件在正确位置
2. ✅ 确保数据文件按标准结构组织
3. ✅ 确保配置文件格式正确TOML
4. ✅ 确保应用程序有读取数据目录的权限
5. ✅ 测试自动路径解析功能
## 更多示例
更多详细示例和高级用法请参考:
- [仿真示例](../examples/Simulation/README.md)
- [集成示例](../examples/Integration/README.md)
## 故障排除
### 常见问题
1. **数据文件未找到**
- 检查数据目录结构是否正确
- 确认DLL和数据目录的相对位置
- 查看调试输出中的路径解析信息
2. **配置文件解析错误**
- 检查TOML文件语法
- 确认必需字段是否存在
- 查看错误日志获取详细信息
3. **导弹创建失败**
- 确认导弹型号在配置文件中存在
- 检查配置文件的完整性
- 验证制导系统配置是否正确