private static void ConversionIntegrityTest(float altitude) { float derivedPressure = StaticPressureHelper.GetPressure(altitude, SeaLevelStaticPressure); float derivedAltitude = StaticPressureHelper.GetAltitude(derivedPressure, SeaLevelStaticPressure); AssertWithin(derivedAltitude, altitude, 0.001f); }
public void GetPressureTest() { float altitude, expected, actual; // All expected values are taken from a lookup table altitude = 11000f; expected = 22632f; actual = StaticPressureHelper.GetPressure(altitude, SeaLevelStaticPressure); AssertWithin(actual, expected, 100); altitude = 0f; expected = 101325f; actual = StaticPressureHelper.GetPressure(altitude, SeaLevelStaticPressure); AssertWithin(actual, expected, 100); altitude = 5000f; expected = 54019f; actual = StaticPressureHelper.GetPressure(altitude, SeaLevelStaticPressure); AssertWithin(actual, expected, 100); }
public float GetSimulatedStaticPressure(float trueAltitude) { float truePressure = StaticPressureHelper.GetPressure(trueAltitude, SeaLevelStaticPresure); // If we assume the pressure is rising linearly (although it is not) we would want to further distort the // measured pressure by applying non-linearity to the readings. Vector2 lowestPressurePlot = GetPressurePlot(StaticPressureHelper.MinAltitude); Vector2 highestPressurePlot = GetPressurePlot(StaticPressureHelper.MaxAltitude); var pressurePlot = new Vector2(trueAltitude, truePressure); // float nonLinearPressure = NonLinearity.SinusOffset(pressurePlot, lowestPressurePlot, highestPressurePlot).Y; float nonLinearPressure = NonLinearity.SinusOffset(pressurePlot, lowestPressurePlot, highestPressurePlot, 5f, 100).Y; // Noise amplitude is selected to give a few meters of variation, both positive and negative const float pressurePerMeter = 11.989f; const float noiseAmplitudeMeters = 0.5f; const float noiseAmplitudePressure = noiseAmplitudeMeters * pressurePerMeter; return(Noise.WhiteNoise(nonLinearPressure, noiseAmplitudePressure)); }
private Vector2 GetPressurePlot(float altitude) { return(new Vector2(altitude, StaticPressureHelper.GetPressure(altitude, SeaLevelStaticPresure))); }