2017-04-27 18:44:03 -03:00
|
|
|
|
|
|
|
/* Variometer class by Samuel Tabor
|
|
|
|
|
|
|
|
Manages the estimation of aircraft total energy, drag and vertical air velocity.
|
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <AP_AHRS/AP_AHRS.h>
|
|
|
|
#include <AP_Param/AP_Param.h>
|
2019-03-26 12:29:53 -03:00
|
|
|
#include <Filter/AverageFilter.h>
|
2022-09-29 20:10:41 -03:00
|
|
|
#include <AP_Vehicle/AP_FixedWing.h>
|
2017-04-27 18:44:03 -03:00
|
|
|
|
|
|
|
class Variometer {
|
|
|
|
|
2022-09-29 20:10:41 -03:00
|
|
|
const AP_FixedWing &_aparm;
|
2017-04-27 18:44:03 -03:00
|
|
|
|
|
|
|
// store time of last update
|
2019-08-07 19:33:06 -03:00
|
|
|
uint64_t _prev_update_time;
|
2017-04-27 18:44:03 -03:00
|
|
|
|
2021-04-04 09:17:05 -03:00
|
|
|
float _raw_climb_rate;
|
|
|
|
|
2019-06-23 04:35:33 -03:00
|
|
|
float _aspd_filt_constrained;
|
|
|
|
|
2019-06-22 13:02:35 -03:00
|
|
|
float _expected_thermalling_sink;
|
2017-04-27 18:44:03 -03:00
|
|
|
|
2019-03-26 12:29:53 -03:00
|
|
|
// declares a 5point average filter using floats
|
|
|
|
AverageFilterFloat_Size5 _vdot_filter;
|
|
|
|
|
|
|
|
AverageFilterFloat_Size5 _sp_filter;
|
|
|
|
|
2021-04-04 09:17:05 -03:00
|
|
|
/*
|
|
|
|
low pass filters for various purposes.
|
|
|
|
*/
|
|
|
|
// Climb rate filter for monitoring progress in thermal.
|
2021-06-06 03:47:58 -03:00
|
|
|
LowPassFilter<float> _climb_filter{1/60.0};
|
2021-04-04 09:17:05 -03:00
|
|
|
|
|
|
|
// Fast filter for mavlink/audio vario output.
|
|
|
|
LowPassFilter<float> _audio_filter{1/0.71};
|
|
|
|
|
|
|
|
// Slower filter for deciding to enter THERMAL mode.
|
|
|
|
LowPassFilter<float> _trigger_filter{1/4.06};
|
|
|
|
|
|
|
|
// Longitudinal acceleration bias filter.
|
|
|
|
LowPassFilter<float> _vdotbias_filter{1/60.0};
|
2019-06-28 10:29:04 -03:00
|
|
|
|
2021-02-28 08:54:34 -04:00
|
|
|
// Speed to fly vario filter.
|
|
|
|
LowPassFilter<float> _stf_filter{1/20.0};
|
|
|
|
|
2017-04-27 18:44:03 -03:00
|
|
|
public:
|
2020-04-20 08:11:22 -03:00
|
|
|
struct PolarParams {
|
|
|
|
AP_Float K;
|
|
|
|
AP_Float CD0;
|
|
|
|
AP_Float B;
|
|
|
|
};
|
|
|
|
|
2022-09-29 20:10:41 -03:00
|
|
|
Variometer(const AP_FixedWing &parms, const PolarParams &polarParams);
|
2020-04-20 08:11:22 -03:00
|
|
|
|
2017-04-27 18:44:03 -03:00
|
|
|
float alt;
|
|
|
|
float reading;
|
2020-01-11 11:14:06 -04:00
|
|
|
float tau;
|
2017-04-27 18:44:03 -03:00
|
|
|
|
2020-04-20 08:11:22 -03:00
|
|
|
void update(const float thermal_bank);
|
|
|
|
float calculate_aircraft_sinkrate(float phi) const;
|
2017-04-27 18:44:03 -03:00
|
|
|
|
2021-04-04 09:17:05 -03:00
|
|
|
void reset_climb_filter(float value) { _climb_filter.reset(value);}
|
|
|
|
|
|
|
|
void reset_trigger_filter(float value) { _trigger_filter.reset(value);}
|
|
|
|
|
|
|
|
float get_airspeed(void) const {return _aspd_filt_constrained;};
|
|
|
|
|
|
|
|
float get_displayed_value(void) const {return _audio_filter.get();};
|
|
|
|
|
|
|
|
float get_filtered_climb(void) const {return _climb_filter.get();};
|
2019-06-22 13:02:35 -03:00
|
|
|
|
2021-04-04 09:17:05 -03:00
|
|
|
float get_trigger_value(void) const {return _trigger_filter.get();};
|
2019-06-22 13:02:35 -03:00
|
|
|
|
2021-02-28 08:54:34 -04:00
|
|
|
float get_stf_value(void) const {return _stf_filter.get();};
|
|
|
|
|
2021-02-01 12:26:34 -04:00
|
|
|
float get_exp_thermalling_sink(void) const {return _expected_thermalling_sink;};
|
2019-06-23 04:35:33 -03:00
|
|
|
|
2022-07-14 13:22:24 -03:00
|
|
|
float calculate_circling_time_constant(const float thermal_bank) const;
|
2020-04-20 08:11:22 -03:00
|
|
|
|
|
|
|
private:
|
2022-07-14 13:22:11 -03:00
|
|
|
const PolarParams &_polarParams;
|
2017-04-27 18:44:03 -03:00
|
|
|
};
|
|
|
|
|