-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #552 from AndyTWF/glideslop-drift
Glideslop deviation
- Loading branch information
Showing
38 changed files
with
849 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# Glideslope Deviation | ||
|
||
The glideslope deviation TAG item displays the aircrafts current deviation from the glideslope. It does this by looking at the aircraft current position | ||
along the localiser (by taking a perpendicular line from the aircraft to the localiser) and then calculating the difference between the aircrafts altitude | ||
and the altitude of the glideslope at that point. | ||
|
||
## TAG Item | ||
|
||
The "Glideslope Deviation" TAG item displays the current deviation from the glideslope in the format of `+/-XXX` where `XXX` is the deviation in feet. It will display in | ||
green when the aircraft is within a few hundred feet of or below the glideslope, and red when the aircraft is above the glideslope. If the aircraft is massively above or below the | ||
glideslope, the deviation will be displayed as `>/<1k`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#include "GlideslopeDeviationEstimator.h" | ||
#include "euroscope/EuroScopeCRadarTargetInterface.h" | ||
#include "runway/Runway.h" | ||
|
||
namespace UKControllerPlugin::Approach { | ||
|
||
auto GlideslopeDeviationEstimator::CalculateGlideslopeDeviation( | ||
const Euroscope::EuroScopeCRadarTargetInterface& radarTarget, const Runway::Runway& runway) const | ||
-> GlideslopeDeviation | ||
{ | ||
// Calculate the slope of each line | ||
const auto runwaySlope = runway.RunwayHeadingLineSlope(); | ||
const auto runwayPerpendicularSlope = runway.RunwayPerpendicularHeadingLineSlope(); | ||
|
||
// Calculate the distance between the intersection and the threshold | ||
EuroScopePlugIn::CPosition intersection; | ||
intersection.m_Latitude = (runwaySlope * runway.Threshold().m_Latitude - | ||
runwayPerpendicularSlope * radarTarget.GetPosition().m_Latitude + | ||
radarTarget.GetPosition().m_Longitude - runway.Threshold().m_Longitude) / | ||
(runwaySlope - runwayPerpendicularSlope); | ||
intersection.m_Longitude = | ||
runwaySlope * (intersection.m_Latitude - runway.Threshold().m_Latitude) + runway.Threshold().m_Longitude; | ||
const auto distance = runway.Threshold().DistanceTo(intersection); | ||
|
||
return { | ||
.deviation = radarTarget.GetAltitude() - runway.GlideslopeAltitudeAtDistance(distance), | ||
.perpendicularDistanceFromLocaliser = radarTarget.GetPosition().DistanceTo(intersection), | ||
.localiserRange = distance}; | ||
} | ||
} // namespace UKControllerPlugin::Approach |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#pragma once | ||
|
||
namespace UKControllerPlugin { | ||
namespace Euroscope { | ||
class EuroScopeCRadarTargetInterface; | ||
} // namespace Euroscope | ||
namespace Runway { | ||
class Runway; | ||
} // namespace Runway | ||
} // namespace UKControllerPlugin | ||
|
||
namespace UKControllerPlugin::Approach { | ||
// Struct representing glideslope deviation | ||
struct GlideslopeDeviation | ||
{ | ||
int deviation; | ||
double perpendicularDistanceFromLocaliser; | ||
double localiserRange; | ||
}; | ||
|
||
class GlideslopeDeviationEstimator | ||
{ | ||
public: | ||
[nodiscard] auto CalculateGlideslopeDeviation( | ||
const Euroscope::EuroScopeCRadarTargetInterface& radarTarget, | ||
const Runway::Runway& runway) const -> GlideslopeDeviation; | ||
}; | ||
} // namespace UKControllerPlugin::Approach |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
#include "GlideslopeDeviationEstimator.h" | ||
#include "GlideslopeDeviationTagItem.h" | ||
#include "euroscope/EuroScopeCFlightPlanInterface.h" | ||
#include "euroscope/EuroScopeCRadarTargetInterface.h" | ||
#include "runway/Runway.h" | ||
#include "runway/RunwayCollection.h" | ||
#include "tag/TagData.h" | ||
|
||
namespace UKControllerPlugin::Approach { | ||
GlideslopeDeviationTagItem::GlideslopeDeviationTagItem( | ||
std::shared_ptr<const GlideslopeDeviationEstimator> glideslopeDeviationEstimator, | ||
std::shared_ptr<const Runway::RunwayCollection> runways) | ||
: glideslopeDeviationEstimator(glideslopeDeviationEstimator), runways(runways) | ||
{ | ||
assert(this->glideslopeDeviationEstimator != nullptr && "Glideslope deviation estimator cannot be null"); | ||
assert(this->runways != nullptr && "Runways cannot be null"); | ||
} | ||
|
||
std::string GlideslopeDeviationTagItem::GetTagItemDescription(int tagItemId) const | ||
{ | ||
switch (tagItemId) { | ||
case 132: | ||
return "Glideslope Deviation"; | ||
default: | ||
throw std::invalid_argument("Invalid tag item ID"); | ||
} | ||
} | ||
|
||
void GlideslopeDeviationTagItem::SetTagItemData(Tag::TagData& tagData) | ||
{ | ||
const auto& flightplan = tagData.GetFlightplan(); | ||
|
||
// Get the runway | ||
const auto runway = | ||
runways->GetByAirfieldAndIdentifier(flightplan.GetDestination(), flightplan.GetArrivalRunway()); | ||
if (runway == nullptr) { | ||
return; | ||
} | ||
|
||
// Make sure we're upwind of the runway | ||
if (std::abs(tagData.GetRadarTarget().GetPosition().DirectionTo(runway->Threshold()) - runway->Heading()) > | ||
90) { | ||
return; | ||
} | ||
|
||
// Calculate the deviation and make sure we're somewhat close | ||
const auto deviation = | ||
glideslopeDeviationEstimator->CalculateGlideslopeDeviation(tagData.GetRadarTarget(), *runway); | ||
if (deviation.perpendicularDistanceFromLocaliser > 15) { | ||
return; | ||
} | ||
|
||
if (deviation.localiserRange > 25) { | ||
return; | ||
} | ||
|
||
// Set the tag colour to red if we're massively out | ||
if (deviation.deviation > 300) { | ||
tagData.SetTagColour(RGB(255, 87, 51)); | ||
} | ||
|
||
// If we're massively out, abbreviate the string | ||
if (deviation.deviation > 999) { | ||
tagData.SetItemString(">1k"); | ||
return; | ||
} else if (deviation.deviation < -999) { | ||
tagData.SetItemString("<1k"); | ||
return; | ||
} | ||
|
||
// Set the tag item string | ||
const auto deviationSign = deviation.deviation >= 0 ? "+" : ""; | ||
tagData.SetItemString(deviationSign + std::to_string(deviation.deviation)); | ||
} | ||
} // namespace UKControllerPlugin::Approach |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#pragma once | ||
#include "tag/TagItemInterface.h" | ||
|
||
namespace UKControllerPlugin { | ||
namespace Runway { | ||
class RunwayCollection; | ||
} // namespace Runway | ||
} // namespace UKControllerPlugin | ||
|
||
namespace UKControllerPlugin::Approach { | ||
|
||
class GlideslopeDeviationEstimator; | ||
|
||
class GlideslopeDeviationTagItem : public Tag::TagItemInterface | ||
{ | ||
public: | ||
GlideslopeDeviationTagItem( | ||
std::shared_ptr<const GlideslopeDeviationEstimator> glideslopeDeviationEstimator, | ||
std::shared_ptr<const Runway::RunwayCollection> runways); | ||
auto GetTagItemDescription(int tagItemId) const -> std::string override; | ||
void SetTagItemData(Tag::TagData& tagData) override; | ||
|
||
private: | ||
// The glideslope deviation estimator | ||
std::shared_ptr<const GlideslopeDeviationEstimator> glideslopeDeviationEstimator; | ||
|
||
// The runways | ||
std::shared_ptr<const Runway::RunwayCollection> runways; | ||
}; | ||
|
||
} // namespace UKControllerPlugin::Approach |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#include "Angle.h" | ||
|
||
namespace UKControllerPlugin::Geometry { | ||
|
||
const double pi = 3.14159265358979323846; | ||
|
||
auto DegreesToRadians(const double degrees) -> double | ||
{ | ||
return degrees * pi / 180; | ||
} | ||
|
||
auto RadiansToDegrees(const double radians) -> double | ||
{ | ||
return radians * 180 / pi; | ||
} | ||
|
||
auto Slope(const double radians) -> double | ||
{ | ||
return std::tan(radians); | ||
} | ||
} // namespace UKControllerPlugin::Geometry |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#pragma once | ||
|
||
namespace UKControllerPlugin::Geometry { | ||
[[nodiscard]] auto DegreesToRadians(const double degrees) -> double; | ||
[[nodiscard]] auto RadiansToDegrees(const double radians) -> double; | ||
[[nodiscard]] auto Slope(const double radians) -> double; | ||
|
||
} // namespace UKControllerPlugin::Geometry |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#pragma once | ||
|
||
namespace UKControllerPlugin::Geometry { | ||
[[nodiscard]] inline auto NauticalMilesToFeet(double nauticalMiles) -> double | ||
{ | ||
return nauticalMiles * 6076.115; | ||
} | ||
|
||
[[nodiscard]] inline auto FeetToNauticalMiles(double feet) -> double | ||
{ | ||
return feet / 6076.115; | ||
} | ||
} // namespace UKControllerPlugin::Geometry |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.