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(" 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 &centerOfGravity, bool dragToGround, bool *corrected) const
CAltitude CAircraftSituation::getCorrectedAltitude(const CLength &centerOfGravity, 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 &centerOfGravity, 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);

View File

@@ -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 &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
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();