From 63e5f75a1d1dde72434f75a6fd331883410a8cc8 Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Fri, 30 Mar 2018 03:09:19 +0200 Subject: [PATCH] Ref T259, Ref T243 situation detects under and overflow * details about altitude correction AltitudeCorrection * function to correct altitude by detecting under/overflow --- src/blackmisc/aviation/aircraftsituation.cpp | 72 +++++++++++++++++--- src/blackmisc/aviation/aircraftsituation.h | 19 +++++- 2 files changed, 79 insertions(+), 12 deletions(-) diff --git a/src/blackmisc/aviation/aircraftsituation.cpp b/src/blackmisc/aviation/aircraftsituation.cpp index 538e8c1bd..760ebfff1 100644 --- a/src/blackmisc/aviation/aircraftsituation.cpp +++ b/src/blackmisc/aviation/aircraftsituation.cpp @@ -55,6 +55,7 @@ namespace BlackMisc QStringLiteral(" pitch: ") % (m_pitch.toQString(i18n)) % QStringLiteral(" heading: ") % (m_heading.toQString(i18n)) % QStringLiteral(" og: ") % this->getOnGroundInfo() % + QStringLiteral(" factor: ") % QString::number(m_onGroundFactor, 'f', 2) % QStringLiteral(" gs: ") % m_groundSpeed.valueRoundedWithUnit(CSpeedUnit::kts(), 1, true) % QStringLiteral(" ") % m_groundSpeed.valueRoundedWithUnit(CSpeedUnit::m_s(), 1, true) % QStringLiteral(" elevation: ") % (m_groundElevationPlane.toQString(i18n)); @@ -102,6 +103,26 @@ namespace BlackMisc } } + const QString &CAircraftSituation::altitudeCorrectionToString(CAircraftSituation::AltitudeCorrection correction) + { + static const QString under("underflow"); + static const QString dragged("dragged to gnd"); + static const QString no("no correction"); + static const QString noElv("no elv."); + static const QString unknown("unknown"); + static const QString agl("AGL"); + switch (correction) + { + case Underflow: return under; + case DraggedToGround: return dragged; + case NoElevation: return noElv; + case NoCorrection: return no; + case AGL: return agl; + default: break; + } + return unknown; + } + const CLength &CAircraftSituation::deltaNearGround() { static const CLength small(0.5, CLengthUnit::m()); @@ -383,33 +404,62 @@ namespace BlackMisc return this->getAltitude() - gh; } - CAltitude CAircraftSituation::getCorrectedAltitude(const CLength ¢erOfGravity, bool dragToGround, bool *corrected) const + CAltitude CAircraftSituation::getCorrectedAltitude(const CLength ¢erOfGravity, bool enableDragToGround, AltitudeCorrection *correctetion) const { - if (corrected) { *corrected = false; } - if (!this->hasGroundElevation()) { return this->getAltitude(); } + if (correctetion) { *correctetion = UnknownCorrection; } + if (!this->hasGroundElevation()) + { + if (correctetion) { *correctetion = NoElevation; } + return this->getAltitude(); + } // above ground if (this->getAltitude().getReferenceDatum() == CAltitude::AboveGround) { BLACK_VERIFY_X(false, Q_FUNC_INFO, "Unsupported"); + if (correctetion) { *correctetion = AGL; } return this->getAltitude(); } else { const CAltitude groundPlusCG = this->getGroundElevation().withOffset(centerOfGravity); - if (groundPlusCG.isNull()) { return this->getAltitude(); } + if (groundPlusCG.isNull()) + { + if (correctetion) { *correctetion = NoElevation; } + return this->getAltitude(); + } const CLength groundDistance = this->getAltitude() - groundPlusCG; - const bool underOrNearGround = groundDistance.isNegativeWithEpsilonConsidered() || groundDistance.abs() < deltaNearGround(); - const bool forceDragGnd = (dragToGround && this->getOnGround() == OnGround) && (this->hasInboundGroundInformation() || this->getOnGroundDetails() == OnGroundByGuessing); - const bool toGround = underOrNearGround || forceDragGnd; - if (!toGround) { return this->getAltitude(); } + const bool underflow = groundDistance.isNegativeWithEpsilonConsidered(); + if (underflow) + { + if (correctetion) { *correctetion = Underflow; } + return groundPlusCG; + } + const bool nearGround = groundDistance.abs() < deltaNearGround(); + if (nearGround) + { + if (correctetion) { *correctetion = NoCorrection; } + return groundPlusCG; + } + const bool forceDragToGround = (enableDragToGround && this->getOnGround() == OnGround) && (this->hasInboundGroundInformation() || this->getOnGroundDetails() == OnGroundByGuessing); + if (forceDragToGround) + { + if (correctetion) { *correctetion = DraggedToGround; } + return groundPlusCG; + } - // underflow or overflow forced to ground - if (corrected) { *corrected = true; } - return groundPlusCG; + if (correctetion) { *correctetion = NoCorrection; } + return this->getAltitude(); } } + CAircraftSituation::AltitudeCorrection CAircraftSituation::correctAltitude(const CLength ¢erOfGravity, bool enableDragToGround) + { + CAircraftSituation::AltitudeCorrection altCor = CAircraftSituation::UnknownCorrection; + this->setAltitude(this->getCorrectedAltitude(centerOfGravity, enableDragToGround, &altCor)); + return altCor; + } + void CAircraftSituation::setPressureAltitude(const CAltitude &altitude) { Q_ASSERT(altitude.getAltitudeType() == CAltitude::PressureAltitude); diff --git a/src/blackmisc/aviation/aircraftsituation.h b/src/blackmisc/aviation/aircraftsituation.h index 6f9bd17a9..29bb60549 100644 --- a/src/blackmisc/aviation/aircraftsituation.h +++ b/src/blackmisc/aviation/aircraftsituation.h @@ -93,6 +93,17 @@ namespace BlackMisc OutOnGroundOwnAircraft //!< sending on ground }; + //! How was altitude corrected + enum AltitudeCorrection + { + NoCorrection, + Underflow, + DraggedToGround, + AGL, + NoElevation, + UnknownCorrection + }; + //! Default constructor. CAircraftSituation(); @@ -248,7 +259,10 @@ namespace BlackMisc //! Get altitude under consideration of ground elevation and ground flag //! \remark with dragToGround it will also compensate overflows, otherwise ony underflow - CAltitude getCorrectedAltitude(const PhysicalQuantities::CLength ¢erOfGravity = PhysicalQuantities::CLength::null(), bool dragToGround = true, bool *corrected = nullptr) const; + CAltitude getCorrectedAltitude(const PhysicalQuantities::CLength ¢erOfGravity = PhysicalQuantities::CLength::null(), bool enableDragToGround = true, AltitudeCorrection *correctetion = nullptr) const; + + //! Set the corrected altitude from CAircraftSituation::getCorrectedAltitude + AltitudeCorrection correctAltitude(const PhysicalQuantities::CLength ¢erOfGravity = PhysicalQuantities::CLength::null(), bool enableDragToGround = true); //! Set altitude void setAltitude(const CAltitude &altitude) { m_position.setGeodeticHeight(altitude); } @@ -324,6 +338,9 @@ namespace BlackMisc //! Enum to string static const QString &onGroundDetailsToString(OnGroundDetails reliability); + //! Enum to string + static const QString &altitudeCorrectionToString(AltitudeCorrection correction); + //! Delta distance, near to ground static const PhysicalQuantities::CLength &deltaNearGround();