use of org.orekit.attitudes.LofOffset in project Orekit by CS-SI.
the class EphemerisTest method testAttitudeOverride.
@Test
public void testAttitudeOverride() throws IllegalArgumentException, OrekitException {
final double positionTolerance = 1e-6;
final double velocityTolerance = 1e-5;
final double attitudeTolerance = 1e-6;
int numberOfInterals = 1440;
double deltaT = finalDate.durationFrom(initDate) / ((double) numberOfInterals);
propagator.setAttitudeProvider(new LofOffset(inertialFrame, LOFType.VVLH));
List<SpacecraftState> states = new ArrayList<SpacecraftState>(numberOfInterals + 1);
for (int j = 0; j <= numberOfInterals; j++) {
states.add(propagator.propagate(initDate.shiftedBy((j * deltaT))));
}
int numInterpolationPoints = 2;
Ephemeris ephemPropagator = new Ephemeris(states, numInterpolationPoints);
Assert.assertEquals(0, ephemPropagator.getManagedAdditionalStates().length);
// First test that we got position, velocity and attitude nailed
int numberEphemTestIntervals = 2880;
deltaT = finalDate.durationFrom(initDate) / ((double) numberEphemTestIntervals);
for (int j = 0; j <= numberEphemTestIntervals; j++) {
AbsoluteDate currentDate = initDate.shiftedBy(j * deltaT);
SpacecraftState ephemState = ephemPropagator.propagate(currentDate);
SpacecraftState keplerState = propagator.propagate(currentDate);
double positionDelta = calculatePositionDelta(ephemState, keplerState);
double velocityDelta = calculateVelocityDelta(ephemState, keplerState);
double attitudeDelta = calculateAttitudeDelta(ephemState, keplerState);
Assert.assertEquals("VVLH Unmatched Position at: " + currentDate, 0.0, positionDelta, positionTolerance);
Assert.assertEquals("VVLH Unmatched Velocity at: " + currentDate, 0.0, velocityDelta, velocityTolerance);
Assert.assertEquals("VVLH Unmatched Attitude at: " + currentDate, 0.0, attitudeDelta, attitudeTolerance);
}
// Now force an override on the attitude and check it against a Keplerian propagator
// setup identically to the first but with a different attitude
// If override isn't working this will fail.
propagator = new KeplerianPropagator(propagator.getInitialState().getOrbit());
propagator.setAttitudeProvider(new LofOffset(inertialFrame, LOFType.QSW));
ephemPropagator.setAttitudeProvider(new LofOffset(inertialFrame, LOFType.QSW));
for (int j = 0; j <= numberEphemTestIntervals; j++) {
AbsoluteDate currentDate = initDate.shiftedBy(j * deltaT);
SpacecraftState ephemState = ephemPropagator.propagate(currentDate);
SpacecraftState keplerState = propagator.propagate(currentDate);
double positionDelta = calculatePositionDelta(ephemState, keplerState);
double velocityDelta = calculateVelocityDelta(ephemState, keplerState);
double attitudeDelta = calculateAttitudeDelta(ephemState, keplerState);
Assert.assertEquals("QSW Unmatched Position at: " + currentDate, 0.0, positionDelta, positionTolerance);
Assert.assertEquals("QSW Unmatched Velocity at: " + currentDate, 0.0, velocityDelta, velocityTolerance);
Assert.assertEquals("QSW Unmatched Attitude at: " + currentDate, 0.0, attitudeDelta, attitudeTolerance);
}
}
use of org.orekit.attitudes.LofOffset in project Orekit by CS-SI.
the class EphemerisTest method testProtectedMethods.
@Test
public void testProtectedMethods() throws OrekitException, SecurityException, NoSuchMethodException, InvocationTargetException, IllegalAccessException {
propagator.setAttitudeProvider(new LofOffset(inertialFrame, LOFType.VVLH));
List<SpacecraftState> states = new ArrayList<SpacecraftState>();
for (double dt = 0; dt >= -1200; dt -= 60.0) {
final SpacecraftState original = propagator.propagate(initDate.shiftedBy(dt));
final SpacecraftState modified = new SpacecraftState(original.getOrbit(), original.getAttitude(), original.getMass() - 0.0625 * dt);
states.add(modified);
}
final Propagator ephem = new Ephemeris(states, 2);
Method propagateOrbit = Ephemeris.class.getDeclaredMethod("propagateOrbit", AbsoluteDate.class);
propagateOrbit.setAccessible(true);
Method getMass = Ephemeris.class.getDeclaredMethod("getMass", AbsoluteDate.class);
getMass.setAccessible(true);
SpacecraftState s = ephem.propagate(initDate.shiftedBy(-270.0));
Orbit o = (Orbit) propagateOrbit.invoke(ephem, s.getDate());
double m = ((Double) getMass.invoke(ephem, s.getDate())).doubleValue();
Assert.assertEquals(0.0, Vector3D.distance(s.getPVCoordinates().getPosition(), o.getPVCoordinates().getPosition()), 1.0e-15);
Assert.assertEquals(s.getMass(), m, 1.0e-15);
}
use of org.orekit.attitudes.LofOffset in project Orekit by CS-SI.
the class FieldEcksteinHechlerPropagatorTest method doPropagatedKeplerian.
private <T extends RealFieldElement<T>> void doPropagatedKeplerian(Field<T> field) throws OrekitException {
T zero = field.getZero();
FieldAbsoluteDate<T> date = new FieldAbsoluteDate<>(field);
// Definition of initial conditions with Keplerian parameters
// -----------------------------------------------------------
FieldAbsoluteDate<T> initDate = date.shiftedBy(584.);
FieldOrbit<T> initialOrbit = new FieldKeplerianOrbit<>(zero.add(7209668.0), zero.add(0.5e-4), zero.add(1.7), zero.add(2.1), zero.add(2.9), zero.add(6.2), PositionAngle.TRUE, FramesFactory.getEME2000(), initDate, provider.getMu());
// Extrapolator definition
// -----------------------
FieldEcksteinHechlerPropagator<T> extrapolator = new FieldEcksteinHechlerPropagator<>(initialOrbit, new LofOffset(initialOrbit.getFrame(), LOFType.VNC), zero.add(2000.0), provider);
// Extrapolation at a final date different from initial date
// ---------------------------------------------------------
// extrapolation duration in seconds
double delta_t = 100000.0;
FieldAbsoluteDate<T> extrapDate = initDate.shiftedBy(delta_t);
FieldSpacecraftState<T> finalOrbit = extrapolator.propagate(extrapDate);
Assert.assertEquals(0.0, finalOrbit.getDate().durationFrom(extrapDate).getReal(), 1.0e-9);
// computation of M final orbit
T LM = finalOrbit.getLE().subtract(finalOrbit.getEquinoctialEx().multiply(finalOrbit.getLE().sin())).add(finalOrbit.getEquinoctialEy().multiply(finalOrbit.getLE().cos()));
Assert.assertEquals(LM.getReal(), finalOrbit.getLM().getReal(), Utils.epsilonAngle);
// test of tan((LE - Lv)/2) :
Assert.assertEquals(FastMath.tan((finalOrbit.getLE().getReal() - finalOrbit.getLv().getReal()) / 2.), tangLEmLv(finalOrbit.getLv(), finalOrbit.getEquinoctialEx(), finalOrbit.getEquinoctialEy()).getReal(), Utils.epsilonAngle);
// test of evolution of M vs E: LM = LE - ex*sin(LE) + ey*cos(LE)
// with ex and ey the same for initial and final orbit
T deltaM = finalOrbit.getLM().subtract(initialOrbit.getLM());
T deltaE = finalOrbit.getLE().subtract(initialOrbit.getLE());
T delta = finalOrbit.getEquinoctialEx().multiply(finalOrbit.getLE().sin()).subtract(initialOrbit.getEquinoctialEx().multiply(initialOrbit.getLE().sin())).subtract(finalOrbit.getEquinoctialEy().multiply(finalOrbit.getLE().cos())).add(initialOrbit.getEquinoctialEy().multiply(initialOrbit.getLE().cos()));
Assert.assertEquals(deltaM.getReal(), deltaE.getReal() - delta.getReal(), Utils.epsilonAngle * FastMath.abs(deltaE.getReal() - delta.getReal()));
// for final orbit
T ex = finalOrbit.getEquinoctialEx();
T ey = finalOrbit.getEquinoctialEy();
T hx = finalOrbit.getHx();
T hy = finalOrbit.getHy();
T LE = finalOrbit.getLE();
T ex2 = ex.multiply(ex);
T ey2 = ey.multiply(ey);
T hx2 = hx.multiply(hx);
T hy2 = hy.multiply(hy);
T h2p1 = hx2.add(1).add(hy2);
T beta = ex2.negate().add(1.).subtract(ey2).sqrt().add(1).reciprocal();
T x3 = ex.negate().add(beta.negate().multiply(ey2).add(1).multiply(LE.cos())).add(beta.multiply(ex).multiply(ey).multiply(LE.sin()));
T y3 = ey.negate().add(beta.negate().multiply(ex2).add(1).multiply(LE.sin())).add(beta.multiply(ex).multiply(ey).multiply(LE.cos()));
FieldVector3D<T> U = new FieldVector3D<>(hx2.subtract(hy2).add(1.).divide(h2p1), hx.multiply(2).multiply(hy).divide(h2p1), hy.multiply(-2.).divide(h2p1));
FieldVector3D<T> V = new FieldVector3D<>(hx.multiply(2.).multiply(hy).divide(h2p1), hy2.subtract(hx2).add(1.).divide(h2p1), hx.multiply(2).divide(h2p1));
FieldVector3D<T> r = new FieldVector3D<>(finalOrbit.getA(), new FieldVector3D<>(x3, U, y3, V));
Assert.assertEquals(finalOrbit.getPVCoordinates().getPosition().getNorm().getReal(), r.getNorm().getReal(), Utils.epsilonTest * r.getNorm().getReal());
}
use of org.orekit.attitudes.LofOffset in project Orekit by CS-SI.
the class FieldEcksteinHechlerPropagatorTest method doPropagatedCartesian.
private <T extends RealFieldElement<T>> void doPropagatedCartesian(Field<T> field) throws OrekitException {
T zero = field.getZero();
FieldAbsoluteDate<T> date = new FieldAbsoluteDate<>(field);
// Definition of initial conditions with position and velocity
// ------------------------------------------------------------
// with e around e = 1.4e-4 and i = 1.7 rad
FieldVector3D<T> position = new FieldVector3D<>(zero.add(3220103.), zero.add(69623.), zero.add(6449822.));
FieldVector3D<T> velocity = new FieldVector3D<>(zero.add(6414.7), zero.add(-2006.), zero.add(-3180.));
FieldAbsoluteDate<T> initDate = date.shiftedBy(584.);
FieldOrbit<T> initialOrbit = new FieldEquinoctialOrbit<>(new FieldPVCoordinates<>(position, velocity), FramesFactory.getEME2000(), initDate, provider.getMu());
// Extrapolator definition
// -----------------------
FieldEcksteinHechlerPropagator<T> extrapolator = new FieldEcksteinHechlerPropagator<>(initialOrbit, new LofOffset(initialOrbit.getFrame(), LOFType.VNC, RotationOrder.XYZ, 0, 0, 0), provider);
// Extrapolation at a final date different from initial date
// ---------------------------------------------------------
// extrapolation duration in seconds
double delta_t = 100000.0;
FieldAbsoluteDate<T> extrapDate = initDate.shiftedBy(delta_t);
FieldSpacecraftState<T> finalOrbit = extrapolator.propagate(extrapDate);
Assert.assertEquals(0.0, finalOrbit.getDate().durationFrom(extrapDate).getReal(), 1.0e-9);
// computation of M final orbit
T LM = finalOrbit.getLE().subtract(finalOrbit.getEquinoctialEx().multiply(finalOrbit.getLE().sin())).add(finalOrbit.getEquinoctialEy().multiply(finalOrbit.getLE().cos()));
Assert.assertEquals(LM.getReal(), finalOrbit.getLM().getReal(), Utils.epsilonAngle * FastMath.abs(finalOrbit.getLM().getReal()));
// test of tan ((LE - Lv)/2) :
Assert.assertEquals(FastMath.tan((finalOrbit.getLE().getReal() - finalOrbit.getLv().getReal()) / 2.), tangLEmLv(finalOrbit.getLv(), finalOrbit.getEquinoctialEx(), finalOrbit.getEquinoctialEy()).getReal(), Utils.epsilonAngle);
// test of evolution of M vs E: LM = LE - ex*sin(LE) + ey*cos(LE)
T deltaM = finalOrbit.getLM().subtract(initialOrbit.getLM());
T deltaE = finalOrbit.getLE().subtract(initialOrbit.getLE());
T delta = finalOrbit.getEquinoctialEx().multiply(finalOrbit.getLE().sin()).subtract(initialOrbit.getEquinoctialEx().multiply(initialOrbit.getLE().sin())).subtract(finalOrbit.getEquinoctialEy().multiply(finalOrbit.getLE().cos())).add(initialOrbit.getEquinoctialEy().multiply(initialOrbit.getLE().cos()));
Assert.assertEquals(deltaM.getReal(), deltaE.getReal() - delta.getReal(), Utils.epsilonAngle * FastMath.abs(deltaE.getReal() - delta.getReal()));
// for final orbit
T ex = finalOrbit.getEquinoctialEx();
T ey = finalOrbit.getEquinoctialEy();
T hx = finalOrbit.getHx();
T hy = finalOrbit.getHy();
T LE = finalOrbit.getLE();
T ex2 = ex.multiply(ex);
T ey2 = ey.multiply(ey);
T hx2 = hx.multiply(hx);
T hy2 = hy.multiply(hy);
T h2p1 = hx2.add(1.).add(hy2);
T beta = ex2.negate().add(1.).subtract(ey2).sqrt().add(1.).reciprocal();
T x3 = ex.negate().add(ey2.multiply(beta).negate().add(1.).multiply(LE.cos())).add(beta.multiply(ex).multiply(ey).multiply(LE.sin()));
T y3 = ey.negate().add(ex2.negate().multiply(beta).add(1).multiply(LE.sin())).add(beta.multiply(ex).multiply(ey).multiply(LE.cos()));
FieldVector3D<T> U = new FieldVector3D<>(hx2.add(1).subtract(hy2).divide(h2p1), hx.multiply(hy).multiply(2).divide(h2p1), hy.multiply(-2).divide(h2p1));
FieldVector3D<T> V = new FieldVector3D<>(hx.multiply(2).multiply(hy).divide(h2p1), hy2.add(1).subtract(hx2).divide(h2p1), hx.multiply(2).divide(h2p1));
FieldVector3D<T> r = new FieldVector3D<>(finalOrbit.getA(), new FieldVector3D<>(x3, U, y3, V));
Assert.assertEquals(finalOrbit.getPVCoordinates().getPosition().getNorm().getReal(), r.getNorm().getReal(), Utils.epsilonTest * r.getNorm().getReal());
}
use of org.orekit.attitudes.LofOffset in project Orekit by CS-SI.
the class KeplerianPropagatorTest method testIssue224.
@Test
public void testIssue224() throws OrekitException, IOException, ClassNotFoundException {
// Inertial frame
Frame inertialFrame = FramesFactory.getEME2000();
// Initial date
TimeScale utc = TimeScalesFactory.getUTC();
AbsoluteDate initialDate = new AbsoluteDate(2004, 01, 01, 23, 30, 00.000, utc);
// Central attraction coefficient
double mu = 3.986004415e+14;
// Initial orbit
// semi major axis in meters
double a = 42100;
// eccentricity
double e = 0.01;
// inclination
double i = FastMath.toRadians(6);
// perigee argument
double omega = FastMath.toRadians(180);
// right ascention of ascending node
double raan = FastMath.toRadians(261);
// mean anomaly
double lM = 0;
Orbit initialOrbit = new KeplerianOrbit(a, e, i, omega, raan, lM, PositionAngle.MEAN, inertialFrame, initialDate, mu);
// Initial state definition
SpacecraftState initialState = new SpacecraftState(initialOrbit);
// Propagator
KeplerianPropagator propagator = new KeplerianPropagator(initialOrbit, new LofOffset(inertialFrame, LOFType.VVLH));
propagator.addAdditionalStateProvider(new SevenProvider());
propagator.setEphemerisMode();
// Impulsive burn 1
final AbsoluteDate burn1Date = initialState.getDate().shiftedBy(200);
ImpulseManeuver<DateDetector> impulsiveBurn1 = new ImpulseManeuver<DateDetector>(new DateDetector(burn1Date), new Vector3D(1000, 0, 0), 320);
propagator.addEventDetector(impulsiveBurn1);
// Impulsive burn 2
final AbsoluteDate burn2Date = initialState.getDate().shiftedBy(300);
ImpulseManeuver<DateDetector> impulsiveBurn2 = new ImpulseManeuver<DateDetector>(new DateDetector(burn2Date), new Vector3D(1000, 0, 0), 320);
propagator.addEventDetector(impulsiveBurn2);
propagator.propagate(initialState.getDate().shiftedBy(400));
ByteArrayOutputStream bos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(bos);
oos.writeObject(propagator.getGeneratedEphemeris());
Assert.assertTrue(bos.size() > 2400);
Assert.assertTrue(bos.size() < 2500);
ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
ObjectInputStream ois = new ObjectInputStream(bis);
BoundedPropagator ephemeris = (BoundedPropagator) ois.readObject();
ephemeris.setMasterMode(10, new OrekitFixedStepHandler() {
public void handleStep(SpacecraftState currentState, boolean isLast) {
if (currentState.getDate().durationFrom(burn1Date) < -0.001) {
Assert.assertEquals(42100.0, currentState.getA(), 1.0e-3);
} else if (currentState.getDate().durationFrom(burn1Date) > 0.001 && currentState.getDate().durationFrom(burn2Date) < -0.001) {
Assert.assertEquals(42979.962, currentState.getA(), 1.0e-3);
} else if (currentState.getDate().durationFrom(burn2Date) > 0.001) {
Assert.assertEquals(43887.339, currentState.getA(), 1.0e-3);
}
}
});
ephemeris.propagate(ephemeris.getMaxDate());
}
Aggregations