mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-15 01:05:35 +08:00
refs #570 Removed the hardcoded 6 seconds, interpolator honors the offsets of the situations.
This commit is contained in:
@@ -80,8 +80,6 @@ namespace BlackCore
|
|||||||
//! Enable debug messages
|
//! Enable debug messages
|
||||||
void enableDebugMessages(bool enabled);
|
void enableDebugMessages(bool enabled);
|
||||||
|
|
||||||
static const qint64 TimeOffsetMs = 6000; //!< offset for interpolation
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
//! Constructor
|
//! Constructor
|
||||||
IInterpolator(BlackMisc::Simulation::IRemoteAircraftProvider *provider, const QString &objectName, QObject *parent);
|
IInterpolator(BlackMisc::Simulation::IRemoteAircraftProvider *provider, const QString &objectName, QObject *parent);
|
||||||
|
|||||||
@@ -49,19 +49,22 @@ namespace BlackCore
|
|||||||
|
|
||||||
// data, split situations by time
|
// data, split situations by time
|
||||||
if (currentTimeMsSinceEpoc < 0) { currentTimeMsSinceEpoc = QDateTime::currentMSecsSinceEpoch(); }
|
if (currentTimeMsSinceEpoc < 0) { currentTimeMsSinceEpoc = QDateTime::currentMSecsSinceEpoch(); }
|
||||||
qint64 splitTimeMsSinceEpoch = currentTimeMsSinceEpoc - TimeOffsetMs; // \todo needs to be variable in the future with interim positions
|
|
||||||
const auto situations = remoteAircraftSituations(callsign);
|
const auto situations = remoteAircraftSituations(callsign);
|
||||||
|
|
||||||
|
// find the first situation not in the correct order, keep only the situations before that one
|
||||||
|
auto end = std::is_sorted_until(situations.begin(), situations.end(), [](auto &&a, auto &&b) { return b.getAdjustedMSecsSinceEpoch() < a.getAdjustedMSecsSinceEpoch(); });
|
||||||
|
auto validSituations = makeRange(situations.begin(), end);
|
||||||
|
|
||||||
// find the first situation earlier than the current time
|
// find the first situation earlier than the current time
|
||||||
auto pivot = std::partition_point(situations.begin(), situations.end(), [ = ](auto &&s) { return s.getMSecsSinceEpoch() > currentTimeMsSinceEpoc; });
|
auto pivot = std::partition_point(validSituations.begin(), validSituations.end(), [ = ](auto &&s) { return s.getAdjustedMSecsSinceEpoch() > currentTimeMsSinceEpoc; });
|
||||||
auto situationsNewer = makeRange(situations.begin(), pivot);
|
auto situationsNewer = makeRange(validSituations.begin(), pivot);
|
||||||
auto situationsOlder = makeRange(pivot, situations.end());
|
auto situationsOlder = makeRange(pivot, validSituations.end());
|
||||||
|
|
||||||
// interpolation situations
|
// interpolation situations
|
||||||
CAircraftSituation oldSituation;
|
CAircraftSituation oldSituation;
|
||||||
CAircraftSituation newSituation;
|
CAircraftSituation newSituation;
|
||||||
|
|
||||||
// latest first, now 00:26 -> 00:26 - 6000ms -> 00:20 split time
|
// latest first, now 00:20 split time
|
||||||
// time pos
|
// time pos
|
||||||
// 00:25 10 newer
|
// 00:25 10 newer
|
||||||
// 00:20 11 newer
|
// 00:20 11 newer
|
||||||
@@ -96,13 +99,13 @@ namespace BlackCore
|
|||||||
status.interpolationSucceeded = true;
|
status.interpolationSucceeded = true;
|
||||||
|
|
||||||
// Time between start and end packet
|
// Time between start and end packet
|
||||||
double deltaTime = oldSituation.absMsecsTo(newSituation);
|
double deltaTime = std::abs(oldSituation.getAdjustedMSecsSinceEpoch() - newSituation.getAdjustedMSecsSinceEpoch());
|
||||||
|
|
||||||
// Fraction of the deltaTime, ideally [0.0 - 1.0]
|
// Fraction of the deltaTime, ideally [0.0 - 1.0]
|
||||||
// < 0 should not happen due to the split, > 1 can happen if new values are delayed beyond split time
|
// < 0 should not happen due to the split, > 1 can happen if new values are delayed beyond split time
|
||||||
// 1) values > 1 mean extrapolation
|
// 1) values > 1 mean extrapolation
|
||||||
// 2) values > 2 mean no new situations coming in
|
// 2) values > 2 mean no new situations coming in
|
||||||
double distanceToSplitTime = newSituation.getMSecsSinceEpoch() - splitTimeMsSinceEpoch;
|
double distanceToSplitTime = newSituation.getAdjustedMSecsSinceEpoch() - currentTimeMsSinceEpoc;
|
||||||
double simulationTimeFraction = 1 - (distanceToSplitTime / deltaTime);
|
double simulationTimeFraction = 1 - (distanceToSplitTime / deltaTime);
|
||||||
if (simulationTimeFraction > 2.0)
|
if (simulationTimeFraction > 2.0)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -656,7 +656,7 @@ namespace BlackSimPlugin
|
|||||||
CAircraftPartsList parts;
|
CAircraftPartsList parts;
|
||||||
if (partsStatus.supportsParts)
|
if (partsStatus.supportsParts)
|
||||||
{
|
{
|
||||||
this->m_interpolator->getPartsBeforeTime(callsign, currentTimestamp - this->m_interpolator->TimeOffsetMs, partsStatus);
|
this->m_interpolator->getPartsBeforeTime(callsign, currentTimestamp, partsStatus);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (interpolatorStatus.allTrue())
|
if (interpolatorStatus.allTrue())
|
||||||
|
|||||||
@@ -62,10 +62,11 @@ namespace BlackCoreTest
|
|||||||
// fixed time so everything can be debugged
|
// fixed time so everything can be debugged
|
||||||
const qint64 ts = 1425000000000; // QDateTime::currentMSecsSinceEpoch();
|
const qint64 ts = 1425000000000; // QDateTime::currentMSecsSinceEpoch();
|
||||||
const qint64 deltaT = 5000; // ms
|
const qint64 deltaT = 5000; // ms
|
||||||
|
const qint64 offset = 5000;
|
||||||
CCallsign cs("SWIFT");
|
CCallsign cs("SWIFT");
|
||||||
for (int i = 0; i < IRemoteAircraftProvider::MaxSituationsPerCallsign; i++)
|
for (int i = 0; i < IRemoteAircraftProvider::MaxSituationsPerCallsign; i++)
|
||||||
{
|
{
|
||||||
CAircraftSituation s(getTestSituation(cs, i, ts, deltaT));
|
CAircraftSituation s(getTestSituation(cs, i, ts, deltaT, offset));
|
||||||
|
|
||||||
// check height above ground
|
// check height above ground
|
||||||
CLength hag = (s.getAltitude() - s.geodeticHeight());
|
CLength hag = (s.getAltitude() - s.geodeticHeight());
|
||||||
@@ -90,11 +91,11 @@ namespace BlackCoreTest
|
|||||||
IInterpolator::InterpolationStatus status;
|
IInterpolator::InterpolationStatus status;
|
||||||
double latOld = 360.0;
|
double latOld = 360.0;
|
||||||
double lngOld = 360.0;
|
double lngOld = 360.0;
|
||||||
for (qint64 currentTime = ts - 2 * deltaT; currentTime < ts; currentTime += (deltaT / 20))
|
for (qint64 currentTime = ts - 2 * deltaT + offset; currentTime < ts + offset; currentTime += (deltaT / 20))
|
||||||
{
|
{
|
||||||
// This will use time range
|
// This will use time range
|
||||||
// from: ts - 2* deltaT - IInterpolator::TimeOffsetMs
|
// from: ts - 2 * deltaT + offset
|
||||||
// to: ts - IInterpolator::TimeOffsetMs
|
// to: ts + offset
|
||||||
CAircraftSituation currentSituation(interpolator.getInterpolatedSituation
|
CAircraftSituation currentSituation(interpolator.getInterpolatedSituation
|
||||||
(cs, currentTime, false, status)
|
(cs, currentTime, false, status)
|
||||||
);
|
);
|
||||||
@@ -103,6 +104,7 @@ namespace BlackCoreTest
|
|||||||
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);
|
||||||
QVERIFY2(latDeg < latOld && lngDeg < lngOld, "Values shall decrease");
|
QVERIFY2(latDeg < latOld && lngDeg < lngOld, "Values shall decrease");
|
||||||
|
QVERIFY2(latDeg >= 0 && latDeg <= IRemoteAircraftProvider::MaxSituationsPerCallsign, "Values shall be in range");
|
||||||
latOld = latDeg;
|
latOld = latDeg;
|
||||||
lngOld = lngDeg;
|
lngOld = lngDeg;
|
||||||
}
|
}
|
||||||
@@ -120,11 +122,11 @@ namespace BlackCoreTest
|
|||||||
|
|
||||||
for (int loops = 0; loops < 20; loops++)
|
for (int loops = 0; loops < 20; loops++)
|
||||||
{
|
{
|
||||||
for (qint64 currentTime = startTimeMsSinceEpoch; currentTime < ts; currentTime += (deltaT / 20))
|
for (qint64 currentTime = startTimeMsSinceEpoch + offset; currentTime < ts + offset; currentTime += (deltaT / 20))
|
||||||
{
|
{
|
||||||
// This will use range
|
// This will use range
|
||||||
// from: ts - 2* deltaT - IInterpolator::TimeOffsetMs
|
// from: ts - 2* deltaT + offset
|
||||||
// to: ts - IInterpolator::TimeOffsetMs
|
// to: ts + offset
|
||||||
CAircraftSituation currentSituation(interpolator.getInterpolatedSituation
|
CAircraftSituation currentSituation(interpolator.getInterpolatedSituation
|
||||||
(cs, currentTime, false, status)
|
(cs, currentTime, false, status)
|
||||||
);
|
);
|
||||||
@@ -155,7 +157,7 @@ namespace BlackCoreTest
|
|||||||
qDebug() << timeMs << "ms" << "for" << fetchedParts << "fetched parts";
|
qDebug() << timeMs << "ms" << "for" << fetchedParts << "fetched parts";
|
||||||
}
|
}
|
||||||
|
|
||||||
CAircraftSituation CTestInterpolator::getTestSituation(const CCallsign &callsign, int number, qint64 ts, qint64 deltaT)
|
CAircraftSituation CTestInterpolator::getTestSituation(const CCallsign &callsign, int number, qint64 ts, qint64 deltaT, qint64 offset)
|
||||||
{
|
{
|
||||||
CAltitude a(number, CAltitude::MeanSeaLevel, CLengthUnit::m());
|
CAltitude a(number, CAltitude::MeanSeaLevel, CLengthUnit::m());
|
||||||
CLatitude lat(number, CAngleUnit::deg());
|
CLatitude lat(number, CAngleUnit::deg());
|
||||||
@@ -168,6 +170,7 @@ namespace BlackCoreTest
|
|||||||
CCoordinateGeodetic c(lat, lng, height);
|
CCoordinateGeodetic c(lat, lng, height);
|
||||||
CAircraftSituation s(callsign, c, a, heading, pitch, bank, gs);
|
CAircraftSituation s(callsign, c, a, heading, pitch, bank, gs);
|
||||||
s.setMSecsSinceEpoch(ts - deltaT * number); // values in past
|
s.setMSecsSinceEpoch(ts - deltaT * number); // values in past
|
||||||
|
s.setTimeOffsetMs(offset);
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ namespace BlackCoreTest
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
//! Test situation for testing
|
//! Test situation for testing
|
||||||
static BlackMisc::Aviation::CAircraftSituation getTestSituation(const BlackMisc::Aviation::CCallsign &callsign, int number, qint64 ts, qint64 deltaT);
|
static BlackMisc::Aviation::CAircraftSituation getTestSituation(const BlackMisc::Aviation::CCallsign &callsign, int number, qint64 ts, qint64 deltaT, qint64 offset);
|
||||||
|
|
||||||
//! Test parts
|
//! Test parts
|
||||||
static BlackMisc::Aviation::CAircraftParts getTestParts(int number, qint64 ts, qint64 deltaT);
|
static BlackMisc::Aviation::CAircraftParts getTestParts(int number, qint64 ts, qint64 deltaT);
|
||||||
|
|||||||
Reference in New Issue
Block a user