Skip to content

Commit

Permalink
Add TLE proxy (#120)
Browse files Browse the repository at this point in the history
  • Loading branch information
sylvain-guillet authored Jul 4, 2023
1 parent 0626908 commit 976f84f
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 5 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ CTestTestfile.cmake
_deps
out/
cmake-build-release/
cmake-build-release-coverage/
cmake-build-debug/
.vscode/
build/lib/
Expand Down
19 changes: 18 additions & 1 deletion IO.Astrodynamics.Tests/APITests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -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) +
Expand Down
28 changes: 28 additions & 0 deletions IO.Astrodynamics/API/DTO/TLEElementsDTO.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
Copyright (c) 2023. Sylvain Guillet ([email protected])
*/

//
// 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
32 changes: 30 additions & 2 deletions IO.Astrodynamics/API/Proxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<IO::Astrodynamics::Body::CelestialBody>(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<double>(epoch)));
auto svDTO = ToStateVectorDTO(sv);
Expand Down Expand Up @@ -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<IO::Astrodynamics::Body::CelestialBody>(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
Expand Down
7 changes: 5 additions & 2 deletions IO.Astrodynamics/API/Proxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <EquinoctialElementsDTO.h>
#include <RaDecDTO.h>
#include <HorizontalDTO.h>
#include <TLEElementsDTO.h>

#pragma region Proxy
#ifdef __cplusplus
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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<int, std::shared_ptr<IO::Astrodynamics::Body::CelestialBody>>
Expand Down

0 comments on commit 976f84f

Please sign in to comment.