2 ******************************************************************************
3 * @addtogroup OpenPilotModules OpenPilot Modules
5 * @addtogroup State Estimation
6 * @brief Acquires sensor data and computes state estimate
10 * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2013.
11 * @brief Airspeed filter, calculates true airspeed based on indicated
12 * airspeed and uncorrected barometric altitude
13 * NOTE: This Sensor uses UNCORRECTED barometric altitude for
14 * correction -- run before barometric bias correction!
16 * @see The GNU Public License (GPL) Version 3
18 ******************************************************************************/
20 * This program is free software; you can redistribute it and/or modify
21 * it under the terms of the GNU General Public License as published by
22 * the Free Software Foundation; either version 3 of the License, or
23 * (at your option) any later version.
25 * This program is distributed in the hope that it will be useful, but
26 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
27 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
30 * You should have received a copy of the GNU General Public License along
31 * with this program; if not, write to the Free Software Foundation, Inc.,
32 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
35 #include "inc/stateestimation.h"
39 #define STACK_REQUIRED 64
41 // simple IAS to TAS aproximation - 2% increase per 1000ft
42 // since we do not have flowing air temperature information
43 #define IAS2TAS(alt) (1.0f + (0.02f * (alt) / 304.8f))
52 static int32_t init(stateFilter
*self
);
53 static filterResult
filter(stateFilter
*self
, stateEstimation
*state
);
56 int32_t filterAirInitialize(stateFilter
*handle
)
59 handle
->filter
= &filter
;
60 handle
->localdata
= pios_malloc(sizeof(struct data
));
61 return STACK_REQUIRED
;
64 static int32_t init(stateFilter
*self
)
66 struct data
*this = (struct data
*)self
->localdata
;
68 this->altitude
= 0.0f
;
72 static filterResult
filter(stateFilter
*self
, stateEstimation
*state
)
74 struct data
*this = (struct data
*)self
->localdata
;
76 // take static pressure altitude estimation for
77 if (IS_SET(state
->updated
, SENSORUPDATES_baro
)) {
78 this->altitude
= state
->baro
[0];
80 // calculate true airspeed estimation
81 if (IS_SET(state
->updated
, SENSORUPDATES_airspeed
) && (state
->airspeed
[1] < 0.f
)) {
82 state
->airspeed
[1] = state
->airspeed
[0] * IAS2TAS(this->altitude
);
85 return FILTERRESULT_OK
;