Skip to content

Commit

Permalink
add missing haveGpsAlt and haveBaroAlt checks
Browse files Browse the repository at this point in the history
simplify conditions
  • Loading branch information
Maciej Bunia committed Apr 30, 2019
1 parent fe4c3ac commit bd5b73d
Showing 1 changed file with 9 additions and 22 deletions.
31 changes: 9 additions & 22 deletions src/main/flight/position.c
Expand Up @@ -144,38 +144,25 @@ if (sensors(SENSOR_GPS) && STATE(GPS_FIX)) {
baroAlt -= baroAltOffset;
gpsAlt -= gpsAltOffset;

if(positionConfig()->altSource == BARO_ONLY){
estimatedAltitudeCm = baroAlt;

if (haveGpsAlt && haveBaroAlt && positionConfig()->altSource == DEFAULT) {
estimatedAltitudeCm = gpsAlt * gpsTrust + baroAlt * (1 - gpsTrust);
#ifdef USE_VARIO
// baro is a better source for vario, so ignore gpsVertSpeed
estimatedVario = calculateEstimatedVario(baroAlt, dTime);
#endif
}
else if (positionConfig()->altSource == GPS_ONLY){
} else if (haveGpsAlt && (positionConfig()->altSource == GPS_ONLY || positionConfig()->altSource == DEFAULT )) {
estimatedAltitudeCm = gpsAlt;
#if defined(USE_VARIO) && defined(USE_GPS)
estimatedVario = gpsVertSpeed;
#endif
}
else {
if (haveGpsAlt && haveBaroAlt) {
estimatedAltitudeCm = gpsAlt * gpsTrust + baroAlt * (1 - gpsTrust);
#ifdef USE_VARIO
// baro is a better source for vario, so ignore gpsVertSpeed
estimatedVario = calculateEstimatedVario(baroAlt, dTime);
#endif
} else if (haveGpsAlt) {
estimatedAltitudeCm = gpsAlt;
#if defined(USE_VARIO) && defined(USE_GPS)
estimatedVario = gpsVertSpeed;
#endif
} else if (haveBaroAlt) {
estimatedAltitudeCm = baroAlt;
} else if (haveBaroAlt && (positionConfig()->altSource == BARO_ONLY || positionConfig()->altSource == DEFAULT)) {
estimatedAltitudeCm = baroAlt;
#ifdef USE_VARIO
estimatedVario = calculateEstimatedVario(baroAlt, dTime);
estimatedVario = calculateEstimatedVario(baroAlt, dTime);
#endif
}
}



DEBUG_SET(DEBUG_ALTITUDE, 0, (int32_t)(100 * gpsTrust));
Expand Down

0 comments on commit bd5b73d

Please sign in to comment.