airspeed: use floating point values and better averaging in zero_airspeed()
this makes the calibration of airspeed a bit more accurate, and prevents truncation of airspeed values
This commit is contained in:
parent
5d503fd65e
commit
011110e1dd
@ -422,7 +422,7 @@ test_radio(uint8_t argc, const Menu::arg *argv)
|
||||
|
||||
while(1){
|
||||
for(int i = 0; i < 9; i++){
|
||||
Serial.printf_P(PSTR("%u,"),adc.Ch(i));
|
||||
Serial.printf_P(PSTR("%.1f,"),adc.Ch(i));
|
||||
}
|
||||
Serial.println();
|
||||
delay(20);
|
||||
|
@ -364,7 +364,7 @@ static float current_total;
|
||||
// Airspeed Sensors
|
||||
// ----------------
|
||||
static float airspeed_raw; // Airspeed Sensor - is a float to better handle filtering
|
||||
static int airspeed_pressure; // airspeed as a pressure value
|
||||
static float airspeed_pressure; // airspeed as a pressure value
|
||||
|
||||
// Barometer Sensor variables
|
||||
// --------------------------
|
||||
|
@ -80,9 +80,9 @@ static void read_airspeed(void)
|
||||
airspeed_raw = (float)adc.Ch(AIRSPEED_CH);
|
||||
g.airspeed_offset.set_and_save(airspeed_raw);
|
||||
}
|
||||
airspeed_raw = ((float)adc.Ch(AIRSPEED_CH) * .25) + (airspeed_raw * .75);
|
||||
airspeed_pressure = max(((int)airspeed_raw - g.airspeed_offset), 0);
|
||||
airspeed = sqrt((float)airspeed_pressure * g.airspeed_ratio) * 100;
|
||||
airspeed_raw = (adc.Ch(AIRSPEED_CH) * 0.25) + (airspeed_raw * 0.75);
|
||||
airspeed_pressure = max((airspeed_raw - g.airspeed_offset), 0);
|
||||
airspeed = sqrt(airspeed_pressure * g.airspeed_ratio) * 100;
|
||||
#endif
|
||||
|
||||
calc_airspeed_errors();
|
||||
@ -90,12 +90,15 @@ static void read_airspeed(void)
|
||||
|
||||
static void zero_airspeed(void)
|
||||
{
|
||||
airspeed_raw = (float)adc.Ch(AIRSPEED_CH);
|
||||
for(int c = 0; c < 10; c++){
|
||||
delay(20);
|
||||
airspeed_raw = (airspeed_raw * .90) + ((float)adc.Ch(AIRSPEED_CH) * .10);
|
||||
float sum = 0;
|
||||
int c;
|
||||
airspeed_raw = adc.Ch(AIRSPEED_CH);
|
||||
for(c = 0; c < 250; c++) {
|
||||
delay(2);
|
||||
sum += adc.Ch(AIRSPEED_CH);
|
||||
}
|
||||
g.airspeed_offset.set_and_save(airspeed_raw);
|
||||
sum /= c;
|
||||
g.airspeed_offset.set_and_save((int16_t)sum);
|
||||
}
|
||||
|
||||
#endif // HIL_MODE != HIL_MODE_ATTITUDE
|
||||
|
@ -459,7 +459,7 @@ test_adc(uint8_t argc, const Menu::arg *argv)
|
||||
delay(1000);
|
||||
|
||||
while(1){
|
||||
for (int i=0;i<9;i++) Serial.printf_P(PSTR("%u\t"),adc.Ch(i));
|
||||
for (int i=0;i<9;i++) Serial.printf_P(PSTR("%.1f\t"),adc.Ch(i));
|
||||
Serial.println();
|
||||
delay(100);
|
||||
if(Serial.available() > 0){
|
||||
@ -630,9 +630,9 @@ test_mag(uint8_t argc, const Menu::arg *argv)
|
||||
static int8_t
|
||||
test_airspeed(uint8_t argc, const Menu::arg *argv)
|
||||
{
|
||||
unsigned airspeed_ch = adc.Ch(AIRSPEED_CH);
|
||||
float airspeed_ch = adc.Ch(AIRSPEED_CH);
|
||||
// Serial.println(adc.Ch(AIRSPEED_CH));
|
||||
Serial.printf_P(PSTR("airspeed_ch: %u\n"), airspeed_ch);
|
||||
Serial.printf_P(PSTR("airspeed_ch: %.1f\n"), airspeed_ch);
|
||||
|
||||
if (g.airspeed_enabled == false){
|
||||
Serial.printf_P(PSTR("airspeed: "));
|
||||
@ -648,7 +648,7 @@ test_airspeed(uint8_t argc, const Menu::arg *argv)
|
||||
while(1){
|
||||
delay(20);
|
||||
read_airspeed();
|
||||
Serial.printf_P(PSTR("%fm/s\n"), airspeed / 100.0);
|
||||
Serial.printf_P(PSTR("%.1f m/s\n"), airspeed / 100.0);
|
||||
|
||||
if(Serial.available() > 0){
|
||||
return (0);
|
||||
|
Loading…
Reference in New Issue
Block a user