mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-17 19:05:31 +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->getOwnAircraftXpdrAsync(&m_xplaneData);
|
||||||
m_serviceProxy->getAllWheelsOnGroundAsync(&m_xplaneData.onGroundAll);
|
m_serviceProxy->getAllWheelsOnGroundAsync(&m_xplaneData.onGroundAll);
|
||||||
m_serviceProxy->getHeightAglMAsync(&m_xplaneData.heightAglM);
|
m_serviceProxy->getHeightAglMAsync(&m_xplaneData.heightAglM);
|
||||||
|
m_serviceProxy->getPressureAltitudeFtAsync(&m_xplaneData.pressureAltitudeFt);
|
||||||
|
|
||||||
CAircraftSituation situation;
|
CAircraftSituation situation;
|
||||||
situation.setPosition({ m_xplaneData.latitudeDeg, m_xplaneData.longitudeDeg, 0 });
|
situation.setPosition({ m_xplaneData.latitudeDeg, m_xplaneData.longitudeDeg, 0 });
|
||||||
const CAltitude altitude { m_xplaneData.altitudeM, CAltitude::MeanSeaLevel, CLengthUnit::m() };
|
const CAltitude altitude { m_xplaneData.altitudeM, CAltitude::MeanSeaLevel, CLengthUnit::m() };
|
||||||
situation.setAltitude(altitude);
|
|
||||||
const CPressure seaLevelPressure({ m_xplaneData.seaLevelPressureInHg, CPressureUnit::inHg() });
|
const CPressure seaLevelPressure({ m_xplaneData.seaLevelPressureInHg, CPressureUnit::inHg() });
|
||||||
const CAltitude pressureAltitude(altitude.toPressureAltitude(seaLevelPressure));
|
const CAltitude pressureAltitude(altitude.toPressureAltitude(seaLevelPressure));
|
||||||
|
if (std::isnan(m_xplaneData.pressureAltitudeFt))
|
||||||
|
{
|
||||||
|
situation.setAltitude(altitude);
|
||||||
situation.setPressureAltitude(pressureAltitude);
|
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.setHeading({ m_xplaneData.trueHeadingDeg, CHeading::True, CAngleUnit::deg() });
|
||||||
situation.setPitch({ m_xplaneData.pitchDeg, CAngleUnit::deg() });
|
situation.setPitch({ m_xplaneData.pitchDeg, CAngleUnit::deg() });
|
||||||
situation.setBank({ m_xplaneData.rollDeg, CAngleUnit::deg() });
|
situation.setBank({ m_xplaneData.rollDeg, CAngleUnit::deg() });
|
||||||
@@ -1076,7 +1088,13 @@ namespace BlackSimPlugin::XPlane
|
|||||||
const CInterpolationResult result = xplaneAircraft.getInterpolation(currentTimestamp, setup, aircraftNumber++);
|
const CInterpolationResult result = xplaneAircraft.getInterpolation(currentTimestamp, setup, aircraftNumber++);
|
||||||
if (result.getInterpolationStatus().hasValidSituation())
|
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
|
// update situation
|
||||||
if (updateAllAircraft || !this->isEqualLastSent(interpolatedSituation))
|
if (updateAllAircraft || !this->isEqualLastSent(interpolatedSituation))
|
||||||
|
|||||||
@@ -75,6 +75,7 @@ namespace BlackSimPlugin::XPlane
|
|||||||
double latitudeDeg = 0; //!< Longitude [deg]
|
double latitudeDeg = 0; //!< Longitude [deg]
|
||||||
double longitudeDeg = 0; //!< Latitude [deg]
|
double longitudeDeg = 0; //!< Latitude [deg]
|
||||||
double altitudeM = 0; //!< Altitude [m]
|
double altitudeM = 0; //!< Altitude [m]
|
||||||
|
double pressureAltitudeFt = 0; //!< Pressure altitude [ft, XP12]
|
||||||
double heightAglM = 0; //!< Height AGL [m]
|
double heightAglM = 0; //!< Height AGL [m]
|
||||||
double groundspeedMs = 0; //!< Ground speed [m/s]
|
double groundspeedMs = 0; //!< Ground speed [m/s]
|
||||||
double pitchDeg = 0; //!< Pitch [deg]
|
double pitchDeg = 0; //!< Pitch [deg]
|
||||||
@@ -283,6 +284,7 @@ namespace BlackSimPlugin::XPlane
|
|||||||
BlackMisc::Simulation::CSimulatedAircraftList m_aircraftAddedFailed; //!< aircraft for which adding failed
|
BlackMisc::Simulation::CSimulatedAircraftList m_aircraftAddedFailed; //!< aircraft for which adding failed
|
||||||
BlackMisc::PhysicalQuantities::CLength m_minSuspicousTerrainProbe { nullptr }; //!< min. distance of "failed" (suspicious) terrain probe requests
|
BlackMisc::PhysicalQuantities::CLength m_minSuspicousTerrainProbe { nullptr }; //!< min. distance of "failed" (suspicious) terrain probe requests
|
||||||
XPlaneData m_xplaneData; //!< XPlane data
|
XPlaneData m_xplaneData; //!< XPlane data
|
||||||
|
BlackMisc::PhysicalQuantities::CLength m_altitudeDelta; //!< XP12 altitude difference cause by temperature effect
|
||||||
|
|
||||||
// statistics
|
// statistics
|
||||||
qint64 m_statsAddMaxTimeMs = -1;
|
qint64 m_statsAddMaxTimeMs = -1;
|
||||||
|
|||||||
@@ -409,6 +409,15 @@ namespace BlackSimPlugin::XPlane
|
|||||||
m_dbusInterface->callDBusAsync(QLatin1String("getAltitudeMslM"), setterCallback(o_altitude));
|
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
|
double CXSwiftBusServiceProxy::getHeightAglM() const
|
||||||
{
|
{
|
||||||
return m_dbusInterface->callDBusRet<double>(QLatin1String("getHeightAglM"));
|
return m_dbusInterface->callDBusRet<double>(QLatin1String("getHeightAglM"));
|
||||||
|
|||||||
@@ -239,6 +239,12 @@ namespace BlackSimPlugin::XPlane
|
|||||||
void getAltitudeMslMAsync(double *o_altitude);
|
void getAltitudeMslMAsync(double *o_altitude);
|
||||||
//! @}
|
//! @}
|
||||||
|
|
||||||
|
//! \copydoc XSwiftBus::CService::getPressureAltitudeFt
|
||||||
|
//! @{
|
||||||
|
double getPressureAltitudeFt() const;
|
||||||
|
void getPressureAltitudeFtAsync(double *o_altitude);
|
||||||
|
//! @}
|
||||||
|
|
||||||
//! \copydoc XSwiftBus::CService::getHeightAglM
|
//! \copydoc XSwiftBus::CService::getHeightAglM
|
||||||
//! @{
|
//! @{
|
||||||
double getHeightAglM() const;
|
double getHeightAglM() const;
|
||||||
|
|||||||
@@ -124,6 +124,9 @@ R"XML(<node>
|
|||||||
<method name="getAltitudeMslM">
|
<method name="getAltitudeMslM">
|
||||||
<arg type="d" direction="out"/>
|
<arg type="d" direction="out"/>
|
||||||
</method>
|
</method>
|
||||||
|
<method name="getPressureAltitudeFt">
|
||||||
|
<arg type="d" direction="out"/>
|
||||||
|
</method>
|
||||||
<method name="getHeightAglM">
|
<method name="getHeightAglM">
|
||||||
<arg type="d" direction="out"/>
|
<arg type="d" direction="out"/>
|
||||||
</method>
|
</method>
|
||||||
|
|||||||
@@ -661,6 +661,13 @@ namespace XSwiftBus
|
|||||||
sendDBusReply(sender, serial, getAltitudeMslM());
|
sendDBusReply(sender, serial, getAltitudeMslM());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
else if (message.getMethodName() == "getPressureAltitudeFt")
|
||||||
|
{
|
||||||
|
queueDBusCall([=]()
|
||||||
|
{
|
||||||
|
sendDBusReply(sender, serial, getPressureAltitudeFt());
|
||||||
|
});
|
||||||
|
}
|
||||||
else if (message.getMethodName() == "getHeightAglM")
|
else if (message.getMethodName() == "getHeightAglM")
|
||||||
{
|
{
|
||||||
queueDBusCall([ = ]()
|
queueDBusCall([ = ]()
|
||||||
|
|||||||
@@ -23,6 +23,7 @@
|
|||||||
#include <XPLM/XPLMNavigation.h>
|
#include <XPLM/XPLMNavigation.h>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
|
#include <limits>
|
||||||
|
|
||||||
//! \cond PRIVATE
|
//! \cond PRIVATE
|
||||||
#define XSWIFTBUS_SERVICE_INTERFACENAME "org.swift_project.xswiftbus.service"
|
#define XSWIFTBUS_SERVICE_INTERFACENAME "org.swift_project.xswiftbus.service"
|
||||||
@@ -134,6 +135,10 @@ namespace XSwiftBus
|
|||||||
//! Get aircraft altitude in meters
|
//! Get aircraft altitude in meters
|
||||||
double getAltitudeMslM() const { return m_elevation.get(); }
|
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
|
//! Get aircraft height in meters
|
||||||
double getHeightAglM() const { return m_agl.get(); }
|
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::latitude> m_latitude;
|
||||||
DataRef<xplane::data::sim::flightmodel::position::longitude> m_longitude;
|
DataRef<xplane::data::sim::flightmodel::position::longitude> m_longitude;
|
||||||
DataRef<xplane::data::sim::flightmodel::position::elevation> m_elevation;
|
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::y_agl> m_agl;
|
||||||
DataRef<xplane::data::sim::flightmodel::position::groundspeed> m_groundSpeed;
|
DataRef<xplane::data::sim::flightmodel::position::groundspeed> m_groundSpeed;
|
||||||
DataRef<xplane::data::sim::flightmodel::position::indicated_airspeed2> m_indicatedAirspeed;
|
DataRef<xplane::data::sim::flightmodel::position::indicated_airspeed2> m_indicatedAirspeed;
|
||||||
|
|||||||
Reference in New Issue
Block a user