Search in sources :

Example 31 with PVCoordinatesProvider

use of org.orekit.utils.PVCoordinatesProvider in project Orekit by CS-SI.

the class CelestialBodyPointingTest method testSunPointing.

@Test
public void testSunPointing() throws OrekitException {
    PVCoordinatesProvider sun = CelestialBodyFactory.getSun();
    final Frame frame = FramesFactory.getGCRF();
    AbsoluteDate date = new AbsoluteDate(new DateComponents(1970, 01, 01), new TimeComponents(3, 25, 45.6789), TimeScalesFactory.getTAI());
    AttitudeProvider sunPointing = new CelestialBodyPointed(frame, sun, Vector3D.PLUS_K, Vector3D.PLUS_I, Vector3D.PLUS_K);
    PVCoordinates pv = new PVCoordinates(new Vector3D(28812595.32120171334, 5948437.45881852374, 0.0), new Vector3D(0, 0, 3680.853673522056));
    Orbit orbit = new KeplerianOrbit(pv, frame, date, 3.986004415e14);
    Attitude attitude = sunPointing.getAttitude(orbit, date, frame);
    checkField(Decimal64Field.getInstance(), sunPointing, orbit, date, frame);
    Vector3D xDirection = attitude.getRotation().applyInverseTo(Vector3D.PLUS_I);
    Vector3D zDirection = attitude.getRotation().applyInverseTo(Vector3D.PLUS_K);
    Assert.assertEquals(0, Vector3D.dotProduct(zDirection, Vector3D.crossProduct(xDirection, Vector3D.PLUS_K)), 1.0e-15);
    // the following statement checks we take parallax into account
    // Sun-Earth-Sat are in quadrature, with distance (Earth, Sat) == distance(Sun, Earth) / 5000
    Assert.assertEquals(FastMath.atan(1.0 / 5000.0), Vector3D.angle(xDirection, sun.getPVCoordinates(date, frame).getPosition()), 1.0e-15);
    double h = 0.1;
    Attitude aMinus = sunPointing.getAttitude(orbit.shiftedBy(-h), date.shiftedBy(-h), frame);
    Attitude a0 = sunPointing.getAttitude(orbit, date, frame);
    Attitude aPlus = sunPointing.getAttitude(orbit.shiftedBy(h), date.shiftedBy(h), frame);
    // check spin is consistent with attitude evolution
    double errorAngleMinus = Rotation.distance(aMinus.shiftedBy(h).getRotation(), a0.getRotation());
    double evolutionAngleMinus = Rotation.distance(aMinus.getRotation(), a0.getRotation());
    Assert.assertEquals(0.0, errorAngleMinus, 1.0e-6 * evolutionAngleMinus);
    double errorAnglePlus = Rotation.distance(a0.getRotation(), aPlus.shiftedBy(-h).getRotation());
    double evolutionAnglePlus = Rotation.distance(a0.getRotation(), aPlus.getRotation());
    Assert.assertEquals(0.0, errorAnglePlus, 1.0e-6 * evolutionAnglePlus);
}
Also used : Frame(org.orekit.frames.Frame) FieldOrbit(org.orekit.orbits.FieldOrbit) Orbit(org.orekit.orbits.Orbit) KeplerianOrbit(org.orekit.orbits.KeplerianOrbit) PVCoordinates(org.orekit.utils.PVCoordinates) DateComponents(org.orekit.time.DateComponents) TimeComponents(org.orekit.time.TimeComponents) FieldAbsoluteDate(org.orekit.time.FieldAbsoluteDate) AbsoluteDate(org.orekit.time.AbsoluteDate) Vector3D(org.hipparchus.geometry.euclidean.threed.Vector3D) PVCoordinatesProvider(org.orekit.utils.PVCoordinatesProvider) KeplerianOrbit(org.orekit.orbits.KeplerianOrbit) Test(org.junit.Test)

Example 32 with PVCoordinatesProvider

use of org.orekit.utils.PVCoordinatesProvider in project Orekit by CS-SI.

the class FieldEcksteinHechlerPropagatorTest method doWrongAttitude.

private <T extends RealFieldElement<T>> void doWrongAttitude(Field<T> field) throws OrekitException {
    T zero = field.getZero();
    FieldAbsoluteDate<T> date = new FieldAbsoluteDate<>(field);
    FieldKeplerianOrbit<T> orbit = new FieldKeplerianOrbit<>(zero.add(1.0e10), zero.add(1.0e-4), zero.add(1.0e-2), zero, zero, zero, PositionAngle.TRUE, FramesFactory.getEME2000(), date, 3.986004415e14);
    final DummyLocalizable gasp = new DummyLocalizable("gasp");
    AttitudeProvider wrongLaw = new AttitudeProvider() {

        private static final long serialVersionUID = 1L;

        @Override
        public Attitude getAttitude(PVCoordinatesProvider pvProv, AbsoluteDate date, Frame frame) throws OrekitException {
            throw new OrekitException(gasp, new RuntimeException());
        }

        @Override
        public <Q extends RealFieldElement<Q>> FieldAttitude<Q> getAttitude(FieldPVCoordinatesProvider<Q> pvProv, FieldAbsoluteDate<Q> date, Frame frame) throws OrekitException {
            throw new OrekitException(gasp, new RuntimeException());
        }
    };
    try {
        FieldEcksteinHechlerPropagator<T> propagator = new FieldEcksteinHechlerPropagator<>(orbit, wrongLaw, provider);
        propagator.propagate(date.shiftedBy(10.0));
        Assert.fail("an exception should have been thrown");
    } catch (OrekitException oe) {
        Assert.assertSame(gasp, oe.getSpecifier());
    }
}
Also used : DummyLocalizable(org.hipparchus.exception.DummyLocalizable) Frame(org.orekit.frames.Frame) TopocentricFrame(org.orekit.frames.TopocentricFrame) RealFieldElement(org.hipparchus.RealFieldElement) FieldAbsoluteDate(org.orekit.time.FieldAbsoluteDate) AbsoluteDate(org.orekit.time.AbsoluteDate) FieldKeplerianOrbit(org.orekit.orbits.FieldKeplerianOrbit) FieldPVCoordinatesProvider(org.orekit.utils.FieldPVCoordinatesProvider) PVCoordinatesProvider(org.orekit.utils.PVCoordinatesProvider) FieldPVCoordinatesProvider(org.orekit.utils.FieldPVCoordinatesProvider) OrekitException(org.orekit.errors.OrekitException) FieldAbsoluteDate(org.orekit.time.FieldAbsoluteDate) AttitudeProvider(org.orekit.attitudes.AttitudeProvider)

Example 33 with PVCoordinatesProvider

use of org.orekit.utils.PVCoordinatesProvider in project Orekit by CS-SI.

the class FieldKeplerianPropagatorTest method doTestWrongAttitude.

private <T extends RealFieldElement<T>> void doTestWrongAttitude(Field<T> field) throws OrekitException {
    T zero = field.getZero();
    FieldKeplerianOrbit<T> orbit = new FieldKeplerianOrbit<>(zero.add(1.0e10), zero.add(1.0e-4), zero.add(1.0e-2), zero, zero, zero, PositionAngle.TRUE, FramesFactory.getEME2000(), new FieldAbsoluteDate<>(field), 3.986004415e14);
    AttitudeProvider wrongLaw = new AttitudeProvider() {

        private static final long serialVersionUID = 1L;

        @Override
        public Attitude getAttitude(PVCoordinatesProvider pvProv, AbsoluteDate date, Frame frame) throws OrekitException {
            throw new OrekitException(new DummyLocalizable("gasp"), new RuntimeException());
        }

        @Override
        public <Q extends RealFieldElement<Q>> FieldAttitude<Q> getAttitude(FieldPVCoordinatesProvider<Q> pvProv, FieldAbsoluteDate<Q> date, Frame frame) throws OrekitException {
            throw new OrekitException(new DummyLocalizable("gasp"), new RuntimeException());
        }
    };
    FieldKeplerianPropagator<T> propagator = new FieldKeplerianPropagator<>(orbit, wrongLaw);
    propagator.propagate(new FieldAbsoluteDate<>(field).shiftedBy(10.0));
}
Also used : DummyLocalizable(org.hipparchus.exception.DummyLocalizable) Frame(org.orekit.frames.Frame) TopocentricFrame(org.orekit.frames.TopocentricFrame) RealFieldElement(org.hipparchus.RealFieldElement) FieldAbsoluteDate(org.orekit.time.FieldAbsoluteDate) AbsoluteDate(org.orekit.time.AbsoluteDate) FieldKeplerianOrbit(org.orekit.orbits.FieldKeplerianOrbit) FieldPVCoordinatesProvider(org.orekit.utils.FieldPVCoordinatesProvider) PVCoordinatesProvider(org.orekit.utils.PVCoordinatesProvider) FieldPVCoordinatesProvider(org.orekit.utils.FieldPVCoordinatesProvider) OrekitException(org.orekit.errors.OrekitException) FieldAbsoluteDate(org.orekit.time.FieldAbsoluteDate) AttitudeProvider(org.orekit.attitudes.AttitudeProvider)

Example 34 with PVCoordinatesProvider

use of org.orekit.utils.PVCoordinatesProvider in project Orekit by CS-SI.

the class EarthObservation method main.

/**
 * Program entry point.
 * @param args program arguments (unused here)
 */
public static void main(String[] args) {
    try {
        // configure Orekit
        File home = new File(System.getProperty("user.home"));
        File orekitData = new File(home, "orekit-data");
        if (!orekitData.exists()) {
            System.err.format(Locale.US, "Failed to find %s folder%n", orekitData.getAbsolutePath());
            System.err.format(Locale.US, "You need to download %s from the %s page and unzip it in %s for this tutorial to work%n", "orekit-data.zip", "https://www.orekit.org/forge/projects/orekit/files", home.getAbsolutePath());
            System.exit(1);
        }
        DataProvidersManager manager = DataProvidersManager.getInstance();
        manager.addProvider(new DirectoryCrawler(orekitData));
        final SortedSet<String> output = new TreeSet<String>();
        // Initial state definition : date, orbit
        final AbsoluteDate initialDate = new AbsoluteDate(2004, 01, 01, 23, 30, 00.000, TimeScalesFactory.getUTC());
        final Vector3D position = new Vector3D(-6142438.668, 3492467.560, -25767.25680);
        final Vector3D velocity = new Vector3D(505.8479685, 942.7809215, 7435.922231);
        final Orbit initialOrbit = new KeplerianOrbit(new PVCoordinates(position, velocity), FramesFactory.getEME2000(), initialDate, Constants.EIGEN5C_EARTH_MU);
        // Attitudes sequence definition
        final AttitudeProvider dayObservationLaw = new LofOffset(initialOrbit.getFrame(), LOFType.VVLH, RotationOrder.XYZ, FastMath.toRadians(20), FastMath.toRadians(40), 0);
        final AttitudeProvider nightRestingLaw = new LofOffset(initialOrbit.getFrame(), LOFType.VVLH);
        final PVCoordinatesProvider sun = CelestialBodyFactory.getSun();
        final PVCoordinatesProvider earth = CelestialBodyFactory.getEarth();
        final EventDetector dayNightEvent = new EclipseDetector(sun, 696000000., earth, Constants.WGS84_EARTH_EQUATORIAL_RADIUS).withHandler(new ContinueOnEvent<EclipseDetector>());
        final EventDetector nightDayEvent = new EclipseDetector(sun, 696000000., earth, Constants.WGS84_EARTH_EQUATORIAL_RADIUS).withHandler(new ContinueOnEvent<EclipseDetector>());
        final AttitudesSequence attitudesSequence = new AttitudesSequence();
        final AttitudesSequence.SwitchHandler switchHandler = new AttitudesSequence.SwitchHandler() {

            public void switchOccurred(AttitudeProvider preceding, AttitudeProvider following, SpacecraftState s) {
                if (preceding == dayObservationLaw) {
                    output.add(s.getDate() + ": switching to night law");
                } else {
                    output.add(s.getDate() + ": switching to day law");
                }
            }
        };
        attitudesSequence.addSwitchingCondition(dayObservationLaw, nightRestingLaw, dayNightEvent, false, true, 10.0, AngularDerivativesFilter.USE_R, switchHandler);
        attitudesSequence.addSwitchingCondition(nightRestingLaw, dayObservationLaw, nightDayEvent, true, false, 10.0, AngularDerivativesFilter.USE_R, switchHandler);
        if (dayNightEvent.g(new SpacecraftState(initialOrbit)) >= 0) {
            // initial position is in daytime
            attitudesSequence.resetActiveProvider(dayObservationLaw);
        } else {
            // initial position is in nighttime
            attitudesSequence.resetActiveProvider(nightRestingLaw);
        }
        // Propagator : consider the analytical Eckstein-Hechler model
        final Propagator propagator = new EcksteinHechlerPropagator(initialOrbit, attitudesSequence, Constants.EIGEN5C_EARTH_EQUATORIAL_RADIUS, Constants.EIGEN5C_EARTH_MU, Constants.EIGEN5C_EARTH_C20, Constants.EIGEN5C_EARTH_C30, Constants.EIGEN5C_EARTH_C40, Constants.EIGEN5C_EARTH_C50, Constants.EIGEN5C_EARTH_C60);
        // Register the switching events to the propagator
        attitudesSequence.registerSwitchEvents(propagator);
        propagator.setMasterMode(180.0, new OrekitFixedStepHandler() {

            public void init(final SpacecraftState s0, final AbsoluteDate t) {
            }

            public void handleStep(SpacecraftState currentState, boolean isLast) throws OrekitException {
                DecimalFormatSymbols angleDegree = new DecimalFormatSymbols(Locale.US);
                angleDegree.setDecimalSeparator('\u00b0');
                DecimalFormat ad = new DecimalFormat(" 00.000;-00.000", angleDegree);
                // the Earth position in spacecraft frame should be along spacecraft Z axis
                // during nigthtime and away from it during daytime due to roll and pitch offsets
                final Vector3D earth = currentState.toTransform().transformPosition(Vector3D.ZERO);
                final double pointingOffset = Vector3D.angle(earth, Vector3D.PLUS_K);
                // the g function is the eclipse indicator, its an angle between Sun and Earth limb,
                // positive when Sun is outside of Earth limb, negative when Sun is hidden by Earth limb
                final double eclipseAngle = dayNightEvent.g(currentState);
                output.add(currentState.getDate() + " " + ad.format(FastMath.toDegrees(eclipseAngle)) + " " + ad.format(FastMath.toDegrees(pointingOffset)));
            }
        });
        // Propagate from the initial date for the fixed duration
        SpacecraftState finalState = propagator.propagate(initialDate.shiftedBy(12600.));
        // to make sure out of orders calls between step handler and event handlers don't mess things up
        for (final String line : output) {
            System.out.println(line);
        }
        System.out.println("Propagation ended at " + finalState.getDate());
    } catch (OrekitException oe) {
        System.err.println(oe.getMessage());
    }
}
Also used : DecimalFormat(java.text.DecimalFormat) PVCoordinates(org.orekit.utils.PVCoordinates) AbsoluteDate(org.orekit.time.AbsoluteDate) AttitudesSequence(org.orekit.attitudes.AttitudesSequence) SpacecraftState(org.orekit.propagation.SpacecraftState) EcksteinHechlerPropagator(org.orekit.propagation.analytical.EcksteinHechlerPropagator) Vector3D(org.hipparchus.geometry.euclidean.threed.Vector3D) TreeSet(java.util.TreeSet) EcksteinHechlerPropagator(org.orekit.propagation.analytical.EcksteinHechlerPropagator) Propagator(org.orekit.propagation.Propagator) DirectoryCrawler(org.orekit.data.DirectoryCrawler) PVCoordinatesProvider(org.orekit.utils.PVCoordinatesProvider) KeplerianOrbit(org.orekit.orbits.KeplerianOrbit) OrekitException(org.orekit.errors.OrekitException) LofOffset(org.orekit.attitudes.LofOffset) OrekitFixedStepHandler(org.orekit.propagation.sampling.OrekitFixedStepHandler) EclipseDetector(org.orekit.propagation.events.EclipseDetector) Orbit(org.orekit.orbits.Orbit) KeplerianOrbit(org.orekit.orbits.KeplerianOrbit) DecimalFormatSymbols(java.text.DecimalFormatSymbols) EventDetector(org.orekit.propagation.events.EventDetector) DataProvidersManager(org.orekit.data.DataProvidersManager) File(java.io.File) AttitudeProvider(org.orekit.attitudes.AttitudeProvider)

Example 35 with PVCoordinatesProvider

use of org.orekit.utils.PVCoordinatesProvider in project Orekit by CS-SI.

the class Frames3 method main.

public static void main(String[] args) {
    try {
        // configure Orekit
        File home = new File(System.getProperty("user.home"));
        File orekitData = new File(home, "orekit-data");
        if (!orekitData.exists()) {
            System.err.format(Locale.US, "Failed to find %s folder%n", orekitData.getAbsolutePath());
            System.err.format(Locale.US, "You need to download %s from the %s page and unzip it in %s for this tutorial to work%n", "orekit-data.zip", "https://www.orekit.org/forge/projects/orekit/files", home.getAbsolutePath());
            System.exit(1);
        }
        DataProvidersManager manager = DataProvidersManager.getInstance();
        manager.addProvider(new DirectoryCrawler(orekitData));
        // Initial state definition :
        // ==========================
        // Date
        // ****
        AbsoluteDate initialDate = new AbsoluteDate(2003, 4, 7, 10, 55, 21.575, TimeScalesFactory.getUTC());
        // Orbit
        // *****
        // The Sun is in the orbital plane for raan ~ 202
        // gravitation coefficient
        double mu = 3.986004415e+14;
        // inertial frame
        Frame eme2000 = FramesFactory.getEME2000();
        Orbit orbit = new CircularOrbit(7178000.0, 0.5e-4, -0.5e-4, FastMath.toRadians(50.), FastMath.toRadians(220.), FastMath.toRadians(5.300), PositionAngle.MEAN, eme2000, initialDate, mu);
        // Attitude laws
        // *************
        // Earth
        Frame earthFrame = FramesFactory.getITRF(IERSConventions.IERS_2010, true);
        BodyShape earth = new OneAxisEllipsoid(Constants.WGS84_EARTH_EQUATORIAL_RADIUS, Constants.WGS84_EARTH_FLATTENING, earthFrame);
        // Target pointing attitude provider over satellite nadir at date, without yaw compensation
        NadirPointing nadirLaw = new NadirPointing(eme2000, earth);
        // Target pointing attitude provider with yaw compensation
        final PVCoordinatesProvider sun = CelestialBodyFactory.getSun();
        YawSteering yawSteeringLaw = new YawSteering(eme2000, nadirLaw, sun, Vector3D.MINUS_I);
        // Propagator : Eckstein-Hechler analytic propagator
        Propagator propagator = new EcksteinHechlerPropagator(orbit, yawSteeringLaw, Constants.EIGEN5C_EARTH_EQUATORIAL_RADIUS, Constants.EIGEN5C_EARTH_MU, Constants.EIGEN5C_EARTH_C20, Constants.EIGEN5C_EARTH_C30, Constants.EIGEN5C_EARTH_C40, Constants.EIGEN5C_EARTH_C50, Constants.EIGEN5C_EARTH_C60);
        // Let's write the results in a file in order to draw some plots.
        propagator.setMasterMode(10, new OrekitFixedStepHandler() {

            PrintStream out = null;

            public void init(SpacecraftState s0, AbsoluteDate t, double step) throws OrekitException {
                try {
                    File file = new File(System.getProperty("user.home"), "XYZ.dat");
                    System.out.println("Results written to file: " + file.getAbsolutePath());
                    out = new PrintStream(file, "UTF-8");
                    out.println("#time X Y Z Wx Wy Wz");
                } catch (IOException ioe) {
                    throw new OrekitException(ioe, LocalizedCoreFormats.SIMPLE_MESSAGE, ioe.getLocalizedMessage());
                }
            }

            public void handleStep(SpacecraftState currentState, boolean isLast) throws OrekitException {
                // get the transform from orbit/attitude reference frame to spacecraft frame
                Transform inertToSpacecraft = currentState.toTransform();
                // get the position of the Sun in orbit/attitude reference frame
                Vector3D sunInert = sun.getPVCoordinates(currentState.getDate(), currentState.getFrame()).getPosition();
                // convert Sun position to spacecraft frame
                Vector3D sunSat = inertToSpacecraft.transformPosition(sunInert);
                // and the spacecraft rotational rate also
                Vector3D spin = inertToSpacecraft.getRotationRate();
                // Lets calculate the reduced coordinates
                double sunX = sunSat.getX() / sunSat.getNorm();
                double sunY = sunSat.getY() / sunSat.getNorm();
                double sunZ = sunSat.getZ() / sunSat.getNorm();
                out.format(Locale.US, "%s %12.3f %12.3f %12.3f %12.7f %12.7f %12.7f%n", currentState.getDate(), sunX, sunY, sunZ, spin.getX(), spin.getY(), spin.getZ());
                if (isLast) {
                    out.close();
                }
            }
        });
        System.out.println("Running...");
        propagator.propagate(initialDate.shiftedBy(6000));
    } catch (OrekitException oe) {
        System.err.println(oe.getMessage());
    }
}
Also used : NadirPointing(org.orekit.attitudes.NadirPointing) PrintStream(java.io.PrintStream) Frame(org.orekit.frames.Frame) OneAxisEllipsoid(org.orekit.bodies.OneAxisEllipsoid) Orbit(org.orekit.orbits.Orbit) CircularOrbit(org.orekit.orbits.CircularOrbit) IOException(java.io.IOException) BodyShape(org.orekit.bodies.BodyShape) AbsoluteDate(org.orekit.time.AbsoluteDate) EcksteinHechlerPropagator(org.orekit.propagation.analytical.EcksteinHechlerPropagator) SpacecraftState(org.orekit.propagation.SpacecraftState) CircularOrbit(org.orekit.orbits.CircularOrbit) Vector3D(org.hipparchus.geometry.euclidean.threed.Vector3D) EcksteinHechlerPropagator(org.orekit.propagation.analytical.EcksteinHechlerPropagator) Propagator(org.orekit.propagation.Propagator) DirectoryCrawler(org.orekit.data.DirectoryCrawler) YawSteering(org.orekit.attitudes.YawSteering) DataProvidersManager(org.orekit.data.DataProvidersManager) PVCoordinatesProvider(org.orekit.utils.PVCoordinatesProvider) OrekitException(org.orekit.errors.OrekitException) Transform(org.orekit.frames.Transform) File(java.io.File) OrekitFixedStepHandler(org.orekit.propagation.sampling.OrekitFixedStepHandler)

Aggregations

PVCoordinatesProvider (org.orekit.utils.PVCoordinatesProvider)35 Test (org.junit.Test)28 Frame (org.orekit.frames.Frame)22 AbsoluteDate (org.orekit.time.AbsoluteDate)20 FieldAbsoluteDate (org.orekit.time.FieldAbsoluteDate)19 Vector3D (org.hipparchus.geometry.euclidean.threed.Vector3D)16 OneAxisEllipsoid (org.orekit.bodies.OneAxisEllipsoid)14 OrekitException (org.orekit.errors.OrekitException)13 KeplerianOrbit (org.orekit.orbits.KeplerianOrbit)12 FieldKeplerianOrbit (org.orekit.orbits.FieldKeplerianOrbit)11 SpacecraftState (org.orekit.propagation.SpacecraftState)11 FieldVector3D (org.hipparchus.geometry.euclidean.threed.FieldVector3D)8 Orbit (org.orekit.orbits.Orbit)8 DateComponents (org.orekit.time.DateComponents)8 TimeComponents (org.orekit.time.TimeComponents)8 AttitudeProvider (org.orekit.attitudes.AttitudeProvider)7 DummyLocalizable (org.hipparchus.exception.DummyLocalizable)6 GeodeticPoint (org.orekit.bodies.GeodeticPoint)6 AbstractLegacyForceModelTest (org.orekit.forces.AbstractLegacyForceModelTest)6 TopocentricFrame (org.orekit.frames.TopocentricFrame)6