Skip to content

Commit 2ccee12

Browse files
committed
[XP] Get the ground elevation under the own aircraft
1 parent f5a9452 commit 2ccee12

File tree

8 files changed

+42
-0
lines changed

8 files changed

+42
-0
lines changed

src/plugins/simulator/xplane/simulatorxplane.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,7 @@ namespace BlackSimPlugin::XPlane
321321
m_serviceProxy->getOwnAircraftCom2DataAsync(&m_xplaneData);
322322
m_serviceProxy->getOwnAircraftXpdrAsync(&m_xplaneData);
323323
m_serviceProxy->getAllWheelsOnGroundAsync(&m_xplaneData.onGroundAll);
324+
m_serviceProxy->getGroundElevationAsync(&m_xplaneData.groundElevation);
324325

325326
CAircraftSituation situation;
326327
situation.setPosition({ m_xplaneData.latitudeDeg, m_xplaneData.longitudeDeg, 0 });
@@ -333,6 +334,8 @@ namespace BlackSimPlugin::XPlane
333334
situation.setPitch({ m_xplaneData.pitchDeg, CAngleUnit::deg() });
334335
situation.setBank({ m_xplaneData.rollDeg, CAngleUnit::deg() });
335336
situation.setGroundSpeed({ m_xplaneData.groundspeedMs, CSpeedUnit::m_s() });
337+
const CAltitude elevation { std::isnan(m_xplaneData.groundElevation) ? 0 : m_xplaneData.groundElevation, CAltitude::MeanSeaLevel, CLengthUnit::m() };
338+
situation.setGroundElevation(elevation, CAircraftSituation::FromProvider);
336339
situation.setVelocity({ m_xplaneData.localXVelocityMs, m_xplaneData.localYVelocityMs, m_xplaneData.localZVelocityMs,
337340
CSpeedUnit::m_s(), m_xplaneData.pitchRadPerSec, m_xplaneData.rollRadPerSec, m_xplaneData.headingRadPerSec,
338341
CAngleUnit::rad(), CTimeUnit::s()});

src/plugins/simulator/xplane/simulatorxplane.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ namespace BlackSimPlugin::XPlane
8686
double rollRadPerSec = 0; //!< Roll angular velocity [rad/s]
8787
double headingRadPerSec = 0; //!< Heading angular velocity [rad/s]
8888
bool onGroundAll = false; //!< All wheels on ground?
89+
double groundElevation = 0; //!< Elevation of ground [m]
8990
int com1ActiveKhz = 122800; //!< COM1 active [kHz]
9091
int com1StandbyKhz = 122800; //!< COM1 standby [kHz]
9192
bool isCom1Receiving = true; //!< COM1 receiving

src/plugins/simulator/xplane/xswiftbusserviceproxy.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -544,6 +544,16 @@ namespace BlackSimPlugin::XPlane
544544
m_dbusInterface->callDBusAsync(QLatin1String("getAllWheelsOnGround"), setterCallback(o_allWheels));
545545
}
546546

547+
double CXSwiftBusServiceProxy::getGroundElevation() const
548+
{
549+
return m_dbusInterface->callDBusRet<double>(QLatin1String("getGroundElevation"));
550+
}
551+
552+
void CXSwiftBusServiceProxy::getGroundElevationAsync(double* o_elevationM)
553+
{
554+
m_dbusInterface->callDBusAsync(QLatin1String("getGroundElevation"), setterCallback(o_elevationM));
555+
}
556+
547557
int CXSwiftBusServiceProxy::getCom1ActiveKhz() const
548558
{
549559
return m_dbusInterface->callDBusRet<int>(QLatin1String("getCom1ActiveKhz"));

src/plugins/simulator/xplane/xswiftbusserviceproxy.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,12 @@ namespace BlackSimPlugin::XPlane
329329
void getAllWheelsOnGroundAsync(bool *o_allWheels);
330330
//! @}
331331

332+
//! Get elevation of ground under the plane (in meters)
333+
//! @{
334+
double getGroundElevation() const;
335+
void getGroundElevationAsync(double *o_elevationM);
336+
//! @}
337+
332338
//! \copydoc XSwiftBus::CService::getCom1ActiveKhz
333339
//! @{
334340
int getCom1ActiveKhz() const;

src/xswiftbus/service.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -766,6 +766,13 @@ namespace XSwiftBus
766766
sendDBusReply(sender, serial, getAllWheelsOnGround());
767767
});
768768
}
769+
else if (message.getMethodName() == "getGroundElevation")
770+
{
771+
queueDBusCall([ = ]()
772+
{
773+
sendDBusReply(sender, serial, getGroundElevation());
774+
});
775+
}
769776
else if (message.getMethodName() == "getCom1ActiveKhz")
770777
{
771778
queueDBusCall([ = ]()

src/xswiftbus/service.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "datarefs.h"
2020
#include "messages.h"
2121
#include "navdatareference.h"
22+
#include "terrainprobe.h"
2223
#include <XPLM/XPLMNavigation.h>
2324
#include <string>
2425
#include <chrono>
@@ -174,6 +175,9 @@ namespace XSwiftBus
174175
//! Get whether all wheels are on the ground
175176
bool getAllWheelsOnGround() const { return m_onGroundAll.get(); }
176177

178+
//! Get elevation of ground under the plane in meters
179+
double getGroundElevation() const { return m_terrainProbe.getElevation(m_latitude.get(), m_longitude.get(), m_elevation.get())[0]; }
180+
177181
//! COM Selection 6/7
178182
//! @{
179183
int getComSelection() const { return m_comAudioSelection.get(); }
@@ -333,6 +337,7 @@ namespace XSwiftBus
333337
int m_disapperMessageWindowTimeMs = 5000;
334338
std::chrono::system_clock::time_point m_disappearMessageWindowTime;
335339
std::vector<CNavDataReference> m_airports;
340+
CTerrainProbe m_terrainProbe;
336341

337342
void readAirportsDatabase();
338343
std::vector<CNavDataReference> findClosestAirports(int number, double latitude, double longitude);

src/xswiftbus/terrainprobe.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,13 @@ namespace XSwiftBus
1818

1919
CTerrainProbe::~CTerrainProbe() { XPLMDestroyProbe(m_ref); }
2020

21+
std::array<double, 3> CTerrainProbe::getElevation(double degreesLatitude, double degreesLongitude, double metersAltitude) const
22+
{
23+
static const std::string callsign = "myself";
24+
bool unused = false;
25+
return getElevation(degreesLatitude, degreesLongitude, metersAltitude, callsign, unused);
26+
}
27+
2128
std::array<double, 3> CTerrainProbe::getElevation(double degreesLatitude, double degreesLongitude, double metersAltitude, const std::string &callsign, bool &o_isWater) const
2229
{
2330
double x, y, z;

src/xswiftbus/terrainprobe.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,10 @@ namespace XSwiftBus
3636
//! Get the elevation in meters at the given point in OpenGL space.
3737
//! \note Due to the Earth's curvature, the OpenGL vertical axis may not be exactly perpendicular to the surface of the geoid.
3838
//! \return NaN if no ground was detected.
39+
//! @{
40+
std::array<double, 3> getElevation(double degreesLatitude, double degreesLongitude, double metersAltitude) const;
3941
std::array<double, 3> getElevation(double degreesLatitude, double degreesLongitude, double metersAltitude, const std::string &callsign, bool &o_isWater) const;
42+
//! @}
4043

4144
private:
4245
XPLMProbeRef m_ref = nullptr;

0 commit comments

Comments
 (0)