2 * This file is part of Cleanflight.
4 * Cleanflight is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * Cleanflight is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with Cleanflight. If not, see <http://www.gnu.org/licenses/>.
23 #include "build/build_config.h"
24 #include "build/debug.h"
26 #include "common/axis.h"
28 #include "config/feature.h"
30 #include "common/maths.h"
31 #include "common/utils.h"
33 #include "fc/config.h"
35 #include "flight/pid.h"
36 #include "flight/wind_estimator.h"
40 #include "navigation/navigation.h"
41 #include "navigation/navigation_private.h"
43 #include "sensors/pitotmeter.h"
45 #include "drivers/pitotmeter/pitotmeter.h"
46 #include "drivers/pitotmeter/pitotmeter_virtual.h"
48 #if defined(USE_WIND_ESTIMATOR) && defined(USE_PITOT_VIRTUAL)
50 static bool virtualPitotStart(pitotDev_t
*pitot
)
56 static bool virtualPitotRead(pitotDev_t
*pitot
)
62 static void virtualPitotCalculate(pitotDev_t
*pitot
, float *pressure
, float *temperature
)
65 float airSpeed
= 0.0f
;
66 if (pitotIsCalibrationComplete()) {
67 if (isEstimatedWindSpeedValid() && STATE(GPS_FIX
)) {
68 uint16_t windHeading
; //centidegrees
69 float windSpeed
= getEstimatedHorizontalWindSpeed(&windHeading
); //cm/s
70 float horizontalWindSpeed
= windSpeed
* cos_approx(CENTIDEGREES_TO_RADIANS(windHeading
- posControl
.actualState
.yaw
)); //yaw int32_t centidegrees
71 airSpeed
= posControl
.actualState
.velXY
- horizontalWindSpeed
; //float cm/s or gpsSol.groundSpeed int16_t cm/s
72 airSpeed
= calc_length_pythagorean_2D(airSpeed
,getEstimatedActualVelocity(Z
)+getEstimatedWindSpeed(Z
));
74 else if (STATE(GPS_FIX
))
76 airSpeed
= calc_length_pythagorean_3D(gpsSol
.velNED
[X
],gpsSol
.velNED
[Y
],gpsSol
.velNED
[Z
]);
79 airSpeed
= pidProfile()->fixedWingReferenceAirspeed
; //float cm/s
83 *pressure
= sq(airSpeed
) * SSL_AIR_DENSITY
/ 20000.0f
+ SSL_AIR_PRESSURE
;
85 *temperature
= SSL_AIR_TEMPERATURE
; // Temperature at standard sea level
88 bool virtualPitotDetect(pitotDev_t
*pitot
)
91 pitot
->calibThreshold
= 0.00001f
;
92 pitot
->start
= virtualPitotStart
;
93 pitot
->get
= virtualPitotRead
;
94 pitot
->calculate
= virtualPitotCalculate
;
95 return feature(FEATURE_GPS
);