File tree Expand file tree Collapse file tree
flight/modules/StateEstimation Expand file tree Collapse file tree Original file line number Diff line number Diff line change 77 * @{
88 *
99 * @file filterbaro.c
10- * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2013.
10+ * @author The LibrePilot Project, http://www.librepilot.org Copyright (C) 2017.
11+ * The OpenPilot Team, http://www.openpilot.org Copyright (C) 2013.
1112 * @brief Barometric altitude filter, calculates altitude offset based on
1213 * GPS altitude offset if available
1314 *
3637
3738// Private constants
3839
39- #define STACK_REQUIRED 128
40- #define INIT_CYCLES 100
40+ #define STACK_REQUIRED 128
41+ #define INIT_CYCLES 500
42+ #define BARO_OFFSET_ALPHA 0.02f
4143
4244// Private types
4345struct data {
@@ -119,7 +121,11 @@ static filterResult filter(stateFilter *self, stateEstimation *state)
119121 // Initialize to current altitude reading at initial location
120122 if (IS_SET (state -> updated , SENSORUPDATES_baro )) {
121123 if (this -> first_run < INIT_CYCLES || !this -> useGPS ) {
122- this -> baroOffset = (((float )(INIT_CYCLES )- this -> first_run ) / (float )(INIT_CYCLES )) * this -> baroOffset + (this -> first_run / (float )(INIT_CYCLES )) * (state -> baro [0 ] + this -> gpsAlt );
124+ if (this -> first_run > INIT_CYCLES - 2 ) {
125+ this -> baroOffset = (state -> baro [0 ] + this -> gpsAlt );
126+ }
127+ // Set baroOffset using filtering, this allow better altitude zeroing
128+ this -> baroOffset = ((1.0f - BARO_OFFSET_ALPHA ) * this -> baroOffset ) + (BARO_OFFSET_ALPHA * (state -> baro [0 ] + this -> gpsAlt ));
123129 this -> baroAlt = state -> baro [0 ];
124130 this -> first_run -- ;
125131 }
You can’t perform that action at this time.
0 commit comments