From 06c36b8b3042405d0bc95c9b4964541cc9be04ca Mon Sep 17 00:00:00 2001 From: Don Gagne Date: Tue, 7 Jan 2014 17:39:49 -0800 Subject: [PATCH] ind_airspeed used uninitialized when _sensorHilEnabled == false Fixing -Wuninitialized --- src/comm/QGCFlightGearLink.cc | 38 +++++++++++++++++------------------ 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/src/comm/QGCFlightGearLink.cc b/src/comm/QGCFlightGearLink.cc index d75770671..4a044c840 100644 --- a/src/comm/QGCFlightGearLink.cc +++ b/src/comm/QGCFlightGearLink.cc @@ -281,31 +281,31 @@ void QGCFlightGearLink::readBytes() temperature = values.at(19).toFloat(); abs_pressure = values.at(20).toFloat()*1e2; //convert to Pa from hPa + //calculate differential pressure + const float air_gas_constant = 287.1f; // J/(kg * K) + const float absolute_null_celsius = -273.15f; // °C + float density = abs_pressure / (air_gas_constant * (temperature - absolute_null_celsius)); + diff_pressure = true_airspeed * true_airspeed * density / 2.0f; + //qDebug() << "diff_pressure: " << diff_pressure << "abs_pressure: " << abs_pressure; + + /* Calculate indicated airspeed */ + const float air_density_sea_level_15C = 1.225f; //kg/m^3 + if (diff_pressure > 0) + { + ind_airspeed = sqrtf((2.0f*diff_pressure) / air_density_sea_level_15C); + } else + { + ind_airspeed = -sqrtf((2.0f*fabsf(diff_pressure)) / air_density_sea_level_15C); + } + + //qDebug() << "ind_airspeed: " << ind_airspeed << "true_airspeed: " << true_airspeed; + // Send updated state //qDebug() << "sensorHilEnabled: " << sensorHilEnabled; if (_sensorHilEnabled) { quint16 fields_changed = 0xFFF; //set all 12 used bits - //calculate differential pressure - const float air_gas_constant = 287.1f; // J/(kg * K) - const float absolute_null_celsius = -273.15f; // °C - float density = abs_pressure / (air_gas_constant * (temperature - absolute_null_celsius)); - diff_pressure = true_airspeed * true_airspeed * density / 2.0f; - //qDebug() << "diff_pressure: " << diff_pressure << "abs_pressure: " << abs_pressure; - - /* Calculate indicated airspeed */ - const float air_density_sea_level_15C = 1.225f; //kg/m^3 - if (diff_pressure > 0) - { - ind_airspeed = sqrtf((2.0f*diff_pressure) / air_density_sea_level_15C); - } else - { - ind_airspeed = -sqrtf((2.0f*fabsf(diff_pressure)) / air_density_sea_level_15C); - } - - //qDebug() << "ind_airspeed: " << ind_airspeed << "true_airspeed: " << true_airspeed; - float pressure_alt = alt; xmag_ned = cosf(mag_variation); -- 2.22.0