Search in sources :

Example 1 with EventDetector

use of org.orekit.propagation.events.EventDetector in project Orekit by CS-SI.

the class ConstantThrustManeuverTest method testNegativeDuration.

@Test
public void testNegativeDuration() throws OrekitException {
    AbsoluteDate date = new AbsoluteDate(new DateComponents(2004, 01, 01), new TimeComponents(23, 30, 00.000), TimeScalesFactory.getUTC());
    ConstantThrustManeuver maneuver = new ConstantThrustManeuver(date, -10.0, 400.0, 300.0, Vector3D.PLUS_K, "1A-");
    ParameterDriver[] drivers = maneuver.getParametersDrivers();
    Assert.assertEquals(2, drivers.length);
    Assert.assertEquals("1A-thrust", drivers[0].getName());
    Assert.assertEquals("1A-flow rate", drivers[1].getName());
    EventDetector[] switches = maneuver.getEventsDetectors().toArray(EventDetector[]::new);
    Orbit o1 = dummyOrbit(date.shiftedBy(-11.0));
    Assert.assertTrue(switches[0].g(new SpacecraftState(o1)) < 0);
    Orbit o2 = dummyOrbit(date.shiftedBy(-9.0));
    Assert.assertTrue(switches[0].g(new SpacecraftState(o2)) > 0);
    Orbit o3 = dummyOrbit(date.shiftedBy(-1.0));
    Assert.assertTrue(switches[1].g(new SpacecraftState(o3)) < 0);
    Orbit o4 = dummyOrbit(date.shiftedBy(1.0));
    Assert.assertTrue(switches[1].g(new SpacecraftState(o4)) > 0);
}
Also used : SpacecraftState(org.orekit.propagation.SpacecraftState) FieldSpacecraftState(org.orekit.propagation.FieldSpacecraftState) EventDetector(org.orekit.propagation.events.EventDetector) CartesianOrbit(org.orekit.orbits.CartesianOrbit) FieldKeplerianOrbit(org.orekit.orbits.FieldKeplerianOrbit) KeplerianOrbit(org.orekit.orbits.KeplerianOrbit) Orbit(org.orekit.orbits.Orbit) CircularOrbit(org.orekit.orbits.CircularOrbit) DateComponents(org.orekit.time.DateComponents) TimeComponents(org.orekit.time.TimeComponents) ParameterDriver(org.orekit.utils.ParameterDriver) FieldAbsoluteDate(org.orekit.time.FieldAbsoluteDate) AbsoluteDate(org.orekit.time.AbsoluteDate) AbstractLegacyForceModelTest(org.orekit.forces.AbstractLegacyForceModelTest) Test(org.junit.Test)

Example 2 with EventDetector

use of org.orekit.propagation.events.EventDetector in project Orekit by CS-SI.

the class ConstantThrustManeuverTest method testPositiveDuration.

@Test
public void testPositiveDuration() throws OrekitException {
    AbsoluteDate date = new AbsoluteDate(new DateComponents(2004, 01, 01), new TimeComponents(23, 30, 00.000), TimeScalesFactory.getUTC());
    ConstantThrustManeuver maneuver = new ConstantThrustManeuver(date, 10.0, 400.0, 300.0, Vector3D.PLUS_K);
    Assert.assertFalse(maneuver.dependsOnPositionOnly());
    ParameterDriver[] drivers = maneuver.getParametersDrivers();
    Assert.assertEquals(2, drivers.length);
    Assert.assertEquals("thrust", drivers[0].getName());
    Assert.assertEquals("flow rate", drivers[1].getName());
    EventDetector[] switches = maneuver.getEventsDetectors().toArray(EventDetector[]::new);
    Orbit o1 = dummyOrbit(date.shiftedBy(-1.0));
    Assert.assertTrue(switches[0].g(new SpacecraftState(o1)) < 0);
    Orbit o2 = dummyOrbit(date.shiftedBy(1.0));
    Assert.assertTrue(switches[0].g(new SpacecraftState(o2)) > 0);
    Orbit o3 = dummyOrbit(date.shiftedBy(9.0));
    Assert.assertTrue(switches[1].g(new SpacecraftState(o3)) < 0);
    Orbit o4 = dummyOrbit(date.shiftedBy(11.0));
    Assert.assertTrue(switches[1].g(new SpacecraftState(o4)) > 0);
}
Also used : SpacecraftState(org.orekit.propagation.SpacecraftState) FieldSpacecraftState(org.orekit.propagation.FieldSpacecraftState) EventDetector(org.orekit.propagation.events.EventDetector) CartesianOrbit(org.orekit.orbits.CartesianOrbit) FieldKeplerianOrbit(org.orekit.orbits.FieldKeplerianOrbit) KeplerianOrbit(org.orekit.orbits.KeplerianOrbit) Orbit(org.orekit.orbits.Orbit) CircularOrbit(org.orekit.orbits.CircularOrbit) DateComponents(org.orekit.time.DateComponents) TimeComponents(org.orekit.time.TimeComponents) ParameterDriver(org.orekit.utils.ParameterDriver) FieldAbsoluteDate(org.orekit.time.FieldAbsoluteDate) AbsoluteDate(org.orekit.time.AbsoluteDate) AbstractLegacyForceModelTest(org.orekit.forces.AbstractLegacyForceModelTest) Test(org.junit.Test)

Example 3 with EventDetector

use of org.orekit.propagation.events.EventDetector in project Orekit by CS-SI.

the class AttitudesSequenceTest method doTestDayNightSwitchField.

private <T extends RealFieldElement<T>> void doTestDayNightSwitchField(final Field<T> field) throws OrekitException {
    // Initial state definition : date, orbit
    final FieldAbsoluteDate<T> initialDate = new FieldAbsoluteDate<>(field, 2004, 01, 01, 23, 30, 00.000, TimeScalesFactory.getUTC());
    final FieldVector3D<T> position = new FieldVector3D<>(field, new Vector3D(-6142438.668, 3492467.560, -25767.25680));
    final FieldVector3D<T> velocity = new FieldVector3D<>(field, new Vector3D(505.8479685, 942.7809215, 7435.922231));
    final FieldOrbit<T> initialOrbit = new FieldKeplerianOrbit<>(new FieldPVCoordinates<>(position, velocity), FramesFactory.getEME2000(), initialDate, Constants.EIGEN5C_EARTH_MU);
    // Attitudes sequence definition
    EventsLogger logger = new EventsLogger();
    final AttitudesSequence attitudesSequence = new AttitudesSequence();
    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 EclipseDetector ed = new EclipseDetector(sun, 696000000., earth, Constants.WGS84_EARTH_EQUATORIAL_RADIUS).withHandler(new ContinueOnEvent<EclipseDetector>() {

        private static final long serialVersionUID = 1L;

        int count = 0;

        public EventHandler.Action eventOccurred(final SpacecraftState s, final EclipseDetector d, final boolean increasing) {
            setInEclipse(s.getDate(), !increasing);
            if (count++ == 7) {
                return Action.STOP;
            } else {
                switch(count % 3) {
                    case 0:
                        return Action.CONTINUE;
                    case 1:
                        return Action.RESET_DERIVATIVES;
                    default:
                        return Action.RESET_STATE;
                }
            }
        }
    });
    final EventDetector monitored = logger.monitorDetector(ed);
    final Handler dayToNightHandler = new Handler(dayObservationLaw, nightRestingLaw);
    final Handler nightToDayHandler = new Handler(nightRestingLaw, dayObservationLaw);
    attitudesSequence.addSwitchingCondition(dayObservationLaw, nightRestingLaw, monitored, false, true, 300.0, AngularDerivativesFilter.USE_RRA, dayToNightHandler);
    attitudesSequence.addSwitchingCondition(nightRestingLaw, dayObservationLaw, monitored, true, false, 300.0, AngularDerivativesFilter.USE_RRA, nightToDayHandler);
    FieldSpacecraftState<T> initialState = new FieldSpacecraftState<>(initialOrbit);
    initialState = initialState.addAdditionalState("fortyTwo", field.getZero().add(42.0));
    if (ed.g(initialState.toSpacecraftState()) >= 0) {
        // initial position is in daytime
        setInEclipse(initialDate.toAbsoluteDate(), false);
        attitudesSequence.resetActiveProvider(dayObservationLaw);
    } else {
        // initial position is in nighttime
        setInEclipse(initialDate.toAbsoluteDate(), true);
        attitudesSequence.resetActiveProvider(nightRestingLaw);
    }
    // Propagator : consider the analytical Eckstein-Hechler model
    final FieldPropagator<T> propagator = new FieldEcksteinHechlerPropagator<T>(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(field, propagator);
    propagator.setMasterMode(field.getZero().add(60.0), new FieldOrekitFixedStepHandler<T>() {

        public void handleStep(FieldSpacecraftState<T> currentState, boolean isLast) throws OrekitException {
            // the Earth position in spacecraft frame should be along spacecraft Z axis
            // during night time and away from it during day time due to roll and pitch offsets
            final FieldVector3D<T> earth = currentState.toTransform().transformPosition(Vector3D.ZERO);
            final T pointingOffset = FieldVector3D.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 = ed.g(currentState.toSpacecraftState());
            if (currentState.getDate().durationFrom(lastChange).getReal() > 300) {
                if (inEclipse) {
                    Assert.assertTrue(eclipseAngle <= 0);
                    Assert.assertEquals(0.0, pointingOffset.getReal(), 1.0e-6);
                } else {
                    Assert.assertTrue(eclipseAngle >= 0);
                    Assert.assertEquals(0.767215, pointingOffset.getReal(), 1.0e-6);
                }
            } else {
                // we are in transition
                Assert.assertTrue(pointingOffset.getReal() + " " + (0.767215 - pointingOffset.getReal()), pointingOffset.getReal() <= 0.7672155);
            }
        }
    });
    // Propagate from the initial date for the fixed duration
    propagator.propagate(initialDate.shiftedBy(12600.));
    // as we have 2 switch events (even if they share the same underlying event detector),
    // and these events are triggered at both eclipse entry and exit, we get 8
    // raw events on 2 orbits
    Assert.assertEquals(8, logger.getLoggedEvents().size());
    // we have 4 attitudes switch on 2 orbits, 2 of each type
    Assert.assertEquals(2, dayToNightHandler.dates.size());
    Assert.assertEquals(2, nightToDayHandler.dates.size());
}
Also used : FieldVector3D(org.hipparchus.geometry.euclidean.threed.FieldVector3D) FieldKeplerianOrbit(org.orekit.orbits.FieldKeplerianOrbit) SpacecraftState(org.orekit.propagation.SpacecraftState) FieldSpacecraftState(org.orekit.propagation.FieldSpacecraftState) FieldVector3D(org.hipparchus.geometry.euclidean.threed.FieldVector3D) Vector3D(org.hipparchus.geometry.euclidean.threed.Vector3D) FieldEcksteinHechlerPropagator(org.orekit.propagation.analytical.FieldEcksteinHechlerPropagator) PVCoordinatesProvider(org.orekit.utils.PVCoordinatesProvider) OrekitException(org.orekit.errors.OrekitException) EclipseDetector(org.orekit.propagation.events.EclipseDetector) FieldSpacecraftState(org.orekit.propagation.FieldSpacecraftState) FieldOrekitFixedStepHandler(org.orekit.propagation.sampling.FieldOrekitFixedStepHandler) OrekitFixedStepHandler(org.orekit.propagation.sampling.OrekitFixedStepHandler) EventHandler(org.orekit.propagation.events.handlers.EventHandler) GeodeticPoint(org.orekit.bodies.GeodeticPoint) EventDetector(org.orekit.propagation.events.EventDetector) EventsLogger(org.orekit.propagation.events.EventsLogger) FieldAbsoluteDate(org.orekit.time.FieldAbsoluteDate)

Example 4 with EventDetector

use of org.orekit.propagation.events.EventDetector in project Orekit by CS-SI.

the class AttitudesSequenceTest method testDayNightSwitch.

@Test
public void testDayNightSwitch() throws OrekitException {
    // 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);
    final EventsLogger // Attitudes sequence definition
    logger = new EventsLogger();
    final AttitudesSequence attitudesSequence = new AttitudesSequence();
    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 EclipseDetector ed = new EclipseDetector(sun, 696000000., earth, Constants.WGS84_EARTH_EQUATORIAL_RADIUS).withHandler(new ContinueOnEvent<EclipseDetector>() {

        private static final long serialVersionUID = 1L;

        public EventHandler.Action eventOccurred(final SpacecraftState s, final EclipseDetector d, final boolean increasing) {
            setInEclipse(s.getDate(), !increasing);
            return EventHandler.Action.RESET_STATE;
        }
    });
    final EventDetector monitored = logger.monitorDetector(ed);
    final Handler dayToNightHandler = new Handler(dayObservationLaw, nightRestingLaw);
    final Handler nightToDayHandler = new Handler(nightRestingLaw, dayObservationLaw);
    attitudesSequence.addSwitchingCondition(dayObservationLaw, nightRestingLaw, monitored, false, true, 300.0, AngularDerivativesFilter.USE_RRA, dayToNightHandler);
    attitudesSequence.addSwitchingCondition(nightRestingLaw, dayObservationLaw, monitored, true, false, 300.0, AngularDerivativesFilter.USE_RRA, nightToDayHandler);
    SpacecraftState initialState = new SpacecraftState(initialOrbit);
    initialState = initialState.addAdditionalState("fortyTwo", 42.0);
    if (ed.g(initialState) >= 0) {
        // initial position is in daytime
        setInEclipse(initialDate, false);
        attitudesSequence.resetActiveProvider(dayObservationLaw);
    } else {
        // initial position is in nighttime
        setInEclipse(initialDate, true);
        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(60.0, new OrekitFixedStepHandler() {

        public void handleStep(SpacecraftState currentState, boolean isLast) throws OrekitException {
            // the Earth position in spacecraft frame should be along spacecraft Z axis
            // during night time and away from it during day time 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 = ed.g(currentState);
            if (currentState.getDate().durationFrom(lastChange) > 300) {
                if (inEclipse) {
                    Assert.assertTrue(eclipseAngle <= 0);
                    Assert.assertEquals(0.0, pointingOffset, 1.0e-6);
                } else {
                    Assert.assertTrue(eclipseAngle >= 0);
                    Assert.assertEquals(0.767215, pointingOffset, 1.0e-6);
                }
            } else {
                // we are in transition
                Assert.assertTrue(pointingOffset + " " + (0.767215 - pointingOffset), pointingOffset <= 0.7672155);
            }
        }
    });
    // Propagate from the initial date for the fixed duration
    propagator.propagate(initialDate.shiftedBy(12600.));
    // as we have 2 switch events (even if they share the same underlying event detector),
    // and these events are triggered at both eclipse entry and exit, we get 8
    // raw events on 2 orbits
    Assert.assertEquals(8, logger.getLoggedEvents().size());
    // we have 4 attitudes switch on 2 orbits, 2 of each type
    Assert.assertEquals(2, dayToNightHandler.dates.size());
    Assert.assertEquals(2, nightToDayHandler.dates.size());
}
Also used : EclipseDetector(org.orekit.propagation.events.EclipseDetector) FieldOrbit(org.orekit.orbits.FieldOrbit) FieldKeplerianOrbit(org.orekit.orbits.FieldKeplerianOrbit) KeplerianOrbit(org.orekit.orbits.KeplerianOrbit) Orbit(org.orekit.orbits.Orbit) PVCoordinates(org.orekit.utils.PVCoordinates) FieldPVCoordinates(org.orekit.utils.FieldPVCoordinates) FieldOrekitFixedStepHandler(org.orekit.propagation.sampling.FieldOrekitFixedStepHandler) OrekitFixedStepHandler(org.orekit.propagation.sampling.OrekitFixedStepHandler) EventHandler(org.orekit.propagation.events.handlers.EventHandler) FieldAbsoluteDate(org.orekit.time.FieldAbsoluteDate) AbsoluteDate(org.orekit.time.AbsoluteDate) SpacecraftState(org.orekit.propagation.SpacecraftState) FieldSpacecraftState(org.orekit.propagation.FieldSpacecraftState) FieldEcksteinHechlerPropagator(org.orekit.propagation.analytical.FieldEcksteinHechlerPropagator) EcksteinHechlerPropagator(org.orekit.propagation.analytical.EcksteinHechlerPropagator) EventDetector(org.orekit.propagation.events.EventDetector) FieldVector3D(org.hipparchus.geometry.euclidean.threed.FieldVector3D) Vector3D(org.hipparchus.geometry.euclidean.threed.Vector3D) EventsLogger(org.orekit.propagation.events.EventsLogger) Propagator(org.orekit.propagation.Propagator) NumericalPropagator(org.orekit.propagation.numerical.NumericalPropagator) FieldEcksteinHechlerPropagator(org.orekit.propagation.analytical.FieldEcksteinHechlerPropagator) EcksteinHechlerPropagator(org.orekit.propagation.analytical.EcksteinHechlerPropagator) FieldPropagator(org.orekit.propagation.FieldPropagator) PVCoordinatesProvider(org.orekit.utils.PVCoordinatesProvider) FieldKeplerianOrbit(org.orekit.orbits.FieldKeplerianOrbit) KeplerianOrbit(org.orekit.orbits.KeplerianOrbit) OrekitException(org.orekit.errors.OrekitException) FieldOrekitFixedStepHandler(org.orekit.propagation.sampling.FieldOrekitFixedStepHandler) OrekitFixedStepHandler(org.orekit.propagation.sampling.OrekitFixedStepHandler) Test(org.junit.Test)

Example 5 with EventDetector

use of org.orekit.propagation.events.EventDetector in project Orekit by CS-SI.

the class EcksteinHechlerPropagatorTest method ascendingNode.

@Test
public void ascendingNode() throws OrekitException {
    final KeplerianOrbit orbit = new KeplerianOrbit(7.8e6, 0.032, 0.4, 0.1, 0.2, 0.3, PositionAngle.TRUE, FramesFactory.getEME2000(), AbsoluteDate.J2000_EPOCH, provider.getMu());
    EcksteinHechlerPropagator propagator = new EcksteinHechlerPropagator(orbit, provider);
    NodeDetector detector = new NodeDetector(orbit, FramesFactory.getITRF(IERSConventions.IERS_2010, true));
    Assert.assertTrue(FramesFactory.getITRF(IERSConventions.IERS_2010, true) == detector.getFrame());
    propagator.addEventDetector(detector);
    AbsoluteDate farTarget = AbsoluteDate.J2000_EPOCH.shiftedBy(10000.0);
    SpacecraftState propagated = propagator.propagate(farTarget);
    PVCoordinates pv = propagated.getPVCoordinates(FramesFactory.getITRF(IERSConventions.IERS_2010, true));
    Assert.assertTrue(farTarget.durationFrom(propagated.getDate()) > 3500.0);
    Assert.assertTrue(farTarget.durationFrom(propagated.getDate()) < 4000.0);
    Assert.assertEquals(0, pv.getPosition().getZ(), 1.0e-6);
    Assert.assertTrue(pv.getVelocity().getZ() > 0);
    Collection<EventDetector> detectors = propagator.getEventsDetectors();
    Assert.assertEquals(1, detectors.size());
    propagator.clearEventsDetectors();
    Assert.assertEquals(0, propagator.getEventsDetectors().size());
}
Also used : SpacecraftState(org.orekit.propagation.SpacecraftState) EventDetector(org.orekit.propagation.events.EventDetector) NodeDetector(org.orekit.propagation.events.NodeDetector) TimeStampedPVCoordinates(org.orekit.utils.TimeStampedPVCoordinates) PVCoordinates(org.orekit.utils.PVCoordinates) KeplerianOrbit(org.orekit.orbits.KeplerianOrbit) FieldAbsoluteDate(org.orekit.time.FieldAbsoluteDate) AbsoluteDate(org.orekit.time.AbsoluteDate) Test(org.junit.Test)

Aggregations

SpacecraftState (org.orekit.propagation.SpacecraftState)7 EventDetector (org.orekit.propagation.events.EventDetector)7 KeplerianOrbit (org.orekit.orbits.KeplerianOrbit)6 AbsoluteDate (org.orekit.time.AbsoluteDate)6 Orbit (org.orekit.orbits.Orbit)5 FieldAbsoluteDate (org.orekit.time.FieldAbsoluteDate)5 Vector3D (org.hipparchus.geometry.euclidean.threed.Vector3D)4 Test (org.junit.Test)4 OrekitException (org.orekit.errors.OrekitException)4 FieldKeplerianOrbit (org.orekit.orbits.FieldKeplerianOrbit)4 FieldSpacecraftState (org.orekit.propagation.FieldSpacecraftState)4 PVCoordinates (org.orekit.utils.PVCoordinates)4 Propagator (org.orekit.propagation.Propagator)3 EclipseDetector (org.orekit.propagation.events.EclipseDetector)3 OrekitFixedStepHandler (org.orekit.propagation.sampling.OrekitFixedStepHandler)3 PVCoordinatesProvider (org.orekit.utils.PVCoordinatesProvider)3 File (java.io.File)2 FieldVector3D (org.hipparchus.geometry.euclidean.threed.FieldVector3D)2 GeodeticPoint (org.orekit.bodies.GeodeticPoint)2 DataProvidersManager (org.orekit.data.DataProvidersManager)2