From 976f84fb45c57891db7300c92bccc6b86a6c24cc Mon Sep 17 00:00:00 2001 From: sylvain-guillet Date: Tue, 4 Jul 2023 17:42:24 +0200 Subject: [PATCH] Add TLE proxy (#120) --- .gitignore | 1 + IO.Astrodynamics.Tests/APITests.cpp | 19 +++++++++++++- IO.Astrodynamics/API/DTO/TLEElementsDTO.h | 28 ++++++++++++++++++++ IO.Astrodynamics/API/Proxy.cpp | 32 +++++++++++++++++++++-- IO.Astrodynamics/API/Proxy.h | 7 +++-- 5 files changed, 82 insertions(+), 5 deletions(-) create mode 100644 IO.Astrodynamics/API/DTO/TLEElementsDTO.h diff --git a/.gitignore b/.gitignore index 5d1f982e..24364fd0 100644 --- a/.gitignore +++ b/.gitignore @@ -11,6 +11,7 @@ CTestTestfile.cmake _deps out/ cmake-build-release/ +cmake-build-release-coverage/ cmake-build-debug/ .vscode/ build/lib/ diff --git a/IO.Astrodynamics.Tests/APITests.cpp b/IO.Astrodynamics.Tests/APITests.cpp index d81e7e7e..cd62ce59 100644 --- a/IO.Astrodynamics.Tests/APITests.cpp +++ b/IO.Astrodynamics.Tests/APITests.cpp @@ -443,7 +443,7 @@ TEST(API, TransformFrame) TEST(API, ConvertTLEToStateVectorProxy) { IO::Astrodynamics::Time::TDB epoch("2021-01-20T18:50:13.663106"); - auto stateVector = ConvertTLEToStateVectorProxy( + auto stateVector = ConvertTLEToStateVectorProxy("ISS", "1 25544U 98067A 21020.53488036 .00016717 00000-0 10270-3 0 9054", "2 25544 51.6423 353.0312 0000493 320.8755 39.2360 15.49309423 25703", epoch.GetSecondsFromJ2000().count()); @@ -456,6 +456,23 @@ TEST(API, ConvertTLEToStateVectorProxy) ASSERT_DOUBLE_EQ(664440682.84760022, stateVector.epoch); } +TEST(API, GetTLEElementsProxy) +{ + auto res = GetTLEElementsProxy("ISS", + "1 25544U 98067A 21020.53488036 .00016717 00000-0 10270-3 0 9054", + "2 25544 51.6423 353.0312 0000493 320.8755 39.2360 15.49309423 25703"); + ASSERT_DOUBLE_EQ(6803376.2171725659, res.A); + ASSERT_DOUBLE_EQ(4.9299999999999999e-05, res.E); + ASSERT_DOUBLE_EQ(0.9013281683026676, res.I); + ASSERT_DOUBLE_EQ(6.1615568022666061, res.O); + ASSERT_DOUBLE_EQ(5.6003339639830649, res.W); + ASSERT_DOUBLE_EQ(0.68479738531249512, res.M); + ASSERT_DOUBLE_EQ(664419082.8475914, res.Epoch); + ASSERT_DOUBLE_EQ(5.06539394194257e-10, res.BalisticCoefficient); + ASSERT_DOUBLE_EQ(0.0001027, res.DragTerm); + ASSERT_DOUBLE_EQ(0.0, res.SecondDerivativeOfMeanMotion); +} + TEST(API, ConvertConicOrbitalElementsToStateVector) { double perifocalDist = std::sqrt(std::pow(-6.116559469556896E+06, 2) + std::pow(-1.546174698676721E+06, 2) + diff --git a/IO.Astrodynamics/API/DTO/TLEElementsDTO.h b/IO.Astrodynamics/API/DTO/TLEElementsDTO.h new file mode 100644 index 00000000..c99a333f --- /dev/null +++ b/IO.Astrodynamics/API/DTO/TLEElementsDTO.h @@ -0,0 +1,28 @@ +/* + Copyright (c) 2023. Sylvain Guillet (sylvain.guillet@tutamail.com) + */ + +// +// Created by spacer on 7/4/23. +// + +#ifndef IO_TLEELEMENTSDTO_H +#define IO_TLEELEMENTSDTO_H +namespace IO::Astrodynamics::API::DTO +{ + struct TLEElementsDTO + { + double BalisticCoefficient{}; + double SecondDerivativeOfMeanMotion{}; + double DragTerm{}; + double Epoch{}; + double A{}; + double E{}; + double I{}; + double W{}; + double O{}; + double M{}; + const char *Error{}; + }; +} +#endif //IO_TLEELEMENTSDTO_H diff --git a/IO.Astrodynamics/API/Proxy.cpp b/IO.Astrodynamics/API/Proxy.cpp index 262efcda..bd07ad9d 100644 --- a/IO.Astrodynamics/API/Proxy.cpp +++ b/IO.Astrodynamics/API/Proxy.cpp @@ -628,11 +628,11 @@ TransformFrameProxy(const char *fromFrame, const char *toFrame, double epoch) return frameTransformationDto; } -IO::Astrodynamics::API::DTO::StateVectorDTO ConvertTLEToStateVectorProxy(const char *L1, const char *L2, double epoch) +IO::Astrodynamics::API::DTO::StateVectorDTO ConvertTLEToStateVectorProxy(const char *L1, const char *L2, const char *L3, double epoch) { ActivateErrorManagement(); auto earth = std::make_shared(399); - std::string strings[3] = {"ISS", L1, L2}; + std::string strings[3] = {L1, L2, L3}; IO::Astrodynamics::OrbitalParameters::TLE tle(earth, strings); auto sv = tle.ToStateVector(IO::Astrodynamics::Time::TDB(std::chrono::duration(epoch))); auto svDTO = ToStateVectorDTO(sv); @@ -743,6 +743,34 @@ IO::Astrodynamics::API::DTO::StateVectorDTO ReadEphemerisAtGivenEpochProxy(doubl return stateVectorDto; } +IO::Astrodynamics::API::DTO::TLEElementsDTO GetTLEElementsProxy(const char *L1, const char *L2, const char *L3) +{ + ActivateErrorManagement(); + std::string lines[3]{L1, L2, L3}; + auto earth = std::make_shared(399); + IO::Astrodynamics::OrbitalParameters::TLE tle(earth, lines); + + IO::Astrodynamics::API::DTO::TLEElementsDTO tleElementsDto; + + tleElementsDto.A = tle.GetSemiMajorAxis(); + tleElementsDto.E = tle.GetEccentricity(); + tleElementsDto.I = tle.GetInclination(); + tleElementsDto.O = tle.GetRightAscendingNodeLongitude(); + tleElementsDto.W = tle.GetPeriapsisArgument(); + tleElementsDto.M = tle.GetMeanAnomaly(); + + tleElementsDto.Epoch = tle.GetEpoch().GetSecondsFromJ2000().count(); + + tleElementsDto.BalisticCoefficient = tle.GetBalisticCoefficient(); + tleElementsDto.DragTerm = tle.GetDragTerm(); + tleElementsDto.SecondDerivativeOfMeanMotion = tle.GetSecondDerivativeOfMeanMotion(); + if (failed_c()) + { + tleElementsDto.Error = strdup(HandleError()); + } + return tleElementsDto; +} + #pragma endregion #pragma region ReadResults diff --git a/IO.Astrodynamics/API/Proxy.h b/IO.Astrodynamics/API/Proxy.h index 55052cb5..7d094199 100644 --- a/IO.Astrodynamics/API/Proxy.h +++ b/IO.Astrodynamics/API/Proxy.h @@ -11,6 +11,7 @@ #include #include #include +#include #pragma region Proxy #ifdef __cplusplus @@ -252,7 +253,7 @@ MODULE_API IO::Astrodynamics::API::DTO::FrameTransformationDTO TransformFramePro * @param epoch * @return */ -MODULE_API IO::Astrodynamics::API::DTO::StateVectorDTO ConvertTLEToStateVectorProxy(const char *L1, const char *L2, double epoch); +MODULE_API IO::Astrodynamics::API::DTO::StateVectorDTO ConvertTLEToStateVectorProxy(const char *L1, const char *L2, const char *L3, double epoch); /** * Convert conic orbital elements to state vector @@ -275,6 +276,7 @@ MODULE_API IO::Astrodynamics::API::DTO::StateVectorDTO ConvertEquinoctialElement */ MODULE_API IO::Astrodynamics::API::DTO::RaDecDTO ConvertStateVectorToEquatorialCoordinatesProxy(IO::Astrodynamics::API::DTO::StateVectorDTO stateVectorDto); MODULE_API IO::Astrodynamics::API::DTO::HorizontalDTO GetHorizontalCoordinates(IO::Astrodynamics::API::DTO::StateVectorDTO stateVectorDto); +MODULE_API IO::Astrodynamics::API::DTO::TLEElementsDTO GetTLEElementsProxy(const char *L1, const char *L2, const char *L3); #ifdef __cplusplus } #endif @@ -286,7 +288,8 @@ MODULE_API IO::Astrodynamics::API::DTO::HorizontalDTO GetHorizontalCoordinates(I static constexpr const int lenout = 33; -char * HandleError(); +char *HandleError(); + void ActivateErrorManagement(); std::map>