Line data Source code
1 : #pragma once 2 : 3 : #include "AP_Baro_Backend.h" 4 : 5 : #if AP_SIM_BARO_ENABLED 6 : 7 : #include <AP_Math/vectorN.h> 8 : 9 : #include <SITL/SITL.h> 10 : 11 : class AP_Baro_SITL : public AP_Baro_Backend { 12 : public: 13 : AP_Baro_SITL(AP_Baro &); 14 : 15 : void update() override; 16 : 17 : // adjust for simulated board temperature 18 : static void temperature_adjustment(float &p, float &T); 19 : 20 : // adjust for wind effects 21 : static float wind_pressure_correction(uint8_t instance); 22 : 23 : protected: 24 : 25 3071068 : void update_healthy_flag(uint8_t instance) override { _frontend.sensors[instance].healthy = healthy(instance); }; 26 : 27 : private: 28 : uint8_t _instance; 29 : SITL::SIM *_sitl; 30 : 31 : // barometer delay buffer variables 32 : struct readings_baro { 33 : uint32_t time; 34 : float data; 35 : }; 36 : uint8_t _store_index; 37 : uint32_t _last_store_time; 38 : static const uint8_t _buffer_length = 50; 39 : VectorN<readings_baro, _buffer_length> _buffer; 40 : 41 : // is the barometer usable for flight 42 : bool healthy(uint8_t instance); 43 : 44 : void _timer(); 45 : bool _has_sample; 46 : uint32_t _last_sample_time; 47 : float _recent_temp; 48 : float _recent_press; 49 : float _last_altitude; 50 : 51 : uint32_t last_drift_delta_t_ms; // allows for integration of drift over time 52 : float total_alt_drift; // integrated altitude drift in metres 53 : }; 54 : #endif // AP_SIM_BARO_ENABLED