Ref T259, Ref T243 situation detects under and overflow

* details about altitude correction AltitudeCorrection
* function to correct altitude by detecting under/overflow
This commit is contained in:
Klaus Basan
2018-03-30 03:09:19 +02:00
parent 852abf1232
commit 63e5f75a1d
2 changed files with 79 additions and 12 deletions

View File

@@ -55,6 +55,7 @@ namespace BlackMisc
QStringLiteral(" pitch: ") % (m_pitch.toQString(i18n)) % QStringLiteral(" pitch: ") % (m_pitch.toQString(i18n)) %
QStringLiteral(" heading: ") % (m_heading.toQString(i18n)) % QStringLiteral(" heading: ") % (m_heading.toQString(i18n)) %
QStringLiteral(" og: ") % this->getOnGroundInfo() % QStringLiteral(" og: ") % this->getOnGroundInfo() %
QStringLiteral(" factor: ") % QString::number(m_onGroundFactor, 'f', 2) %
QStringLiteral(" gs: ") % m_groundSpeed.valueRoundedWithUnit(CSpeedUnit::kts(), 1, true) % QStringLiteral(" gs: ") % m_groundSpeed.valueRoundedWithUnit(CSpeedUnit::kts(), 1, true) %
QStringLiteral(" ") % m_groundSpeed.valueRoundedWithUnit(CSpeedUnit::m_s(), 1, true) % QStringLiteral(" ") % m_groundSpeed.valueRoundedWithUnit(CSpeedUnit::m_s(), 1, true) %
QStringLiteral(" elevation: ") % (m_groundElevationPlane.toQString(i18n)); 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() const CLength &CAircraftSituation::deltaNearGround()
{ {
static const CLength small(0.5, CLengthUnit::m()); static const CLength small(0.5, CLengthUnit::m());
@@ -383,31 +404,60 @@ namespace BlackMisc
return this->getAltitude() - gh; return this->getAltitude() - gh;
} }
CAltitude CAircraftSituation::getCorrectedAltitude(const CLength &centerOfGravity, bool dragToGround, bool *corrected) const CAltitude CAircraftSituation::getCorrectedAltitude(const CLength &centerOfGravity, bool enableDragToGround, AltitudeCorrection *correctetion) const
{ {
if (corrected) { *corrected = false; } if (correctetion) { *correctetion = UnknownCorrection; }
if (!this->hasGroundElevation()) { return this->getAltitude(); } if (!this->hasGroundElevation())
{
if (correctetion) { *correctetion = NoElevation; }
return this->getAltitude();
}
// above ground // above ground
if (this->getAltitude().getReferenceDatum() == CAltitude::AboveGround) if (this->getAltitude().getReferenceDatum() == CAltitude::AboveGround)
{ {
BLACK_VERIFY_X(false, Q_FUNC_INFO, "Unsupported"); BLACK_VERIFY_X(false, Q_FUNC_INFO, "Unsupported");
if (correctetion) { *correctetion = AGL; }
return this->getAltitude(); return this->getAltitude();
} }
else else
{ {
const CAltitude groundPlusCG = this->getGroundElevation().withOffset(centerOfGravity); 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 CLength groundDistance = this->getAltitude() - groundPlusCG;
const bool underOrNearGround = groundDistance.isNegativeWithEpsilonConsidered() || groundDistance.abs() < deltaNearGround(); const bool underflow = groundDistance.isNegativeWithEpsilonConsidered();
const bool forceDragGnd = (dragToGround && this->getOnGround() == OnGround) && (this->hasInboundGroundInformation() || this->getOnGroundDetails() == OnGroundByGuessing); if (underflow)
const bool toGround = underOrNearGround || forceDragGnd; {
if (!toGround) { return this->getAltitude(); } if (correctetion) { *correctetion = Underflow; }
// underflow or overflow forced to ground
if (corrected) { *corrected = true; }
return groundPlusCG; 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;
}
if (correctetion) { *correctetion = NoCorrection; }
return this->getAltitude();
}
}
CAircraftSituation::AltitudeCorrection CAircraftSituation::correctAltitude(const CLength &centerOfGravity, bool enableDragToGround)
{
CAircraftSituation::AltitudeCorrection altCor = CAircraftSituation::UnknownCorrection;
this->setAltitude(this->getCorrectedAltitude(centerOfGravity, enableDragToGround, &altCor));
return altCor;
} }
void CAircraftSituation::setPressureAltitude(const CAltitude &altitude) void CAircraftSituation::setPressureAltitude(const CAltitude &altitude)

View File

@@ -93,6 +93,17 @@ namespace BlackMisc
OutOnGroundOwnAircraft //!< sending on ground OutOnGroundOwnAircraft //!< sending on ground
}; };
//! How was altitude corrected
enum AltitudeCorrection
{
NoCorrection,
Underflow,
DraggedToGround,
AGL,
NoElevation,
UnknownCorrection
};
//! Default constructor. //! Default constructor.
CAircraftSituation(); CAircraftSituation();
@@ -248,7 +259,10 @@ namespace BlackMisc
//! Get altitude under consideration of ground elevation and ground flag //! Get altitude under consideration of ground elevation and ground flag
//! \remark with dragToGround it will also compensate overflows, otherwise ony underflow //! \remark with dragToGround it will also compensate overflows, otherwise ony underflow
CAltitude getCorrectedAltitude(const PhysicalQuantities::CLength &centerOfGravity = PhysicalQuantities::CLength::null(), bool dragToGround = true, bool *corrected = nullptr) const; CAltitude getCorrectedAltitude(const PhysicalQuantities::CLength &centerOfGravity = PhysicalQuantities::CLength::null(), bool enableDragToGround = true, AltitudeCorrection *correctetion = nullptr) const;
//! Set the corrected altitude from CAircraftSituation::getCorrectedAltitude
AltitudeCorrection correctAltitude(const PhysicalQuantities::CLength &centerOfGravity = PhysicalQuantities::CLength::null(), bool enableDragToGround = true);
//! Set altitude //! Set altitude
void setAltitude(const CAltitude &altitude) { m_position.setGeodeticHeight(altitude); } void setAltitude(const CAltitude &altitude) { m_position.setGeodeticHeight(altitude); }
@@ -324,6 +338,9 @@ namespace BlackMisc
//! Enum to string //! Enum to string
static const QString &onGroundDetailsToString(OnGroundDetails reliability); static const QString &onGroundDetailsToString(OnGroundDetails reliability);
//! Enum to string
static const QString &altitudeCorrectionToString(AltitudeCorrection correction);
//! Delta distance, near to ground //! Delta distance, near to ground
static const PhysicalQuantities::CLength &deltaNearGround(); static const PhysicalQuantities::CLength &deltaNearGround();