39 #include "airspeedsettings.h"
40 #include "baroairspeed.h"
43 #if defined(PIOS_INCLUDE_MPXV7002) || defined (PIOS_INCLUDE_MPXV5004) || defined (PIOS_INCLUDE_ADC)
45 #define SAMPLING_DELAY_MS_MPXV 10 //Update at 100Hz
46 #define CALIBRATION_IDLE_MS 2000 //Time to wait before calibrating, in [ms]
47 #define CALIBRATION_COUNT_MS 2000 //Time to spend calibrating, in [ms]
48 #define ANALOG_BARO_AIRSPEED_TIME_CONSTANT_MS 100.0f //Needs to be settable in a UAVO
56 static uint16_t calibrationCount=0;
65 if(airspeedADCPin <0){
66 baroAirspeedData->BaroConnected = BAROAIRSPEED_BAROCONNECTED_FALSE;
72 if (calibrationCount < CALIBRATION_IDLE_MS/SAMPLING_DELAY_MS_MPXV) {
75 }
else if (calibrationCount <= (CALIBRATION_IDLE_MS + CALIBRATION_COUNT_MS)/SAMPLING_DELAY_MS_MPXV) {
78 uint16_t sensorCalibration;
79 #if defined(PIOS_INCLUDE_MPXV7002) || defined (PIOS_INCLUDE_MPXV5004)
80 if(airspeedSensorType==AIRSPEEDSETTINGS_AIRSPEEDSENSORTYPE_DIYDRONESMPXV7002){
81 sensorCalibration=
PIOS_MPXV7002_Calibrate(airspeedADCPin, calibrationCount-CALIBRATION_IDLE_MS/SAMPLING_DELAY_MS_MPXV);
84 else if(airspeedSensorType==AIRSPEEDSETTINGS_AIRSPEEDSENSORTYPE_DIYDRONESMPXV5004){
85 sensorCalibration=
PIOS_MPXV5004_Calibrate(airspeedADCPin, calibrationCount-CALIBRATION_IDLE_MS/SAMPLING_DELAY_MS_MPXV);
91 baroAirspeedData->BaroConnected = BAROAIRSPEED_BAROCONNECTED_TRUE;
94 if (calibrationCount == (CALIBRATION_IDLE_MS + CALIBRATION_COUNT_MS)/SAMPLING_DELAY_MS_MPXV)
95 AirspeedSettingsZeroPointSet(&sensorCalibration);
101 float calibratedAirspeed=0;
102 #if defined(PIOS_INCLUDE_MPXV7002) || defined (PIOS_INCLUDE_MPXV5004)
103 if(airspeedSensorType==AIRSPEEDSETTINGS_AIRSPEEDSENSORTYPE_DIYDRONESMPXV7002){
105 if (calibratedAirspeed < 0)
117 else if(airspeedSensorType==AIRSPEEDSETTINGS_AIRSPEEDSENSORTYPE_DIYDRONESMPXV5004){
119 if (calibratedAirspeed < 0)
133 }
else if (airspeedSensorType == AIRSPEEDSETTINGS_AIRSPEEDSENSORTYPE_RAWANALOG) {
136 baroAirspeedData->SensorValue = calibratedAirspeed;
139 float alpha=SAMPLING_DELAY_MS_MPXV/(SAMPLING_DELAY_MS_MPXV + ANALOG_BARO_AIRSPEED_TIME_CONSTANT_MS);
140 float filteredAirspeed = calibratedAirspeed*(alpha) + baroAirspeedData->CalibratedAirspeed*(1.0f-alpha);
143 baroAirspeedData->CalibratedAirspeed = filteredAirspeed;
149 void baro_airspeedGetAnalog(BaroAirspeedData *baroAirspeedData, uint32_t *lastSysTime, uint8_t airspeedSensorType, int8_t airspeedADCPin)
float PIOS_MPXV5004_ReadAirspeed(uint8_t airspeedADCPin)
void PIOS_MPXV5004_UpdateCalibration(uint16_t zeroPoint)
static uint8_t airspeedSensorType
float PIOS_MPXV7002_ReadAirspeed(uint8_t airspeedADCPin)
void PIOS_MPXV7002_UpdateCalibration(uint16_t zeroPoint)
uint16_t PIOS_MPXV7002_Calibrate(uint8_t airspeedADCPin, uint16_t calibrationCount)
uint16_t PIOS_MPXV7002_Measure(uint8_t airspeedADCPin)
void baro_airspeedGetAnalog(BaroAirspeedData *baroAirspeedData, uint32_t *lastSysTime, uint8_t airspeedSensorType, int8_t airspeedADCPin)
void PIOS_Thread_Sleep_Until(uint32_t *previous_ms, uint32_t increment_ms)
uint16_t PIOS_MPXV5004_Measure(uint8_t airspeedADCPin)
int32_t PIOS_ADC_GetChannelRaw(uint32_t channel)
Includes PiOS and core architecture components.
static uint32_t lastSysTime
uint16_t PIOS_MPXV5004_Calibrate(uint8_t airspeedADCPin, uint16_t calibrationCount)