Larus glider flight sensor system 3.9.2024
Software-In-The-Loop test and validation system
Loading...
Searching...
No Matches
variometer.cpp
Go to the documentation of this file.
1/***********************************************************************/
25#include <variometer.h>
27#include "embedded_math.h"
28
29#define ONE_DIV_BY_GRAVITY_TIMES_2 0.0509684f
30#define RECIP_GRAVITY 0.1094f
31
37 float GNSS_negative_altitude,
38 float pressure_altitude,
39 float IAS,
42 )
43{
44 vario_uncompensated_pressure = KalmanVario_pressure.update (
45 pressure_altitude, ahrs_acceleration[DOWN]);
46 speed_compensation_IAS = kinetic_energy_differentiator.respond (
47 IAS * IAS * ONE_DIV_BY_GRAVITY_TIMES_2);
48 vario_averager_pressure.respond (
49 speed_compensation_IAS - vario_uncompensated_pressure); // -> positive on positive energy gain
50
52 {
53 // workaround for no GNSS fix: maintain GNSS vario with pressure data
54 vario_uncompensated_GNSS = vario_uncompensated_pressure;
55 speed_compensation_GNSS = speed_compensation_IAS;
56 vario_averager_GNSS.respond (
57 speed_compensation_IAS - vario_uncompensated_pressure);
58 }
59 else
60 {
61 // The Kalman-filter-based un-compensated variometer in NED-system reports negative if *climbing* !
62 vario_uncompensated_GNSS = -KalmanVario_GNSS.update ( GNSS_negative_altitude, gnss_velocity[DOWN], ahrs_acceleration[DOWN]);
63
64 // 3d acceleration from the AHRS and from the vertical Kalman filter
65 float3vector acceleration = ahrs_acceleration;
66 // the vertical component comes from the Kalman Vario, effective value without gravitation
67 acceleration[DOWN] = KalmanVario_GNSS.get_x ( KalmanVario_PVA_t::ACCELERATION_OBSERVED);
68
69 // horizontal kalman filter for velocity and acceleration in the air- (not ground) system
72
73 // compute our kinetic energy in the air-system
74 specific_energy = (
79
80 // speed-compensation type 1 = scalar product( air_velocity , acceleration) / g;
81 speed_compensation_INS_GNSS_1 = ( gnss_velocity - speed_compensator_wind) * acceleration * RECIP_GRAVITY;
82
83 // speed compensation type 2 = air velocity * acceleration , both Kalman-filtered
84 speed_compensation_kalman_2 =
85 (Kalman_v_a_observer_N.get_x ( Kalman_V_A_Aoff_observer_t::VELOCITY) * Kalman_v_a_observer_N.get_x ( Kalman_V_A_Aoff_observer_t::ACCELERATION)
86 + Kalman_v_a_observer_E.get_x ( Kalman_V_A_Aoff_observer_t::VELOCITY) * Kalman_v_a_observer_E.get_x ( Kalman_V_A_Aoff_observer_t::ACCELERATION)
87 + KalmanVario_GNSS.get_x (KalmanVario_PVA_t::VARIO) * KalmanVario_GNSS.get_x ( KalmanVario_PVA_t::ACCELERATION_OBSERVED))
89
90 // speed compensation type 3 comes from the derivative of the specific energy
91 speed_compensation_energy_3 = specific_energy_differentiator.respond ( specific_energy);
92
93 // speed-compensation type 4 is the product of acceleration and velocity, both calculated along the heading axis
95 kalman_air_velocity[NORTH] = Kalman_v_a_observer_N.get_x ( Kalman_V_A_Aoff_observer_t::VELOCITY);
96 kalman_air_velocity[EAST] = Kalman_v_a_observer_E.get_x ( Kalman_V_A_Aoff_observer_t::VELOCITY);
97 kalman_air_velocity[DOWN] = KalmanVario_GNSS.get_x ( KalmanVario_PVA_t::VARIO);
99
100 acceleration[NORTH] = Kalman_v_a_observer_N.get_x ( Kalman_V_A_Aoff_observer_t::ACCELERATION);
101 acceleration[EAST] = Kalman_v_a_observer_E.get_x ( Kalman_V_A_Aoff_observer_t::ACCELERATION);
102 acceleration[DOWN] = KalmanVario_GNSS.get_x ( KalmanVario_PVA_t::ACCELERATION_OBSERVED);
103 float acceleration_projected = acceleration * heading_vector;
104
105 speed_compensation_projected_4 = air_velocity_projected * acceleration_projected * RECIP_GRAVITY;
106
107 // blending of three mechanisms for speed-compensation
108// speed_compensation_GNSS = GNSS_INS_speedcomp_fusioner.respond( 0.3333333f * (speed_compensation_INS_GNSS_1 + speed_compensation_kalman_2 + speed_compensation_projected_4), speed_compensation_energy_3);
109 speed_compensation_GNSS = GNSS_INS_speedcomp_fusioner.respond( 0.5 * (speed_compensation_INS_GNSS_1 + speed_compensation_kalman_2), speed_compensation_energy_3);
110 vario_averager_GNSS.respond ( vario_uncompensated_GNSS + speed_compensation_GNSS);
111 }
112}
113
114void variometer_t::reset(float pressure_negative_altitude, float GNSS_negative_altitude)
115{
116 KalmanVario_GNSS.reset( GNSS_negative_altitude, -9.81f);
117 KalmanVario_pressure.reset( pressure_negative_altitude, -9.81f);
118}
@ DOWN
Definition AHRS.h:42
@ EAST
Definition AHRS.h:42
@ NORTH
Definition AHRS.h:42
type respond(type HP_input, type LP_input)
void update(const float velocity, const float acceleration)
float update(const float altitude, const float velocity, const float acceleration)
float get_x(state index) const
void reset(const float altitude, const float acceleration_offset)
void reset(const float altitude, const float acceleration_offset)
Definition KalmanVario.h:66
float update(const float altitude, const float acceleration)
datatype respond(const datatype &right)
update differentiator taking next input value
datatype respond(const datatype &input)
Definition pt2.h:79
void update_at_100Hz(const float3vector &gnss_velocity, const float3vector &ahrs_acceleration, const float3vector &heading_vector, float GNSS_altitude, float pressure_altitude, float IAS, const float3vector &wind_average, bool GNSS_fix_avaliable)
calculate instant windspeed and variometer data, update @ 100 Hz
void reset(float pressure_altitude, float GNSS_altitude)
defines platform-dependent algorithms and constants
#define SQR(x)
collection of system tuning parameters
#define RECIP_GRAVITY
#define ONE_DIV_BY_GRAVITY_TIMES_2