Search in sources :

Example 6 with EventDetector

use of org.orekit.propagation.events.EventDetector 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 7 with EventDetector

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

the class VisibilityCheck 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));
        // Initial state definition : date, orbit
        AbsoluteDate initialDate = new AbsoluteDate(2004, 01, 01, 23, 30, 00.000, TimeScalesFactory.getUTC());
        // gravitation coefficient
        double mu = 3.986004415e+14;
        // inertial frame for orbit definition
        Frame inertialFrame = FramesFactory.getEME2000();
        Vector3D position = new Vector3D(-6142438.668, 3492467.560, -25767.25680);
        Vector3D velocity = new Vector3D(505.8479685, 942.7809215, 7435.922231);
        PVCoordinates pvCoordinates = new PVCoordinates(position, velocity);
        Orbit initialOrbit = new KeplerianOrbit(pvCoordinates, inertialFrame, initialDate, mu);
        // Propagator : consider a simple Keplerian motion (could be more elaborate)
        Propagator kepler = new KeplerianPropagator(initialOrbit);
        // Earth and frame
        Frame earthFrame = FramesFactory.getITRF(IERSConventions.IERS_2010, true);
        BodyShape earth = new OneAxisEllipsoid(Constants.WGS84_EARTH_EQUATORIAL_RADIUS, Constants.WGS84_EARTH_FLATTENING, earthFrame);
        // Station
        final double longitude = FastMath.toRadians(45.);
        final double latitude = FastMath.toRadians(25.);
        final double altitude = 0.;
        final GeodeticPoint station1 = new GeodeticPoint(latitude, longitude, altitude);
        final TopocentricFrame sta1Frame = new TopocentricFrame(earth, station1, "station1");
        // Event definition
        final double maxcheck = 60.0;
        final double threshold = 0.001;
        final double elevation = FastMath.toRadians(5.0);
        final EventDetector sta1Visi = new ElevationDetector(maxcheck, threshold, sta1Frame).withConstantElevation(elevation).withHandler(new VisibilityHandler());
        // Add event to be detected
        kepler.addEventDetector(sta1Visi);
        // Propagate from the initial date to the first raising or for the fixed duration
        SpacecraftState finalState = kepler.propagate(initialDate.shiftedBy(1500.));
        System.out.println(" Final state : " + finalState.getDate().durationFrom(initialDate));
    } catch (OrekitException oe) {
        System.err.println(oe.getMessage());
    }
}
Also used : Frame(org.orekit.frames.Frame) TopocentricFrame(org.orekit.frames.TopocentricFrame) OneAxisEllipsoid(org.orekit.bodies.OneAxisEllipsoid) Orbit(org.orekit.orbits.Orbit) KeplerianOrbit(org.orekit.orbits.KeplerianOrbit) ElevationDetector(org.orekit.propagation.events.ElevationDetector) PVCoordinates(org.orekit.utils.PVCoordinates) TopocentricFrame(org.orekit.frames.TopocentricFrame) BodyShape(org.orekit.bodies.BodyShape) AbsoluteDate(org.orekit.time.AbsoluteDate) KeplerianPropagator(org.orekit.propagation.analytical.KeplerianPropagator) SpacecraftState(org.orekit.propagation.SpacecraftState) EventDetector(org.orekit.propagation.events.EventDetector) Vector3D(org.hipparchus.geometry.euclidean.threed.Vector3D) Propagator(org.orekit.propagation.Propagator) KeplerianPropagator(org.orekit.propagation.analytical.KeplerianPropagator) DirectoryCrawler(org.orekit.data.DirectoryCrawler) DataProvidersManager(org.orekit.data.DataProvidersManager) KeplerianOrbit(org.orekit.orbits.KeplerianOrbit) OrekitException(org.orekit.errors.OrekitException) GeodeticPoint(org.orekit.bodies.GeodeticPoint) File(java.io.File)

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