mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-21 12:55:31 +08:00
Ref T180, interpolator status can check validity of situation and provide an info string
This commit is contained in:
@@ -64,7 +64,11 @@ namespace BlackMisc
|
|||||||
const auto interpolant = derived()->getInterpolant(currentTimeMsSinceEpoc, setup, hints, status, log);
|
const auto interpolant = derived()->getInterpolant(currentTimeMsSinceEpoc, setup, hints, status, log);
|
||||||
|
|
||||||
// succeeded so far?
|
// succeeded so far?
|
||||||
if (!status.didInterpolationSucceed()) { return currentSituation; }
|
if (!status.didInterpolationSucceed())
|
||||||
|
{
|
||||||
|
status.setValidSituation(currentSituation);
|
||||||
|
return currentSituation;
|
||||||
|
}
|
||||||
|
|
||||||
// use derived interpolant function
|
// use derived interpolant function
|
||||||
currentSituation.setPosition(interpolant.interpolatePosition(setup, hints));
|
currentSituation.setPosition(interpolant.interpolatePosition(setup, hints));
|
||||||
@@ -112,7 +116,7 @@ namespace BlackMisc
|
|||||||
currentSituation.setGroundSpeed(pbh.getGroundSpeed());
|
currentSituation.setGroundSpeed(pbh.getGroundSpeed());
|
||||||
status.setChangedPosition(true);
|
status.setChangedPosition(true);
|
||||||
}
|
}
|
||||||
status.setInterpolationSucceeded(true);
|
status.setInterpolationSucceeded(true, currentSituation);
|
||||||
m_isFirstInterpolation = false;
|
m_isFirstInterpolation = false;
|
||||||
|
|
||||||
if (m_logger && hints.isLoggingInterpolation())
|
if (m_logger && hints.isLoggingInterpolation())
|
||||||
@@ -348,17 +352,41 @@ namespace BlackMisc
|
|||||||
situation.setOnGround(CAircraftSituation::OnGround, CAircraftSituation::OnGroundByGuessing);
|
situation.setOnGround(CAircraftSituation::OnGround, CAircraftSituation::OnGroundByGuessing);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CInterpolationStatus::allTrue() const
|
void CInterpolationStatus::setInterpolationSucceeded(bool succeeded, const CAircraftSituation &situation)
|
||||||
{
|
{
|
||||||
return m_interpolationSucceeded && m_changedPosition;
|
m_interpolationSucceeded = succeeded;
|
||||||
|
this->setValidSituation(situation);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CInterpolationStatus::setValidSituation(const CAircraftSituation &situation)
|
||||||
|
{
|
||||||
|
m_validSituation = !situation.isGeodeticHeightNull() && !situation.isPositionNull();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CInterpolationStatus::validAndChangedInterpolatedSituation() const
|
||||||
|
{
|
||||||
|
return m_interpolationSucceeded && m_changedPosition && m_validSituation;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CInterpolationStatus::validInterpolatedSituation() const
|
||||||
|
{
|
||||||
|
return m_interpolationSucceeded && m_validSituation;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CInterpolationStatus::reset()
|
void CInterpolationStatus::reset()
|
||||||
{
|
{
|
||||||
|
m_validSituation = false;
|
||||||
m_changedPosition = false;
|
m_changedPosition = false;
|
||||||
m_interpolationSucceeded = false;
|
m_interpolationSucceeded = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString CInterpolationStatus::toQString() const
|
||||||
|
{
|
||||||
|
return "Interpolation: " % boolToYesNo(m_interpolationSucceeded) %
|
||||||
|
" situation valid: " % boolToYesNo(m_interpolationSucceeded) %
|
||||||
|
" changed pos.: " % boolToYesNo(m_changedPosition);
|
||||||
|
}
|
||||||
|
|
||||||
bool CPartsStatus::allTrue() const
|
bool CPartsStatus::allTrue() const
|
||||||
{
|
{
|
||||||
return m_supportsParts;
|
return m_supportsParts;
|
||||||
|
|||||||
@@ -151,21 +151,37 @@ namespace BlackMisc
|
|||||||
//! Set succeeded
|
//! Set succeeded
|
||||||
void setInterpolationSucceeded(bool succeeded) { m_interpolationSucceeded = succeeded; }
|
void setInterpolationSucceeded(bool succeeded) { m_interpolationSucceeded = succeeded; }
|
||||||
|
|
||||||
|
//! Set succeeded
|
||||||
|
void setInterpolationSucceeded(bool succeeded, const Aviation::CAircraftSituation &situation);
|
||||||
|
|
||||||
//! Changed position?
|
//! Changed position?
|
||||||
bool hasChangedPosition() const { return m_changedPosition; }
|
bool hasChangedPosition() const { return m_changedPosition; }
|
||||||
|
|
||||||
|
//! Is the corresponding position valid?
|
||||||
|
bool hasValidSituation() const { return m_validSituation; }
|
||||||
|
|
||||||
|
//! Is that a valid position?
|
||||||
|
void setValidSituation(const Aviation::CAircraftSituation &situation);
|
||||||
|
|
||||||
//! Set as changed
|
//! Set as changed
|
||||||
void setChangedPosition(bool changed) { m_changedPosition = changed; }
|
void setChangedPosition(bool changed) { m_changedPosition = changed; }
|
||||||
|
|
||||||
//! all OK
|
//! Valid interpolated situation which also changed
|
||||||
bool allTrue() const;
|
bool validAndChangedInterpolatedSituation() const;
|
||||||
|
|
||||||
|
//! Valid interpolated situation
|
||||||
|
bool validInterpolatedSituation() const;
|
||||||
|
|
||||||
//! Reset to default values
|
//! Reset to default values
|
||||||
void reset();
|
void reset();
|
||||||
|
|
||||||
|
//! Info string
|
||||||
|
QString toQString() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool m_changedPosition = false; //!< position was changed
|
bool m_changedPosition = false; //!< position was changed
|
||||||
bool m_interpolationSucceeded = false; //!< interpolation succeeded (means enough values, etc.)
|
bool m_interpolationSucceeded = false; //!< interpolation succeeded (means enough values, etc.)
|
||||||
|
bool m_validSituation = false; //!< is valid situation
|
||||||
};
|
};
|
||||||
|
|
||||||
//! Status regarding parts
|
//! Status regarding parts
|
||||||
|
|||||||
@@ -69,10 +69,20 @@ namespace BlackMisc
|
|||||||
if (situationsOlder.isEmpty() || situationsNewer.isEmpty())
|
if (situationsOlder.isEmpty() || situationsNewer.isEmpty())
|
||||||
{
|
{
|
||||||
// no before situations
|
// no before situations
|
||||||
if (situationsOlder.isEmpty()) { return *(situationsNewer.end() - 1); } // oldest newest
|
if (situationsOlder.isEmpty())
|
||||||
|
{
|
||||||
|
const CAircraftSituation currentSituation(*(situationsNewer.end() - 1)); // oldest newest
|
||||||
|
status.setInterpolationSucceeded(false, currentSituation);
|
||||||
|
return currentSituation;
|
||||||
|
}
|
||||||
|
|
||||||
// only one before situation
|
// only one before situation
|
||||||
if (situationsOlder.size() < 2) { return situationsOlder.front(); } // latest older
|
if (situationsOlder.size() < 2)
|
||||||
|
{
|
||||||
|
const CAircraftSituation currentSituation(situationsOlder.front()); // latest oldest
|
||||||
|
status.setInterpolationSucceeded(false, currentSituation);
|
||||||
|
return currentSituation;
|
||||||
|
}
|
||||||
|
|
||||||
// extrapolate from two before situations
|
// extrapolate from two before situations
|
||||||
oldSituation = *(situationsOlder.begin() + 1); // before newest
|
oldSituation = *(situationsOlder.begin() + 1); // before newest
|
||||||
@@ -115,7 +125,7 @@ namespace BlackMisc
|
|||||||
currentSituation.setMSecsSinceEpoch(oldSituation.getMSecsSinceEpoch() + deltaTimeFractionMs);
|
currentSituation.setMSecsSinceEpoch(oldSituation.getMSecsSinceEpoch() + deltaTimeFractionMs);
|
||||||
|
|
||||||
status.setChangedPosition(m_isFirstInterpolation || oldSituation.getPosition() != newSituation.getPosition() || oldSituation.getAltitude() != newSituation.getAltitude());
|
status.setChangedPosition(m_isFirstInterpolation || oldSituation.getPosition() != newSituation.getPosition() || oldSituation.getAltitude() != newSituation.getAltitude());
|
||||||
status.setInterpolationSucceeded(true);
|
status.setInterpolationSucceeded(true, currentSituation);
|
||||||
|
|
||||||
log.oldSituation = oldSituation;
|
log.oldSituation = oldSituation;
|
||||||
log.newSituation = newSituation;
|
log.newSituation = newSituation;
|
||||||
|
|||||||
@@ -1100,7 +1100,7 @@ namespace BlackSimPlugin
|
|||||||
hints.setLoggingInterpolation(logInterpolationAndParts);
|
hints.setLoggingInterpolation(logInterpolationAndParts);
|
||||||
const CAircraftSituation interpolatedSituation = simObject.getInterpolatedSituation(currentTimestamp, setup, hints, interpolatorStatus);
|
const CAircraftSituation interpolatedSituation = simObject.getInterpolatedSituation(currentTimestamp, setup, hints, interpolatorStatus);
|
||||||
|
|
||||||
if (interpolatorStatus.allTrue())
|
if (interpolatorStatus.validAndChangedInterpolatedSituation())
|
||||||
{
|
{
|
||||||
// update situation
|
// update situation
|
||||||
SIMCONNECT_DATA_INITPOSITION position = this->aircraftSituationToFsxPosition(interpolatedSituation);
|
SIMCONNECT_DATA_INITPOSITION position = this->aircraftSituationToFsxPosition(interpolatedSituation);
|
||||||
|
|||||||
@@ -127,7 +127,7 @@ namespace BlackMiscTest
|
|||||||
CAircraftSituation currentSituation(interpolator.getInterpolatedSituation
|
CAircraftSituation currentSituation(interpolator.getInterpolatedSituation
|
||||||
(currentTime, setup, hints, status)
|
(currentTime, setup, hints, status)
|
||||||
);
|
);
|
||||||
QVERIFY2(status.allTrue(), "Failed interpolation");
|
QVERIFY2(status.validAndChangedInterpolatedSituation(), "Failed interpolation");
|
||||||
QVERIFY2(currentSituation.getCallsign() == cs, "Wrong callsign");
|
QVERIFY2(currentSituation.getCallsign() == cs, "Wrong callsign");
|
||||||
double latDeg = currentSituation.getPosition().latitude().valueRounded(CAngleUnit::deg(), 5);
|
double latDeg = currentSituation.getPosition().latitude().valueRounded(CAngleUnit::deg(), 5);
|
||||||
double lngDeg = currentSituation.getPosition().longitude().valueRounded(CAngleUnit::deg(), 5);
|
double lngDeg = currentSituation.getPosition().longitude().valueRounded(CAngleUnit::deg(), 5);
|
||||||
|
|||||||
Reference in New Issue
Block a user