修改激光驾束仪的制导指令发送方法

This commit is contained in:
Tian jianyong 2025-04-02 12:35:47 +08:00
parent 5552d55940
commit 4631841f57
5 changed files with 148 additions and 14 deletions

View File

@ -0,0 +1,40 @@
---
description: Base Guidelines for Sonnet-3.7 + Cursor Agent
globs: *,**/*
alwaysApply: true
---
# prompts-claude-sonnet-37-rule-claude-sonnet-37.md
# ---------------------------------------------------------------
# DESCRIPTION:
# this rule helps to better control sonnet-3.7 + cursor. (like doing to much, creating unnecessary new files e.g.).
# especially the first two rules give the cursor agent already the most important instructions that worked for me.
#
# ❗ ATTENTION:
# 1. this does not work so easily for large codebases
# 2. remove everything from these rules that you do not need
# 3. also remove this comments
# ---------------------------------------------------------------
# Instructions
1. Always use codebase_search with target_directories="{{ThreatSource/src}}" first to find existing core files
2. Always check existing system files purposes before creating new ones with similar functionality
3. Always list the cursor rules youre using
# Optional
- If a prompt or request specifies certain behaviors, languages, or output formats, you must obey them without deviation.
- Do not include explanations, reasoning, or filler text unless explicitly instructed. Stick strictly to the requested output.
- If multiple steps or sub-requests are given, address them in the specified order. Provide answers in the exact format or sequence requested.
- Pay close attention to all stated constraints (e.g., language choice, performance goals, coding style). Do not ignore any requirement or best practice stated.
- Only produce output relevant to the question or instructions. Do not add features, code, or details beyond what is explicitly asked.
- Deliver the response in a minimal yet complete form. Avoid unnecessary verbosity and tangential remarks.
- If the prompt requests a specific output format (e.g., a fenced code block, bullet points, JSON), follow that format exactly.
- If a prompt includes a pre-seeded answer structure (e.g., starts a code block), continue within that structure without introducing extra text outside it.
- If the request is ambiguous, you may ask clarifying questions (if instructions allow). Otherwise, state briefly that more information is needed.
- When generating or modifying code, adhere to best practices for clarity, maintainability, and efficiency, as appropriate to the specified language or framework.
- Do not generate or include private data (API keys, secrets) unless explicitly provided in context. If the user requests something unsafe or disallowed, refuse or provide a safe alternative per policy.

View File

@ -27,8 +27,8 @@
}
},
"LaserBeamRiderGuidanceConfig": {
"minDetectablePower": 1e-3,
"detectorDiameter": 0.1,
"minDetectablePower": 1e-10,
"detectorDiameter": 0.03,
"controlFieldDiameter": 20.0,
"proportionalGain": 30.0,
"integralGain": 0.05,

View File

@ -51,9 +51,9 @@ namespace ThreatSource.Guidance
/// <remarks>
/// 定义了探测器的灵敏度阈值
/// 低于此值时无法有效探测
/// 典型值为1
/// 典型值为1e-10
/// </remarks>
private const double MinDetectablePower = 1e-3;
private const double MinDetectablePower = 1e-10;
/// <summary>
/// 探测器直径,单位:米
@ -61,9 +61,9 @@ namespace ThreatSource.Guidance
/// <remarks>
/// 定义了探测器的物理尺寸
/// 影响系统的接收能力
/// 典型值为0.1
/// 典型值为0.03
/// </remarks>
private const double DetectorDiameter = 0.1;
private const double DetectorDiameter = 0.03;
/// <summary>
/// 控制场直径,单位:米
@ -71,9 +71,9 @@ namespace ThreatSource.Guidance
/// <remarks>
/// 定义了有效制导范围
/// 超出此范围将失去制导
/// 典型值为20
/// 典型值为6
/// </remarks>
private const double ControlFieldDiameter = 20.0;
private const double ControlFieldDiameter = 6.0;
/// <summary>
/// 上一次的误差向量
@ -93,6 +93,16 @@ namespace ThreatSource.Guidance
/// </remarks>
public Vector3D LastGuidanceAcceleration { get; private set; }
/// <summary>
/// 偏航角偏差
/// </summary>
public double YawAngleOffset { get; private set; }
/// <summary>
/// 俯仰角偏差
/// </summary>
public double PitchAngleOffset { get; private set; }
/// <summary>
/// 积分误差向量
/// </summary>
@ -194,6 +204,9 @@ namespace ThreatSource.Guidance
base.Activate();
// 在这里订阅事件,确保只订阅一次
SimulationManager.SubscribeToEvent<LaserJammingEvent>(OnLaserJamming);
SimulationManager.SubscribeToEvent<LaserBeamStartEvent>(OnLaserBeamStart);
SimulationManager.SubscribeToEvent<LaserBeamUpdateEvent>(OnLaserBeamUpdate);
SimulationManager.SubscribeToEvent<LaserBeamStopEvent>(OnLaserBeamStop);
}
/// <summary>
@ -204,6 +217,9 @@ namespace ThreatSource.Guidance
base.Deactivate();
// 取消订阅事件
SimulationManager.UnsubscribeFromEvent<LaserJammingEvent>(OnLaserJamming);
SimulationManager.UnsubscribeFromEvent<LaserBeamStartEvent>(OnLaserBeamStart);
SimulationManager.UnsubscribeFromEvent<LaserBeamUpdateEvent>(OnLaserBeamUpdate);
SimulationManager.UnsubscribeFromEvent<LaserBeamStopEvent>(OnLaserBeamStop);
}
/// <summary>
@ -426,10 +442,13 @@ namespace ThreatSource.Guidance
Debug.WriteLine($"激光驾束引导系统: 在控制场内, 距离: {shortestDistance}");
// 计算导弹到激光源的距离
Vector3D missileToSource = LaserSourcePosition - Position;
double distance = missileToSource.Magnitude();
// 计算接收到的激光功率
double beamArea = Math.PI * Math.Pow(config.ControlFieldDiameter / 2, 2);
double powerDensity = LaserPower / beamArea;
double receivedPower = powerDensity * (Math.PI * Math.Pow(config.DetectorDiameter / 2, 2));
double receivedPower = CalculateReceivedLaserPower(distance);
Debug.WriteLine($"激光驾束引导系统: 接收到的激光功率: {receivedPower:E} W");
if(receivedPower >= config.MinDetectablePower)
{
@ -442,6 +461,35 @@ namespace ThreatSource.Guidance
}
}
/// <summary>
/// 计算接收到的激光功率
/// </summary>
/// <param name="distance">传播距离,单位:米</param>
/// <returns>接收到的激光功率,单位:瓦特</returns>
/// <remarks>
/// 计算过程:
/// - 使用距离球面公式计算功率密度
/// - 考虑探测器的有效接收面积
/// - 可选:考虑大气衰减
/// </remarks>
private double CalculateReceivedLaserPower(double distance)
{
// 使用距离球面公式计算功率密度
double powerDensity = LaserPower / (4 * Math.PI * Math.Pow(distance, 2));
// 计算探测器的有效接收面积
double detectorArea = Math.PI * Math.Pow(config.DetectorDiameter / 2, 2);
// 计算接收功率
double receivedPower = powerDensity * detectorArea;
// 考虑大气衰减(可选)
// double atmosphericTransmittance = Math.Exp(-attenuationCoefficient * distance);
// receivedPower *= atmosphericTransmittance;
return receivedPower;
}
/// <summary>
/// 计算制导加速度
/// </summary>
@ -670,6 +718,9 @@ namespace ThreatSource.Guidance
// 更新激光波束参数
LaserPower = evt.BeamPower;
YawAngleOffset = evt.YawAngleOffset;
PitchAngleOffset = evt.PitchAngleOffset;
LaserIlluminationOn = true;
HasGuidance = true;
}

View File

@ -171,7 +171,11 @@ namespace ThreatSource.Indicator
Vector3D targetPosition = target.Position;
LaserDirection = (targetPosition - Position).Normalize();
Debug.WriteLine($"激光驾束仪 {Id} 更新激光指向: {LaserDirection}");
PublishLaserBeamUpdateEvent();
if (MissileId != null && SimulationManager.GetEntityById(MissileId) is SimulationElement missile)
{
var (yawAngleOffset, pitchAngleOffset) = CalculateAngularDeviation(missile.Position);
PublishLaserBeamUpdateEvent(yawAngleOffset, pitchAngleOffset);
}
}
}
}
@ -325,11 +329,13 @@ namespace ThreatSource.Indicator
/// 通知仿真系统激光波束状态已更新
/// 包含最新的位置和方向信息
/// </remarks>
private void PublishLaserBeamUpdateEvent()
private void PublishLaserBeamUpdateEvent(double yawAngleOffset, double pitchAngleOffset)
{
PublishEvent(new LaserBeamUpdateEvent
{
LaserBeamRiderId = Id
LaserBeamRiderId = Id,
YawAngleOffset = yawAngleOffset,
PitchAngleOffset = pitchAngleOffset
});
}
@ -434,5 +440,26 @@ namespace ThreatSource.Indicator
}
}
}
/// <summary>
/// 计算导弹相对于激光轴的角度偏差
/// </summary>
/// <param name="missilePosition">导弹位置</param>
/// <returns>(偏航角偏差, 俯仰角偏差),单位:弧度</returns>
private (double yaw, double pitch) CalculateAngularDeviation(Vector3D missilePosition)
{
// 计算导弹相对于激光源的位置向量
Vector3D relativePosition = missilePosition - Position;
Vector3D missileDirection = relativePosition.Normalize();
// 偏航角XZ平面内的偏差绕Y轴的旋转
double yawAngle = Math.Atan2(missileDirection.X, missileDirection.Z) -
Math.Atan2(LaserDirection.X, LaserDirection.Z);
// 俯仰角与XZ平面的夹角绕X轴的旋转
double pitchAngle = Math.Asin(missileDirection.Y) - Math.Asin(LaserDirection.Y);
return (yawAngle, pitchAngle);
}
}
}

View File

@ -338,6 +338,22 @@ namespace ThreatSource.Simulation
/// 用于抗干扰和安全识别
/// </remarks>
public LaserCodeConfig? LaserCodeConfig { get; set; }
/// <summary>
/// 设置偏航角偏差
/// </summary>
/// <remarks>
/// 偏航角偏差
/// </remarks>
public double YawAngleOffset { get; set; }
/// <summary>
/// 设置俯仰角偏差
/// </summary>
/// <remarks>
/// 俯仰角偏差
/// </remarks>
public double PitchAngleOffset { get; set; }
}
/// <summary>