1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2024-12-01 09:24:10 +01:00

Merge branch 'laurent/OP-1869_Analog_airspeed_scaling' into next

This commit is contained in:
abeck70 2015-05-14 20:22:45 +10:00
commit 87f19dc474
3 changed files with 7 additions and 5 deletions

View File

@ -46,7 +46,7 @@
#define CALIBRATION_IDLE_MS 2000 // Time to wait before calibrating, in [ms]
#define CALIBRATION_COUNT_MS 2000 // Time to spend calibrating, in [ms]
#define ANALOG_BARO_AIRSPEED_TIME_CONSTANT_MS 100 // low pass filter
#define ANALOG_BARO_AIRSPEED_TIME_CONSTANT_MS 256 // low pass filter
// Private types
@ -104,9 +104,10 @@ void baro_airspeedGetMPXV(AirspeedSensorData *airspeedSensor, AirspeedSettingsDa
}
}
sensor.zeroPoint = airspeedSettings->ZeroPoint;
sensor.scale = airspeedSettings->Scale;
// Filter CAS
float alpha = airspeedSettings->SamplePeriod / (airspeedSettings->SamplePeriod + ANALOG_BARO_AIRSPEED_TIME_CONSTANT_MS); // Low pass filter.
// Filter CAS : airspeedSettings->SamplePeriod value is 0 - 255 range
float alpha = 1 - (airspeedSettings->SamplePeriod / ANALOG_BARO_AIRSPEED_TIME_CONSTANT_MS); // Low pass filter.
airspeedSensor->CalibratedAirspeed = PIOS_MPXV_CalcAirspeed(&sensor, airspeedSensor->SensorValue) * (alpha) + airspeedSensor->CalibratedAirspeed * (1.0f - alpha);
airspeedSensor->SensorConnected = AIRSPEEDSENSOR_SENSORCONNECTED_TRUE;

View File

@ -68,8 +68,8 @@ uint16_t PIOS_MPXV_Calibrate(PIOS_MPXV_descriptor *desc, uint16_t measurement)
*/
float PIOS_MPXV_CalcAirspeed(PIOS_MPXV_descriptor *desc, uint16_t measurement)
{
// Calculate dynamic pressure, as per docs
float Qc = 3.3f / 4096.0f * (float)(measurement - desc->zeroPoint);
// Calculate dynamic pressure, as per docs - Apply scale factor (voltage divider)
float Qc = 3.3f / 4096.0f * (float)((measurement - desc->zeroPoint) * desc->scale);
// Saturate Qc on the lower bound, in order to make sure we don't have negative airspeeds. No need
// to saturate on the upper bound, we'll handle that later with calibratedAirspeed.

View File

@ -38,6 +38,7 @@ typedef struct {
uint16_t calibrationCount;
uint32_t calibrationSum;
uint16_t zeroPoint;
float scale;
float maxSpeed;
} PIOS_MPXV_descriptor;