39 #include "airspeedsettings.h"
40 #include "baroairspeed.h"
43 #if defined(PIOS_INCLUDE_ETASV3)
45 #define SAMPLING_DELAY_MS_ETASV3 50 //Update at 20Hz
46 #define ETS_AIRSPEED_SCALE 1.0f //???
47 #define CALIBRATION_IDLE_MS 2000 //Time to wait before calibrating, in [ms]
48 #define CALIBRATION_COUNT_MS 2000 //Time to spend calibrating, in [ms]
49 #define CALIBRATION_COUNT_IDLE (CALIBRATION_IDLE_MS/SAMPLING_DELAY_MS_ETASV3) //Ticks to wait before calibrating
50 #define CALIBRATION_COUNT (CALIBRATION_COUNT_MS/SAMPLING_DELAY_MS_ETASV3) //Ticks to wait while calibrating
55 static uint16_t calibrationCount = 0;
56 static uint32_t calibrationSum = 0;
63 AirspeedSettingsData airspeedSettingsData;
64 AirspeedSettingsGet(&airspeedSettingsData);
68 if (baroAirspeedData->SensorValue == -1) {
69 baroAirspeedData->BaroConnected = BAROAIRSPEED_BAROCONNECTED_FALSE;
70 baroAirspeedData->CalibratedAirspeed = 0;
75 if (calibrationCount < CALIBRATION_COUNT_IDLE) {
79 }
else if (calibrationCount < CALIBRATION_COUNT_IDLE + CALIBRATION_COUNT) {
81 calibrationSum += baroAirspeedData->SensorValue;
83 if (calibrationCount == CALIBRATION_COUNT_IDLE + CALIBRATION_COUNT) {
84 airspeedSettingsData.ZeroPoint = (uint16_t) roundf(((
float)calibrationSum) / CALIBRATION_COUNT);
85 AirspeedSettingsZeroPointSet( &airspeedSettingsData.ZeroPoint );
92 float calibratedAirspeed;
93 if (baroAirspeedData->SensorValue > airspeedSettingsData.ZeroPoint)
94 calibratedAirspeed = ETS_AIRSPEED_SCALE * sqrtf(baroAirspeedData->SensorValue - airspeedSettingsData.ZeroPoint);
96 calibratedAirspeed = 0;
98 baroAirspeedData->BaroConnected = BAROAIRSPEED_BAROCONNECTED_TRUE;
99 baroAirspeedData->CalibratedAirspeed = calibratedAirspeed;
104 void baro_airspeedGetETASV3(BaroAirspeedData *baroAirspeedData, uint32_t *lastSysTime, uint8_t airspeedSensorType, int8_t airspeedADCPin)
static uint8_t airspeedSensorType
void baro_airspeedGetETASV3(BaroAirspeedData *baroAirspeedData, uint32_t *lastSysTime, uint8_t airspeedSensorType, int8_t airspeedADCPin)
void PIOS_Thread_Sleep_Until(uint32_t *previous_ms, uint32_t increment_ms)
Includes PiOS and core architecture components.
static uint32_t lastSysTime
int16_t PIOS_ETASV3_ReadAirspeed(void)