mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-22 14:55:36 +08:00
Use new dataref to compensate for XP12 temperature effect on altitude
This commit is contained in:
@@ -322,14 +322,26 @@ namespace BlackSimPlugin::XPlane
|
||||
m_serviceProxy->getOwnAircraftXpdrAsync(&m_xplaneData);
|
||||
m_serviceProxy->getAllWheelsOnGroundAsync(&m_xplaneData.onGroundAll);
|
||||
m_serviceProxy->getHeightAglMAsync(&m_xplaneData.heightAglM);
|
||||
m_serviceProxy->getPressureAltitudeFtAsync(&m_xplaneData.pressureAltitudeFt);
|
||||
|
||||
CAircraftSituation situation;
|
||||
situation.setPosition({ m_xplaneData.latitudeDeg, m_xplaneData.longitudeDeg, 0 });
|
||||
const CAltitude altitude { m_xplaneData.altitudeM, CAltitude::MeanSeaLevel, CLengthUnit::m() };
|
||||
situation.setAltitude(altitude);
|
||||
const CPressure seaLevelPressure({ m_xplaneData.seaLevelPressureInHg, CPressureUnit::inHg() });
|
||||
const CAltitude pressureAltitude(altitude.toPressureAltitude(seaLevelPressure));
|
||||
situation.setPressureAltitude(pressureAltitude);
|
||||
if (std::isnan(m_xplaneData.pressureAltitudeFt))
|
||||
{
|
||||
situation.setAltitude(altitude);
|
||||
situation.setPressureAltitude(pressureAltitude);
|
||||
}
|
||||
else
|
||||
{
|
||||
const CAltitude pressureAltitudeXP12(m_xplaneData.pressureAltitudeFt, CAltitude::MeanSeaLevel, CAltitude::PressureAltitude, CLengthUnit::ft());
|
||||
m_altitudeDelta = pressureAltitude - pressureAltitudeXP12;
|
||||
|
||||
situation.setAltitude({ altitude - m_altitudeDelta, CAltitude::MeanSeaLevel });
|
||||
situation.setPressureAltitude(pressureAltitudeXP12);
|
||||
}
|
||||
situation.setHeading({ m_xplaneData.trueHeadingDeg, CHeading::True, CAngleUnit::deg() });
|
||||
situation.setPitch({ m_xplaneData.pitchDeg, CAngleUnit::deg() });
|
||||
situation.setBank({ m_xplaneData.rollDeg, CAngleUnit::deg() });
|
||||
@@ -1076,7 +1088,13 @@ namespace BlackSimPlugin::XPlane
|
||||
const CInterpolationResult result = xplaneAircraft.getInterpolation(currentTimestamp, setup, aircraftNumber++);
|
||||
if (result.getInterpolationStatus().hasValidSituation())
|
||||
{
|
||||
const CAircraftSituation interpolatedSituation(result);
|
||||
CAircraftSituation interpolatedSituation(result);
|
||||
|
||||
// adjust altitude to compensate for XP12 temperature effect
|
||||
const CLength relativeAltitude = interpolatedSituation.geodeticHeight() - getOwnAircraftPosition().geodeticHeight();
|
||||
const double altitudeDeltaWeight = 2 - qBound(3000.0, relativeAltitude.abs().value(CLengthUnit::ft()), 6000.0) / 3000;
|
||||
const CLength alt = interpolatedSituation.getAltitude() + m_altitudeDelta * altitudeDeltaWeight;
|
||||
interpolatedSituation.setAltitude({ alt, interpolatedSituation.getAltitude().getReferenceDatum() });
|
||||
|
||||
// update situation
|
||||
if (updateAllAircraft || !this->isEqualLastSent(interpolatedSituation))
|
||||
|
||||
@@ -75,6 +75,7 @@ namespace BlackSimPlugin::XPlane
|
||||
double latitudeDeg = 0; //!< Longitude [deg]
|
||||
double longitudeDeg = 0; //!< Latitude [deg]
|
||||
double altitudeM = 0; //!< Altitude [m]
|
||||
double pressureAltitudeFt = 0; //!< Pressure altitude [ft, XP12]
|
||||
double heightAglM = 0; //!< Height AGL [m]
|
||||
double groundspeedMs = 0; //!< Ground speed [m/s]
|
||||
double pitchDeg = 0; //!< Pitch [deg]
|
||||
@@ -283,6 +284,7 @@ namespace BlackSimPlugin::XPlane
|
||||
BlackMisc::Simulation::CSimulatedAircraftList m_aircraftAddedFailed; //!< aircraft for which adding failed
|
||||
BlackMisc::PhysicalQuantities::CLength m_minSuspicousTerrainProbe { nullptr }; //!< min. distance of "failed" (suspicious) terrain probe requests
|
||||
XPlaneData m_xplaneData; //!< XPlane data
|
||||
BlackMisc::PhysicalQuantities::CLength m_altitudeDelta; //!< XP12 altitude difference cause by temperature effect
|
||||
|
||||
// statistics
|
||||
qint64 m_statsAddMaxTimeMs = -1;
|
||||
|
||||
@@ -409,6 +409,15 @@ namespace BlackSimPlugin::XPlane
|
||||
m_dbusInterface->callDBusAsync(QLatin1String("getAltitudeMslM"), setterCallback(o_altitude));
|
||||
}
|
||||
|
||||
double CXSwiftBusServiceProxy::getPressureAltitudeFt() const
|
||||
{
|
||||
return m_dbusInterface->callDBusRet<double>(QLatin1String("getPressureAltitudeFt"));
|
||||
}
|
||||
void CXSwiftBusServiceProxy::getPressureAltitudeFtAsync(double* o_altitude)
|
||||
{
|
||||
m_dbusInterface->callDBusAsync(QLatin1String("getPressureAltitudeFt"), setterCallback(o_altitude));
|
||||
}
|
||||
|
||||
double CXSwiftBusServiceProxy::getHeightAglM() const
|
||||
{
|
||||
return m_dbusInterface->callDBusRet<double>(QLatin1String("getHeightAglM"));
|
||||
|
||||
@@ -239,6 +239,12 @@ namespace BlackSimPlugin::XPlane
|
||||
void getAltitudeMslMAsync(double *o_altitude);
|
||||
//! @}
|
||||
|
||||
//! \copydoc XSwiftBus::CService::getPressureAltitudeFt
|
||||
//! @{
|
||||
double getPressureAltitudeFt() const;
|
||||
void getPressureAltitudeFtAsync(double *o_altitude);
|
||||
//! @}
|
||||
|
||||
//! \copydoc XSwiftBus::CService::getHeightAglM
|
||||
//! @{
|
||||
double getHeightAglM() const;
|
||||
|
||||
@@ -124,6 +124,9 @@ R"XML(<node>
|
||||
<method name="getAltitudeMslM">
|
||||
<arg type="d" direction="out"/>
|
||||
</method>
|
||||
<method name="getPressureAltitudeFt">
|
||||
<arg type="d" direction="out"/>
|
||||
</method>
|
||||
<method name="getHeightAglM">
|
||||
<arg type="d" direction="out"/>
|
||||
</method>
|
||||
|
||||
@@ -661,6 +661,13 @@ namespace XSwiftBus
|
||||
sendDBusReply(sender, serial, getAltitudeMslM());
|
||||
});
|
||||
}
|
||||
else if (message.getMethodName() == "getPressureAltitudeFt")
|
||||
{
|
||||
queueDBusCall([=]()
|
||||
{
|
||||
sendDBusReply(sender, serial, getPressureAltitudeFt());
|
||||
});
|
||||
}
|
||||
else if (message.getMethodName() == "getHeightAglM")
|
||||
{
|
||||
queueDBusCall([ = ]()
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
#include <XPLM/XPLMNavigation.h>
|
||||
#include <string>
|
||||
#include <chrono>
|
||||
#include <limits>
|
||||
|
||||
//! \cond PRIVATE
|
||||
#define XSWIFTBUS_SERVICE_INTERFACENAME "org.swift_project.xswiftbus.service"
|
||||
@@ -134,6 +135,10 @@ namespace XSwiftBus
|
||||
//! Get aircraft altitude in meters
|
||||
double getAltitudeMslM() const { return m_elevation.get(); }
|
||||
|
||||
//! Get aircraft pressure altitude in feet in standard atmosphere in X-Plane 12.
|
||||
//! NaN in earlier versions of X-Plane.
|
||||
double getPressureAltitudeFt() const { return m_pressureAlt.isValid() ? m_pressureAlt.get() : std::numeric_limits<double>::quiet_NaN(); }
|
||||
|
||||
//! Get aircraft height in meters
|
||||
double getHeightAglM() const { return m_agl.get(); }
|
||||
|
||||
@@ -359,6 +364,7 @@ namespace XSwiftBus
|
||||
DataRef<xplane::data::sim::flightmodel::position::latitude> m_latitude;
|
||||
DataRef<xplane::data::sim::flightmodel::position::longitude> m_longitude;
|
||||
DataRef<xplane::data::sim::flightmodel::position::elevation> m_elevation;
|
||||
DataRef<xplane::data::sim::flightmodel2::position::pressure_altitude> m_pressureAlt;
|
||||
DataRef<xplane::data::sim::flightmodel::position::y_agl> m_agl;
|
||||
DataRef<xplane::data::sim::flightmodel::position::groundspeed> m_groundSpeed;
|
||||
DataRef<xplane::data::sim::flightmodel::position::indicated_airspeed2> m_indicatedAirspeed;
|
||||
|
||||
Reference in New Issue
Block a user