Blackbox device type 'file' (SITL) considered working when file handler is available
[inav.git] / src / main / drivers / pitotmeter / pitotmeter_virtual.c
blob525fae31007b03a9a139b064dfbe004e7868df03
1 /*
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/>.
18 #include <stdbool.h>
19 #include <stdint.h>
21 #include <platform.h>
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"
38 #include "io/gps.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)
52 UNUSED(pitot);
53 return true;
56 static bool virtualPitotRead(pitotDev_t *pitot)
58 UNUSED(pitot);
59 return true;
62 static void virtualPitotCalculate(pitotDev_t *pitot, float *pressure, float *temperature)
64 UNUSED(pitot);
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]);
78 else {
79 airSpeed = pidProfile()->fixedWingReferenceAirspeed; //float cm/s
82 if (pressure)
83 *pressure = sq(airSpeed) * SSL_AIR_DENSITY / 20000.0f + SSL_AIR_PRESSURE;
84 if (temperature)
85 *temperature = SSL_AIR_TEMPERATURE; // Temperature at standard sea level
88 bool virtualPitotDetect(pitotDev_t *pitot)
90 pitot->delay = 10000;
91 pitot->calibThreshold = 0.00001f;
92 pitot->start = virtualPitotStart;
93 pitot->get = virtualPitotRead;
94 pitot->calculate = virtualPitotCalculate;
95 return feature(FEATURE_GPS);
97 #endif