Skip to content

Commit e7bbd78

Browse files
Air density mechanism optimized.
SIL-tested: OK.
1 parent 77c12af commit e7bbd78

File tree

1 file changed

+43
-23
lines changed

1 file changed

+43
-23
lines changed

NAV_Algorithms/atmosphere.h

Lines changed: 43 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
#include "embedded_math.h"
3030
#include <air_density_observer.h>
3131
#include "NAV_tuning_parameters.h"
32-
#include <pt2.h>
32+
#include "system_configuration.h"
3333

3434
#define RECIP_STD_DENSITY_TIMES_2 1.632f
3535

@@ -56,8 +56,8 @@ class atmosphere_t
5656
extrapolated_sea_level_pressure(101325),
5757
GNSS_altitude_based_density_available(false),
5858
GNSS_altitude_based_density(1.2255f),
59-
old_density_correction(1.0f),
6059
weight_sum(0.0f),
60+
density_measurement_number(0),
6161
density_factor_weighed_sum(0.0f)
6262
{
6363
}
@@ -130,29 +130,48 @@ class atmosphere_t
130130
return extrapolated_sea_level_pressure;
131131
}
132132

133-
void air_density_metering( float pressure, float MSL_altitude)
134-
{
135-
air_data_result result = air_density_observer.feed_metering( pressure, MSL_altitude);
136-
if( result.valid)
137-
{
138-
#if USE_AIR_DENSITY_LETHARGY
139-
bool first_measurement = (weight_sum == 0.0f);
140-
141-
weight_sum = weight_sum * AIR_DENSITY_LETHARGY + (1.0f - AIR_DENSITY_LETHARGY) / result.density_variance;
142-
density_factor_weighed_sum = density_factor_weighed_sum * AIR_DENSITY_LETHARGY + (1.0f - AIR_DENSITY_LETHARGY) * result.density_correction / result.density_variance;
143-
144-
// postpone update unless we have two measurements
145-
if( ! first_measurement)
133+
void air_density_metering (float pressure, float MSL_altitude)
134+
{
135+
air_data_result result = air_density_observer.feed_metering (pressure,
136+
MSL_altitude);
137+
if (result.valid)
138+
{
139+
if (density_measurement_number < 3)
140+
++density_measurement_number;
141+
142+
weight_sum = weight_sum * AIR_DENSITY_LETHARGY
143+
+ (1.0f - AIR_DENSITY_LETHARGY) / result.density_variance;
144+
density_factor_weighed_sum = density_factor_weighed_sum
145+
* AIR_DENSITY_LETHARGY
146+
+ (1.0f - AIR_DENSITY_LETHARGY) * result.density_correction
147+
/ result.density_variance;
148+
149+
// postpone update unless we have two measurements
150+
switch (density_measurement_number)
151+
{
152+
case 1:
153+
first_result = result; // remember and wait for better statistics
154+
// honorize trend for the moment
155+
density_correction = (1.0f + result.density_correction) * 0.5f;
156+
break;
157+
case 2:
158+
// use variance-weighed sum of both measurements
159+
density_correction = (first_result.density_correction
160+
/ first_result.density_variance
161+
+ result.density_correction / result.density_variance)
162+
/ (1.0f / first_result.density_variance
163+
+ 1.0f / result.density_variance);
164+
break;
165+
default:
166+
// use IIR-filtered weighed sum of measurements
146167
density_correction = density_factor_weighed_sum / weight_sum;
168+
break;
147169

148-
extern void report_desity_parameters( float, float, float, float);
149-
report_desity_parameters( density_correction, density_factor_weighed_sum, weight_sum, result.density_variance);
170+
}
150171

151-
#else
152-
density_correction = result.density_correction;
153-
#endif
154-
}
155-
}
172+
LIMIT_DENSITY_CORRECTION (density_correction);
173+
}
174+
}
156175

157176
private:
158177
float calculateGasConstantHumAir(
@@ -169,8 +188,9 @@ extern void report_desity_parameters( float, float, float, float);
169188
air_density_observer_t air_density_observer;
170189
bool GNSS_altitude_based_density_available;
171190
float GNSS_altitude_based_density;
172-
float old_density_correction;
191+
air_data_result first_result;
173192
float weight_sum;
193+
uint8_t density_measurement_number;
174194
float density_factor_weighed_sum;
175195
};
176196

0 commit comments

Comments
 (0)