PX4 Firmware
PX4 Autopilot Software http://px4.io
AirspeedValidator.hpp
Go to the documentation of this file.
1 /****************************************************************************
2  *
3  * Copyright (c) 2019 PX4 Development Team. All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * 1. Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  * notice, this list of conditions and the following disclaimer in
13  * the documentation and/or other materials provided with the
14  * distribution.
15  * 3. Neither the name PX4 nor the names of its contributors may be
16  * used to endorse or promote products derived from this software
17  * without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
22  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
23  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
24  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
25  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
26  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
27  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
29  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30  * POSSIBILITY OF SUCH DAMAGE.
31  *
32  ****************************************************************************/
33 
34 /**
35  * @file AirspeedValidator.hpp
36  * Calculates airspeed from differential pressure and checks if this airspeed is valid.
37  */
38 
39 #pragma once
40 
41 #include <airspeed/airspeed.h>
44 
45 
46 using matrix::Dcmf;
47 using matrix::Quatf;
48 using matrix::Vector2f;
49 using matrix::Vector3f;
50 
51 using namespace time_literals;
52 
54  uint64_t timestamp;
58  float lpos_vx;
59  float lpos_vy;
60  float lpos_vz;
61  bool lpos_valid;
62  float lpos_evh;
63  float lpos_evv;
64  float att_q[4];
67  float accel_z;
71 };
72 
74 {
75 public:
76  AirspeedValidator() = default;
77  ~AirspeedValidator() = default;
78 
79  void update_airspeed_validator(const airspeed_validator_update_data &input_data);
80 
81  float get_IAS() { return _IAS; }
82  float get_EAS() { return _EAS; }
83  float get_TAS() { return _TAS; }
84  bool get_airspeed_valid() { return _airspeed_valid; }
85  float get_EAS_scale() {return _EAS_scale;}
86 
87  wind_estimate_s get_wind_estimator_states(uint64_t timestamp);
88 
89  // setters wind estimator parameters
90  void set_wind_estimator_wind_p_noise(float wind_sigma) { _wind_estimator.set_wind_p_noise(wind_sigma); }
91  void set_wind_estimator_tas_scale_p_noise(float tas_scale_sigma) { _wind_estimator.set_tas_scale_p_noise(tas_scale_sigma); }
92  void set_wind_estimator_tas_noise(float tas_sigma) { _wind_estimator.set_tas_noise(tas_sigma); }
93  void set_wind_estimator_beta_noise(float beta_var) { _wind_estimator.set_beta_noise(beta_var); }
94  void set_wind_estimator_tas_gate(uint8_t gate_size)
95  {
96  _tas_gate = gate_size;
97  _wind_estimator.set_tas_gate(gate_size);
98  }
99 
100  void set_wind_estimator_beta_gate(uint8_t gate_size) { _wind_estimator.set_beta_gate(gate_size); }
101  void set_wind_estimator_scale_estimation_on(bool scale_estimation_on) { _wind_estimator_scale_estimation_on = scale_estimation_on;}
102 
103  void set_airspeed_scale_manual(float airspeed_scale_manual);
104 
105  // setters for failure detection tuning parameters
106  void set_tas_innov_threshold(float tas_innov_threshold) { _tas_innov_threshold = tas_innov_threshold; }
107  void set_tas_innov_integ_threshold(float tas_innov_integ_threshold) { _tas_innov_integ_threshold = tas_innov_integ_threshold; }
108  void set_checks_fail_delay(float checks_fail_delay) { _checks_fail_delay = checks_fail_delay; }
109  void set_checks_clear_delay(float checks_clear_delay) { _checks_clear_delay = checks_clear_delay; }
110 
111  void set_airspeed_stall(float airspeed_stall) { _airspeed_stall = airspeed_stall; }
112 
113 private:
114 
115  WindEstimator _wind_estimator{}; ///< wind estimator instance running in this particular airspeedValidator
116 
117  // wind estimator parameter
118  bool _wind_estimator_scale_estimation_on{false}; ///< online scale estimation (IAS-->CAS/EAS) is on
119  float _airspeed_scale_manual{1.0f}; ///< manually entered airspeed scale
120 
121  // general states
122  bool _in_fixed_wing_flight{false}; ///< variable to bypass innovation and load factor checks
123  float _IAS{0.0f}; ///< indicated airsped in m/s
124  float _EAS{0.0f}; ///< equivalent airspeed in m/s
125  float _TAS{0.0f}; ///< true airspeed in m/s
126  float _EAS_scale{1.0f}; ///< scale factor from IAS to EAS
127 
128  uint64_t _time_last_airspeed{0}; ///< time last airspeed measurement was received (uSec)
129 
130  // states of data stopped check
131  bool _data_stopped_failed{false}; ///< data_stopp check has detected failure
132  hrt_abstime _previous_airspeed_timestamp{0}; ///< timestamp from previous measurement input, to check validity of measurement
133 
134  // states of innovation check
135  float _tas_gate{1.0f}; ///< gate size of airspeed innovation (to calculate tas_test_ratio)
136  bool _innovations_check_failed{false}; ///< true when airspeed innovations have failed consistency checks
137  float _tas_innov_threshold{1.0}; ///< innovation error threshold for triggering innovation check failure
138  float _tas_innov_integ_threshold{-1.0}; ///< integrator innovation error threshold for triggering innovation check failure
139  uint64_t _time_last_aspd_innov_check{0}; ///< time airspeed innovation was last checked (uSec)
140  uint64_t _time_last_tas_pass{0}; ///< last time innovation checks passed
141  uint64_t _time_last_tas_fail{0}; ///< last time innovation checks failed
142  float _apsd_innov_integ_state{0.0f}; ///< inegral of excess normalised airspeed innovation (sec)
143  static constexpr uint64_t TAS_INNOV_FAIL_DELAY{1_s}; ///< time required for innovation levels to pass or fail (usec)
144  uint64_t _time_wind_estimator_initialized{0}; ///< time last time wind estimator was initialized (uSec)
145 
146  // states of load factor check
147  bool _load_factor_check_failed{false}; ///< load_factor check has detected failure
148  float _airspeed_stall{8.0f}; ///< stall speed of aircraft used for load factor check
149  float _load_factor_ratio{0.5f}; ///< ratio of maximum load factor predicted by stall speed to measured load factor
150 
151  // states of airspeed valid declaration
152  bool _airspeed_valid{false}; ///< airspeed valid (pitot or groundspeed-windspeed)
153  int _checks_fail_delay{3}; ///< delay for airspeed invalid declaration after single check failure (Sec)
154  int _checks_clear_delay{3}; ///< delay for airspeed valid declaration after all checks passed again (Sec)
155  bool _airspeed_failing{false}; ///< airspeed sensor checks have detected failure, but not yet declared failed
156  uint64_t _time_checks_passed{0}; ///< time the checks have last passed (uSec)
157  uint64_t _time_checks_failed{0}; ///< time the checks have last not passed (uSec)
158 
159  void update_in_fixed_wing_flight(bool in_fixed_wing_flight) { _in_fixed_wing_flight = in_fixed_wing_flight; }
160 
161  void update_wind_estimator(const uint64_t timestamp, float airspeed_true_raw, bool lpos_valid, float lpos_vx,
162  float lpos_vy,
163  float lpos_vz,
164  float lpos_evh, float lpos_evv, const float att_q[4]);
165  void update_EAS_scale();
166  void update_EAS_TAS(float air_pressure_pa, float air_temperature_celsius);
167  void check_airspeed_innovation(uint64_t timestamp, float estimator_status_vel_test_ratio,
168  float estimator_status_mag_test_ratio);
169  void check_load_factor(float accel_z);
170  void update_airspeed_valid_status(const uint64_t timestamp);
171 
172 };
void set_wind_estimator_beta_noise(float beta_var)
void set_wind_estimator_tas_scale_p_noise(float tas_scale_sigma)
void set_wind_estimator_tas_noise(float tas_sigma)
Dcm< float > Dcmf
Definition: Dcm.hpp:185
void set_wind_estimator_wind_p_noise(float wind_sigma)
void set_checks_fail_delay(float checks_fail_delay)
void set_wind_estimator_tas_gate(uint8_t gate_size)
A wind and airspeed scale estimator.
void set_airspeed_stall(float airspeed_stall)
void set_checks_clear_delay(float checks_clear_delay)
void update_in_fixed_wing_flight(bool in_fixed_wing_flight)
Vector2< float > Vector2f
Definition: Vector2.hpp:69
__BEGIN_DECLS typedef uint64_t hrt_abstime
Absolute time, in microsecond units.
Definition: drv_hrt.h:58
Vector3< float > Vector3f
Definition: Vector3.hpp:136
Quaternion< float > Quatf
Definition: Quaternion.hpp:544
void set_tas_innov_threshold(float tas_innov_threshold)
void set_tas_innov_integ_threshold(float tas_innov_integ_threshold)
void set_wind_estimator_scale_estimation_on(bool scale_estimation_on)
void set_wind_estimator_beta_gate(uint8_t gate_size)