mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-13 15:45:42 +08:00
refs #865, adjusted interpolator to use elevation or elevation provider
* adjusted IInterpolator::setGroundElevationFromHint * removed cgAboveGround from getCorrectedAltitude
This commit is contained in:
committed by
Mathew Sutcliffe
parent
38585d10b2
commit
daab5eed49
@@ -202,13 +202,12 @@ namespace BlackMisc
|
||||
return { 0, nullptr };
|
||||
}
|
||||
|
||||
CAltitude CAircraftSituation::getCorrectedAltitude(const CLength &cgAboveGround) const
|
||||
CAltitude CAircraftSituation::getCorrectedAltitude() const
|
||||
{
|
||||
if (!this->hasGroundElevation()) { return this->getAltitude(); }
|
||||
const CAltitude groundElevation(cgAboveGround.isNull() ?
|
||||
this->getGroundElevation() :
|
||||
CAltitude(this->getGroundElevation() + cgAboveGround, CAltitude::MeanSeaLevel));
|
||||
return (groundElevation <= this->getAltitude()) ? this->getAltitude() : groundElevation;
|
||||
if (this->getGroundElevation().isNull()) { return this->getAltitude(); }
|
||||
if (this->getAltitude().getReferenceDatum() != CAltitude::MeanSeaLevel) { return this->getAltitude(); }
|
||||
if (this->getGroundElevation() < this->getAltitude()) { return this->getAltitude(); }
|
||||
return this->getGroundElevation();
|
||||
}
|
||||
|
||||
void CAircraftSituation::setCallsign(const CCallsign &callsign)
|
||||
|
||||
@@ -132,8 +132,8 @@ namespace BlackMisc
|
||||
//! Get altitude
|
||||
const BlackMisc::Aviation::CAltitude &getAltitude() const { return this->m_position.geodeticHeight(); }
|
||||
|
||||
//! Get altitude under consideration of ground elevation and CG (if available)
|
||||
BlackMisc::Aviation::CAltitude getCorrectedAltitude(const PhysicalQuantities::CLength &cgAboveGround = { 0, nullptr }) const;
|
||||
//! Get altitude under consideration of ground elevation
|
||||
BlackMisc::Aviation::CAltitude getCorrectedAltitude() const;
|
||||
|
||||
//! Set altitude
|
||||
void setAltitude(const BlackMisc::Aviation::CAltitude &altitude) { this->m_position.setGeodeticHeight(altitude); }
|
||||
|
||||
@@ -8,11 +8,13 @@
|
||||
*/
|
||||
|
||||
#include "interpolator.h"
|
||||
#include "blackmisc/aviation/callsign.h"
|
||||
#include "blackmisc/simulation/interpolationhints.h"
|
||||
#include "blackmisc/aviation/callsign.h"
|
||||
#include "blackmisc/pq/length.h"
|
||||
#include <QDateTime>
|
||||
|
||||
using namespace BlackMisc::Aviation;
|
||||
using namespace BlackMisc::PhysicalQuantities;
|
||||
|
||||
namespace BlackMisc
|
||||
{
|
||||
@@ -68,7 +70,7 @@ namespace BlackMisc
|
||||
const auto soonestLanding = std::find_if(partsNewer.begin(), partsNewer.end(), [](auto && p) { return p.isOnGround(); });
|
||||
|
||||
// our clairvoyance is limited by the time offset
|
||||
const double significantPast = 5.0;
|
||||
const double significantPast = 5.0; // \fixme 20170121 KB would it make sense to centrally define the update time (5secs), in case it changes. I see a lot of 5.0 hardcoded here
|
||||
const double predictableFuture = soonestLanding == partsNewer.end() ? 5.0 : std::min(5.0, static_cast<double>(soonestLanding->getTimeOffsetMs()) / 1000.0);
|
||||
|
||||
const double secondsSinceTakeoff = latestTakeoff == partsOlder.end() ? 5.0 : (currentTimeMsSinceEpoch - latestTakeoff->getAdjustedMSecsSinceEpoch()) / 1000.0;
|
||||
@@ -107,10 +109,10 @@ namespace BlackMisc
|
||||
|
||||
void IInterpolator::setGroundElevationFromHint(const CInterpolationHints &hints, CAircraftSituation &situation)
|
||||
{
|
||||
if (hints.getElevation().isNull()) return;
|
||||
if (situation.hasGroundElevation()) return;
|
||||
if (!hints.isWithinRange(situation)) return;
|
||||
situation.setGroundElevation(hints.getElevation().geodeticHeight());
|
||||
if (situation.hasGroundElevation()) { return; }
|
||||
const CAltitude elevation = hints.getGroundElevation(situation);
|
||||
if (elevation.isNull()) { return; }
|
||||
situation.setGroundElevation(elevation);
|
||||
}
|
||||
|
||||
bool IInterpolator::InterpolationStatus::allTrue() const
|
||||
|
||||
@@ -100,8 +100,8 @@ namespace BlackMisc
|
||||
// take hint into account to calculate elevation and above ground level
|
||||
if (!hints.getElevation().isNull())
|
||||
{
|
||||
setGroundElevationFromHint(hints, oldSituation);
|
||||
setGroundElevationFromHint(hints, newSituation);
|
||||
IInterpolator::setGroundElevationFromHint(hints, oldSituation);
|
||||
IInterpolator::setGroundElevationFromHint(hints, newSituation);
|
||||
}
|
||||
|
||||
CAircraftSituation currentSituation(oldSituation);
|
||||
@@ -135,8 +135,8 @@ namespace BlackMisc
|
||||
currentSituation.setPosition(currentPosition);
|
||||
|
||||
// Interpolate altitude: Alt = (AltB - AltA) * t + AltA
|
||||
const CAltitude oldAlt(oldSituation.getCorrectedAltitude(hints.getCGAboveGround()));
|
||||
const CAltitude newAlt(newSituation.getCorrectedAltitude(hints.getCGAboveGround()));
|
||||
const CAltitude oldAlt(oldSituation.getCorrectedAltitude()); // avoid underflow below ground elevation
|
||||
const CAltitude newAlt(newSituation.getCorrectedAltitude());
|
||||
Q_ASSERT_X(oldAlt.getReferenceDatum() == newAlt.getReferenceDatum(), Q_FUNC_INFO, "mismatch in reference"); // otherwise no calculation is possible
|
||||
currentSituation.setAltitude(CAltitude((newAlt - oldAlt)
|
||||
* simulationTimeFraction
|
||||
@@ -149,11 +149,12 @@ namespace BlackMisc
|
||||
const double groundFactor = hints.getAircraftParts().isOnGroundInterpolated();
|
||||
if (groundFactor > 0.0)
|
||||
{
|
||||
const auto &groundElevation = hints.getElevationProvider();
|
||||
if (groundElevation)
|
||||
const CAltitude groundElevation = hints.getGroundElevation(currentSituation);
|
||||
Q_ASSERT_X(groundElevation.getReferenceDatum() == CAltitude::MeanSeaLevel, Q_FUNC_INFO, "Need MSL value");
|
||||
if (!groundElevation.isNull())
|
||||
{
|
||||
currentSituation.setAltitude(CAltitude(currentSituation.getAltitude() * (1.0 - groundFactor)
|
||||
+ groundElevation(currentSituation) * groundFactor,
|
||||
+ groundElevation * groundFactor,
|
||||
oldAlt.getReferenceDatum()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1000,7 +1000,7 @@ namespace BlackSimPlugin
|
||||
SIMCONNECT_DATA_INITPOSITION position;
|
||||
position.Latitude = situation.latitude().value(CAngleUnit::deg());
|
||||
position.Longitude = situation.longitude().value(CAngleUnit::deg());
|
||||
position.Altitude = situation.getCorrectedAltitude(hints.getCGAboveGround()).value(CLengthUnit::ft());
|
||||
position.Altitude = situation.getAltitude().value(CLengthUnit::ft()); // already corrected in interpolator if there is an underflow
|
||||
position.Heading = situation.getHeading().value(CAngleUnit::deg());
|
||||
position.Airspeed = situation.getGroundSpeed().value(CSpeedUnit::kts());
|
||||
|
||||
|
||||
Reference in New Issue
Block a user