Larus glider flight sensor system 3.9.2024
Software-In-The-Loop test and validation system
Loading...
Searching...
No Matches
atmosphere.cpp
Go to the documentation of this file.
1#include "atmosphere.h"
2#include "embedded_memory.h"
3
12static ROM struct
13{
14 float range1Begin = 223.15f;
15 float range2Begin = 273.16f;
16 float rangeEnd = 333.15f;
17 float s[2][6] =
18 {
19 { 24.8925f, 2.6766f, 0.1327f, 0.0040f, 8.1294e-5f, 1.1624e-6f },
20 { 3.3640e3f, 198.8920f, 5.1247f, 0.0741f, 6.364e-4f, 3.0197e-6f }
21 };
22 float a[2] = { 239.15f, 299.15f };
23} PWS;
24
26#define POT_2(x) ((x)*(x))
27#define POT_3(x) ((x)*(x)*(x))
28#define POT_4(x) ((x)*(x)*(x)*(x))
29#define POT_5(x) ((x)*(x)*(x)*(x)*(x))
30
38float atmosphere_t::calculateSaturationVaporPressure(float temp)
39{
40 if (PWS.range1Begin <= temp && temp < PWS.range2Begin)
41 {
42 return (PWS.s[0][0] + PWS.s[0][1] * ((temp - PWS.a[0]))
43 + PWS.s[0][2] * POT_2((temp - PWS.a[0]))
44 + PWS.s[0][3] * POT_3((temp - PWS.a[0]))
45 + PWS.s[0][4] * POT_4((temp - PWS.a[0]))
46 + PWS.s[0][5] * POT_5((temp - PWS.a[0])));
47 }
48 else if (PWS.range2Begin <= temp && temp <= PWS.rangeEnd)
49 {
50 return (PWS.s[1][0] + PWS.s[1][1] * ((temp - PWS.a[1]))
51 + PWS.s[1][2] * POT_2((temp - PWS.a[1]))
52 + PWS.s[1][3] * POT_3((temp - PWS.a[1]))
53 + PWS.s[1][4] * POT_4((temp - PWS.a[1]))
54 + PWS.s[1][5] * POT_5((temp - PWS.a[1])));
55 }
56 return 0.0f;
57}
58
71float atmosphere_t::calculateGasConstantHumAir(
72 float humidity, float pressure, float temperature)
73{
74 float satVapPressure = calculateSaturationVaporPressure(temperature);
75 float var1 =
76 humidity * satVapPressure / pressure * ONE_MINUS_RATIO_GAS_CONSTANTS;
77
78 return (GAS_CONST_DRY_AIR / (1 - var1));
79}
80
93float atmosphere_t::calculateAirDensity(
94 float humidity, float pressure, float temperature)
95{
96 float abs_temp = (CELSIUS_TO_KELVIN_OFFSET + temperature);
97 float gasConst = calculateGasConstantHumAir(humidity, pressure, abs_temp);
98 return pressure / gasConst / temperature;
99}
float a[2]
float range2Begin
#define POT_4(x)
#define POT_2(x)
float range1Begin
float s[2][6]
#define POT_3(x)
#define POT_5(x)
float rangeEnd
computes properties of earth's atmosphere
#define CELSIUS_TO_KELVIN_OFFSET
Definition atmosphere.h:42
#define ONE_MINUS_RATIO_GAS_CONSTANTS
Definition atmosphere.h:40
#define GAS_CONST_DRY_AIR
Definition atmosphere.h:36
mathematical vector of arbitrary type and size
Definition vector.h:40
settings to allow compiling embedded software on a PC target
#define ROM