Update the sensor at its sensing frequency

more-targets
Titan Yuan 2024-09-12 22:57:16 -07:00
parent ead655695e
commit 488ddaa836
2 changed files with 6 additions and 8 deletions

View File

@ -6,9 +6,8 @@ public class Micromissile : Missile
{
[SerializeField] private float _navigationGain = 3f; // Typically 3-5
private Vector3 _previousLOS;
private SensorOutput _sensorOutput;
private Vector3 _accelerationCommand;
private float _lastUpdateTime;
private double _elapsedTime = 0;
protected override void UpdateMidCourse(double deltaTime)
{
@ -21,16 +20,15 @@ public class Micromissile : Missile
// Correct the state of the target model at the sensor frequency
float sensorUpdatePeriod = 1f / _agentConfig.dynamic_config.sensor_config.frequency;
if (_elapsedTime - _lastUpdateTime >= sensorUpdatePeriod)
if (_elapsedTime >= sensorUpdatePeriod)
{
// TODO: Implement guidance filter to estimate state from sensor output
// For now, we'll use the target's actual state
// targetModel.SetState(_target.GetState());
_lastUpdateTime = (float)_elapsedTime;
_sensorOutput = GetComponent<Sensor>().Sense(_target);
_elapsedTime = 0;
}
// Sense the target
// Check whether the target should be considered a miss
SensorOutput sensorOutput = GetComponent<Sensor>().Sense(_target);
if(sensorOutput.velocity.range > 1000f) {
this.MarkAsMiss();
@ -38,7 +36,7 @@ public class Micromissile : Missile
}
// Calculate the acceleration input
accelerationInput = CalculateAccelerationCommand(sensorOutput);
accelerationInput = CalculateAccelerationCommand(_sensorOutput);
}
// Calculate and set the total acceleration

View File

@ -45,7 +45,7 @@ public class Missile : Agent
Vector3 rollAxis = transform.forward;
// Calculate boost acceleration
float boostAcceleration = StaticConfig.boostConfig.boostAcceleration * Physics.gravity.magnitude;
float boostAcceleration = (float)(StaticConfig.boostConfig.boostAcceleration * Constants.kGravity);
Vector3 accelerationInput = boostAcceleration * rollAxis;
// Calculate the total acceleration