Skip to content
This repository has been archived by the owner on Aug 5, 2024. It is now read-only.

Commit

Permalink
Feature/orbital parameters transformation (#16)
Browse files Browse the repository at this point in the history
* Convert equinoctial to state vector API

* Add conic elements transformation

* Polymorphing ConvertToStateVector

* Convert orbital parameters to Equatorial system

* Code cleanup

* Update IO.SDK libraries to v0.9
  • Loading branch information
sylvain-guillet authored Jun 5, 2023
1 parent ecbc295 commit e6bd502
Show file tree
Hide file tree
Showing 62 changed files with 505 additions and 244 deletions.
158 changes: 142 additions & 16 deletions IO.SDK.Net.Tests/APITest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,6 @@ public void ExecuteLaunchScenario()
double start = api.ConvertUTCToTDB(667915130.814600);
double end = api.ConvertUTCToTDB(668174330.814560);

//Define the celestial body from which the launch will occur
CelestialBody celestialBody =
new CelestialBody(id: PlanetsAndMoons.EARTH.NaifId, centerOfMotionId: Stars.Sun.NaifId, "",
new Vector3D(0.0, 0.0, 0.0), 0.0, "", 0, "");

//Define launch site
Site launchSite = new Site(id: 399303, bodyId: PlanetsAndMoons.EARTH.NaifId,
coordinates: new Geodetic(-81.0 * Constants.DEG_RAD, 28.5 * Constants.DEG_RAD, 0.0), name: "S3",
Expand All @@ -50,7 +45,7 @@ public void ExecuteLaunchScenario()
directoryPath: SitePath);

//Define the targeted parking orbit
StateVector parkingOrbit = new StateVector(celestialBody, start, InertialFrame.ICRF.GetDescription(),
StateVector parkingOrbit = new StateVector(399, start, InertialFrame.ICRF.GetDescription(),
new Vector3D(5056554.1874925727, 4395595.4942363985, 0.0),
new Vector3D(-3708.6305608890916, 4266.2914313011433, 6736.8538488755494));

Expand Down Expand Up @@ -91,13 +86,13 @@ public void ExecuteReachOrbitScenario()
scenario.CelestialBodies[2].Id = PlanetsAndMoons.MOON.NaifId;

//Define parking orbit
StateVector parkingOrbit = new StateVector(scenario.CelestialBodies[1], start,
StateVector parkingOrbit = new StateVector(PlanetsAndMoons.EARTH.NaifId, start,
InertialFrame.ICRF.GetDescription(),
new Vector3D(5056554.1874925727, 4395595.4942363985, 0.0),
new Vector3D(-3708.6305608890916, 4266.2914313011433, 6736.8538488755494));

//Define target orbit
StateVector target = new StateVector(scenario.CelestialBodies[1], start, InertialFrame.ICRF.GetDescription(),
StateVector target = new StateVector(PlanetsAndMoons.EARTH.NaifId, start, InertialFrame.ICRF.GetDescription(),
new Vector3D(4390853.7278876612, 5110607.0005866792, 917659.86391987884),
new Vector3D(-4979.4693432656513, 3033.2639866911495, 6933.1803797017265));

Expand Down Expand Up @@ -226,7 +221,7 @@ public void CheckSize()
{
var scenario = new Scenario();
var size = Marshal.SizeOf(scenario);
Assert.Equal(21440, size);
Assert.Equal(19456, size);
}

[Fact]
Expand Down Expand Up @@ -361,7 +356,7 @@ public void FindWindowsInFieldOfViewConstraint()
scenario.CelestialBodies[2].Id = PlanetsAndMoons.MOON.NaifId;

//Define parking orbit
StateVector parkingOrbit = new StateVector(scenario.CelestialBodies[1], start,
StateVector parkingOrbit = new StateVector(PlanetsAndMoons.EARTH.NaifId, start,
InertialFrame.ICRF.GetDescription(),
new Vector3D(6800000.0, 0.0, 0.0),
new Vector3D(0.0, 7656.2204182967143, 0.0));
Expand Down Expand Up @@ -412,8 +407,7 @@ public void ReadEphemeris()
Assert.Equal(643.53061483971885, res[0].Velocity.X);
Assert.Equal(-666.08181440799092, res[0].Velocity.Y);
Assert.Equal(-301.32283209101018, res[0].Velocity.Z);
Assert.Equal(PlanetsAndMoons.EARTH.NaifId, res[0].CenterOfMotion.Id);
Assert.Equal(Stars.Sun.NaifId, res[0].CenterOfMotion.CenterOfMotionId);
Assert.Equal(PlanetsAndMoons.EARTH.NaifId, res[0].CenterOfMotionId);
Assert.Equal(InertialFrame.ICRF.GetDescription(), res[0].Frame);
Assert.Equal(0.0, res[0].Epoch);
}
Expand All @@ -436,7 +430,7 @@ public void ReadOrientation()
scenario.CelestialBodies[2].Id = PlanetsAndMoons.MOON.NaifId;

//Configure parking orbit
StateVector parkingOrbit = new StateVector(scenario.CelestialBodies[1], tdbSearchWindow.Start,
StateVector parkingOrbit = new StateVector(PlanetsAndMoons.EARTH.NaifId, tdbSearchWindow.Start,
InertialFrame.ICRF.GetDescription(),
new Vector3D(6800000.0, 0.0, 0.0),
new Vector3D(0.0, 7656.2204182967143, 0.0));
Expand Down Expand Up @@ -520,7 +514,7 @@ void WriteEphemeris()
sv[i].Velocity.Y = 8.0 + i * 0.001;
sv[i].Velocity.Z = i;
sv[i].Epoch = i;
sv[i].CenterOfMotion.Id = PlanetsAndMoons.EARTH.NaifId;
sv[i].CenterOfMotionId = PlanetsAndMoons.EARTH.NaifId;
sv[i].Frame = InertialFrame.ICRF.GetDescription();
}

Expand All @@ -543,8 +537,7 @@ void WriteEphemeris()
Assert.Equal(8 + i * 0.001, svResult[i].Velocity.Y, 12);
Assert.Equal(i, svResult[i].Velocity.Z, 12);
Assert.Equal(i, svResult[i].Epoch);
Assert.Equal(PlanetsAndMoons.EARTH.NaifId, svResult[i].CenterOfMotion.Id);
Assert.Equal(Stars.Sun.NaifId, svResult[i].CenterOfMotion.CenterOfMotionId);
Assert.Equal(PlanetsAndMoons.EARTH.NaifId, svResult[i].CenterOfMotionId);
Assert.Equal(InertialFrame.ICRF.GetDescription(), svResult[i].Frame);
}
}
Expand Down Expand Up @@ -591,4 +584,137 @@ void TransformFrame()
Assert.Equal(-2.0389340573814659e-09, res.AngularVelocity.Y);
Assert.Equal(7.2921150642488516e-05, res.AngularVelocity.Z);
}

[Fact]
void ConvertEquinoctialElementsToStateVector()
{
//Initialize API
API api = new API();

//Load solar system kernels
api.LoadKernels(new DirectoryInfo(SolarSystemKernelPath));

double p = 1.0e7;
double ecc = 0.1;
double a = p / (1.0 - ecc);
double argp = 30.0 * Constants.DEG_RAD;
double node = 15.0 * Constants.DEG_RAD;
double inc = 10.0 * Constants.DEG_RAD;
double m0 = 45.0 * Constants.DEG_RAD;

//equinoctial elements
double h = ecc * Math.Sin(argp + node);
double k = ecc * Math.Cos(argp + node);
double p2 = Math.Tan(inc / 2.0) * Math.Sin(node);
double q = Math.Tan(inc / 2.0) * Math.Cos(node);
double L = m0 + argp + node;

EquinoctialElements eqDTO = new EquinoctialElements();
eqDTO.Frame = InertialFrame.ICRF.GetDescription();
eqDTO.DeclinationOfThePole = Math.PI * 0.5;
eqDTO.RightAscensionOfThePole = -Math.PI * 0.5;
eqDTO.AscendingNodeLongitudeRate = 0.0;
eqDTO.PeriapsisLongitudeRate = 0.0;
eqDTO.H = h;
eqDTO.P = p2;
eqDTO.SemiMajorAxis = a;
eqDTO.Epoch = 10.0;
eqDTO.CenterOfMotionId = 399;
eqDTO.L = L;
eqDTO.K = k;
eqDTO.Q = q;

var sv = api.ConvertToStateVector(eqDTO);

Assert.Equal(-1557343.2179623565, sv.Position.X);
Assert.Equal(10112046.56492505, sv.Position.Y);
Assert.Equal(1793343.6111546031, sv.Position.Z);
Assert.Equal(-6369.0795341145204, sv.Velocity.X);
Assert.Equal(-517.51239201161684, sv.Velocity.Y);
Assert.Equal(202.52220483204573, sv.Velocity.Z);
}

[Fact]
void ConvertConicElementsToStateVector()
{
//Initialize API
API api = new API();

//Load solar system kernels
api.LoadKernels(new DirectoryInfo(SolarSystemKernelPath));

double perifocalDist = Math.Sqrt(Math.Pow(-6.116559469556896E+06, 2) + Math.Pow(-1.546174698676721E+06, 2) +
Math.Pow(2.521950157430313E+06, 2));

ConicElements conicElements = new ConicElements();
conicElements.Frame = InertialFrame.ICRF.GetDescription();
conicElements.Epoch = 663724800.00001490; //"2021-01-12T11:58:50.816" UTC
conicElements.MeanAnomaly = 4.541224977546975E+01 * Constants.DEG_RAD;
conicElements.PeriapsisArgument = 1.062574316262159E+02 * Constants.DEG_RAD;
conicElements.AscendingNodeLongitude = 3.257605322534260E+01 * Constants.DEG_RAD;
conicElements.Inclination = 5.171921958517460E+01 * Constants.DEG_RAD;
conicElements.Eccentricity = 1.353139738203394E-03;
conicElements.PerifocalDistance = perifocalDist;
conicElements.CenterOfMotionId = 399;

var sv = api.ConvertToStateVector(conicElements);

Assert.Equal(-6119034.915639279, sv.Position.X, 8);
Assert.Equal(-1546800.4544009243, sv.Position.Y, 6);
Assert.Equal(2522970.821362097, sv.Position.Z, 8);
Assert.Equal(-807.6748840709542, sv.Velocity.X, 8);
Assert.Equal(-5476.5381803473965, sv.Velocity.Y, 8);
Assert.Equal(-5296.561721841285, sv.Velocity.Z, 8);
Assert.Equal(663724800.00001490, sv.Epoch);
Assert.Equal(399, sv.CenterOfMotionId);
Assert.Equal(InertialFrame.ICRF.GetDescription(), sv.Frame);
}

[Fact]
void ConvertStateVectorToRaDec()
{
//Initialize API
API api = new API();

//Load solar system kernels
api.LoadKernels(new DirectoryInfo(SolarSystemKernelPath));

var sv = new StateVector();
sv.CenterOfMotionId = PlanetsAndMoons.EARTH.NaifId;
sv.Epoch = 0.0;
sv.Position = new Vector3D(-291608384.63344, -266716833.39423, -76102487.09990);
sv.Velocity = new Vector3D(643.53139, -666.08768, -301.32570);
sv.Frame = InertialFrame.ICRF.GetDescription();

var radec = api.ConvertToEquatorialCoordinates(sv);
Assert.Equal(222.4472994995566, radec.RightAscencion * Constants.RAD_DEG);
Assert.Equal(-10.900186051699306, radec.Declination * Constants.RAD_DEG);
Assert.Equal(402448639.887328, radec.Radius);
}

[Fact]
void ConvertConicOrbitalElementsToRaDec()
{
//Initialize API
API api = new API();

//Load solar system kernels
api.LoadKernels(new DirectoryInfo(SolarSystemKernelPath));

var conics = new ConicElements();
conics.CenterOfMotionId = PlanetsAndMoons.EARTH.NaifId;
conics.Epoch = 0.0;
conics.Frame = InertialFrame.ICRF.GetDescription();
conics.PerifocalDistance = 365451161.74144;
conics.Eccentricity = 0.05357474;
conics.Inclination = 20.94230395 * Constants.DEG_RAD;
conics.AscendingNodeLongitude = 12.23643846 * Constants.DEG_RAD;
conics.PeriapsisArgument = 68.05335129 * Constants.DEG_RAD;
conics.MeanAnomaly = 140.14966394 * Constants.DEG_RAD;

var radec = api.ConvertToEquatorialCoordinates(conics);
Assert.Equal(222.4472992707561, radec.RightAscencion * Constants.RAD_DEG);
Assert.Equal(-10.900185977212049, radec.Declination * Constants.RAD_DEG);
Assert.Equal(402448637.2542864, radec.Radius);
}
}
Loading

0 comments on commit e6bd502

Please sign in to comment.