diff --git a/src/blackmisc/aviation/aircraftsituation.cpp b/src/blackmisc/aviation/aircraftsituation.cpp index 9d94fa303..1b650f238 100644 --- a/src/blackmisc/aviation/aircraftsituation.cpp +++ b/src/blackmisc/aviation/aircraftsituation.cpp @@ -241,17 +241,15 @@ namespace BlackMisc CLength CAircraftSituation::getHeightAboveGround() const { + if (this->getAltitude().isNull()) { return { 0, nullptr }; } if (this->getAltitude().getReferenceDatum() == CAltitude::AboveGround) { // we have a sure value explicitly set return this->getAltitude(); } const CLength gh(this->getGroundElevation()); - if (!gh.isNull() && !getAltitude().isNull()) - { - return this->getAltitude() - gh; - } - return { 0, nullptr }; + if (gh.isNull()) { return { 0, nullptr }; } + return this->getAltitude() - gh; } CAltitude CAircraftSituation::getCorrectedAltitude() const diff --git a/src/blackmisc/aviation/aircraftsituation.h b/src/blackmisc/aviation/aircraftsituation.h index c5ceffa78..0f1f09690 100644 --- a/src/blackmisc/aviation/aircraftsituation.h +++ b/src/blackmisc/aviation/aircraftsituation.h @@ -73,9 +73,10 @@ namespace BlackMisc //! Reliability of on ground information enum OnGroundReliability { - OnGroundByGuessing, + OnGroundByInterpolation, //!< strongest + OnGroundByElevationAndCG, OnGroundByElevation, - OnGroundByInterpolation, + OnGroundByGuessing, //!< weakest OnGroundReliabilityNoSet }; diff --git a/src/blackmisc/simulation/interpolator.cpp b/src/blackmisc/simulation/interpolator.cpp index 36f9a696b..6926c8d4d 100644 --- a/src/blackmisc/simulation/interpolator.cpp +++ b/src/blackmisc/simulation/interpolator.cpp @@ -303,15 +303,23 @@ namespace BlackMisc return; } - // no value by factor, guess on elevation - const CLength heightAboveGround(situation.getHeightAboveGround()); - const CLength cgAboveGround(hints.getCGAboveGround()); - if (!heightAboveGround.isNull()) + // on elevation and CG + if (!situation.getGroundElevation().isNull()) { - const bool og = cgAboveGround.isNull() ? - heightAboveGround.value(CLengthUnit::m()) < 1.0 : - heightAboveGround <= cgAboveGround; - situation.setOnGround(og ? CAircraftSituation::OnGround : CAircraftSituation::NotOnGround, CAircraftSituation::OnGroundByElevation); + CLength offset(hints.isVtolAircraft() ? 0.0 : 1.0, CLengthUnit::m()); // offset from ground + CAircraftSituation::OnGroundReliability reliability = CAircraftSituation::OnGroundByElevation; + if (!hints.isVtolAircraft() && !hints.getCGAboveGround().isNull()) + { + offset = hints.getCGAboveGround(); + reliability = CAircraftSituation::OnGroundByElevationAndCG; + } + + Q_ASSERT_X(situation.getGroundElevation().getReferenceDatum() == CAltitude::MeanSeaLevel, Q_FUNC_INFO, "Need MSL elevation"); + const CAircraftSituation::IsOnGround og = + situation.getHeightAboveGround() <= offset ? + CAircraftSituation::OnGround : CAircraftSituation::NotOnGround; + situation.setOnGround(og, reliability); + return; } // for VTOL aircraft we give up