Larus glider flight sensor system 3.9.2024
Software-In-The-Loop test and validation system
Loading...
Searching...
No Matches
air_density_observer.cpp
Go to the documentation of this file.
1/***********************************************************************/
25#include "embedded_math.h"
27
29{
31
32#if DENSITY_MEASURMENT_COLLECTS_INTEGER
33 density_QFF_calculator.add_value( MSL_altitude * 100.0f, pressure);
34#else
35 // use values normalized around 1.0
36 density_QFF_calculator.add_value( MSL_altitude * 1e-3, pressure * 1e-5);
37#endif
38
39 if( MSL_altitude > max_altitude)
40 max_altitude = MSL_altitude;
41
42 if( MSL_altitude < min_altitude)
43 min_altitude = MSL_altitude;
44
45 if( false == altitude_trigger.process(MSL_altitude))
46 return air_data;
47
48 if( ((max_altitude - min_altitude) < MINIMUM_ALTITUDE_RANGE) // ... forget this measurement
49 || (density_QFF_calculator.get_count() < 3000))
50 {
51 max_altitude = min_altitude = MSL_altitude;
52 density_QFF_calculator.reset();
53 return air_data;
54 }
55
57 density_QFF_calculator.evaluate(result);
58
59// Due to numeric effects, when using float the
60// variance has been observed to be negative in some cases !
61// Therefore using float this test can not be used.
62 assert( result.variance_slope > 0);
63 assert( result.variance_offset > 0);
64
65 if( result.variance_slope < MAX_ALLOWED_VARIANCE)
66 {
67 air_data.QFF = (float)(result.y_offset);
68 float density = 100.0f * (float)(result.slope) * -0.10194f; // div by -9.81f;
69
70#if DENSITY_MEASURMENT_COLLECTS_INTEGER
71 float pressure = density_QFF_calculator.get_mean_y();
72#else
73 float pressure = 1e5 * density_QFF_calculator.get_mean_y();
74#endif
75
76 float std_density = 1.0496346613e-5f * pressure + 0.1671546011f;
77 air_data.density_correction = density / std_density;
78 air_data.valid = true;
79 }
80
81 max_altitude = min_altitude = MSL_altitude;
82 density_QFF_calculator.reset();
83
84 return air_data;
85}
air-density measurement (interface)
#define MAX_ALLOWED_VARIANCE
#define MINIMUM_ALTITUDE_RANGE
Maintains offset and slope of the air density measurement.
air_data_result feed_metering(float pressure, float MSL_altitude)
void add_value(const sample_type x, const sample_type y)
sample_type get_mean_y(void) const
void evaluate(evaluation_type &a, evaluation_type &b, evaluation_type &variance_a, evaluation_type &variance_b) const
bool process(float value)
Definition trigger.h:43
mathematical vector of arbitrary type and size
Definition vector.h:40
defines platform-dependent algorithms and constants
#define assert(x)
Definition vector.h:29