Created
February 23, 2017 11:14
-
-
Save anonymous/fb939c0df8e6a72282eb27cc76840ac9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package org.testing.orekit; | |
import java.io.File; | |
import java.util.Locale; | |
import org.hipparchus.ode.nonstiff.AdaptiveStepsizeIntegrator; | |
import org.hipparchus.ode.nonstiff.DormandPrince853Integrator; | |
import org.hipparchus.util.FastMath; | |
import org.orekit.bodies.BodyShape; | |
import org.orekit.bodies.GeodeticPoint; | |
import org.orekit.bodies.OneAxisEllipsoid; | |
import org.orekit.data.DataProvidersManager; | |
import org.orekit.data.DirectoryCrawler; | |
import org.orekit.errors.OrekitException; | |
import org.orekit.forces.ForceModel; | |
import org.orekit.forces.gravity.HolmesFeatherstoneAttractionModel; | |
import org.orekit.forces.gravity.potential.GravityFieldFactory; | |
import org.orekit.forces.gravity.potential.NormalizedSphericalHarmonicsProvider; | |
import org.orekit.frames.Frame; | |
import org.orekit.frames.FramesFactory; | |
import org.orekit.frames.TopocentricFrame; | |
import org.orekit.orbits.KeplerianOrbit; | |
import org.orekit.orbits.Orbit; | |
import org.orekit.orbits.OrbitType; | |
import org.orekit.orbits.PositionAngle; | |
import org.orekit.propagation.SpacecraftState; | |
import org.orekit.propagation.events.ElevationDetector; | |
import org.orekit.propagation.events.EventDetector; | |
import org.orekit.propagation.events.handlers.EventHandler; | |
import org.orekit.propagation.numerical.NumericalPropagator; | |
import org.orekit.propagation.sampling.OrekitFixedStepHandler; | |
import org.orekit.time.AbsoluteDate; | |
import org.orekit.time.TimeScalesFactory; | |
import org.orekit.utils.Constants; | |
import org.orekit.utils.IERSConventions; | |
public class MasterMode { | |
/** Program entry point. | |
* @param args program arguments (unused here) | |
*/ | |
public static void main(String[] args) { | |
try { | |
File orekitData = new File(VisibilityCheck.class.getClassLoader().getResource("orekit-data").getFile()); | |
DataProvidersManager manager = DataProvidersManager.getInstance(); | |
manager.addProvider(new DirectoryCrawler(orekitData)); | |
// configure Orekit | |
Autoconfiguration.configureOrekit(); | |
// gravitation coefficient | |
double mu = 3.986004415e+14; | |
// inertial frame | |
Frame inertialFrame = FramesFactory.getEME2000(); | |
// Initial date | |
AbsoluteDate initialDate = new AbsoluteDate(2017, 02, 23, 12, 57, 57.000, | |
TimeScalesFactory.getUTC()); | |
// Initial orbit | |
double a = 6731000; // semi major axis in meters | |
double e = 0.0006623; // eccentricity | |
double i = FastMath.toRadians(51.6380); // inclination | |
double omega = FastMath.toRadians(228.6235); // perigee argument | |
double raan = FastMath.toRadians(244.8319); // right ascention of ascending node | |
double lM = 131.4349; // mean anomaly | |
Orbit initialOrbit = new KeplerianOrbit(a, e, i, omega, raan, lM, PositionAngle.MEAN, | |
inertialFrame, initialDate, mu); | |
// Initial state definition | |
SpacecraftState initialState = new SpacecraftState(initialOrbit); | |
// Adaptive step integrator with a minimum step of 0.001 and a maximum step of 1000 | |
final double minStep = 0.001; | |
final double maxstep = 1000.0; | |
final double positionTolerance = 10.0; | |
final OrbitType propagationType = OrbitType.KEPLERIAN; | |
final double[][] tolerances = | |
NumericalPropagator.tolerances(positionTolerance, initialOrbit, propagationType); | |
AdaptiveStepsizeIntegrator integrator = | |
new DormandPrince853Integrator(minStep, maxstep, tolerances[0], tolerances[1]); | |
// Propagator | |
NumericalPropagator propagator = new NumericalPropagator(integrator); | |
propagator.setOrbitType(propagationType); | |
// Force Model (reduced to perturbing gravity field) | |
final NormalizedSphericalHarmonicsProvider provider = | |
GravityFieldFactory.getNormalizedProvider(10, 10); | |
ForceModel holmesFeatherstone = | |
new HolmesFeatherstoneAttractionModel(FramesFactory.getITRF(IERSConventions.IERS_2010, | |
true), | |
provider); | |
// Add force model to the propagator | |
propagator.addForceModel(holmesFeatherstone); | |
// Set up initial state in the propagator | |
propagator.setInitialState(initialState); | |
// Set up operating mode for the propagator as master mode | |
// with fixed step and specialized step handler | |
propagator.setMasterMode(60., new TutorialStepHandler()); | |
Frame earthFrame = FramesFactory.getITRF(IERSConventions.IERS_2010, true); | |
BodyShape earth = new OneAxisEllipsoid(Constants.WGS84_EARTH_EQUATORIAL_RADIUS, | |
Constants.WGS84_EARTH_FLATTENING, | |
earthFrame); | |
final double longitude = FastMath.toRadians(12.4964); | |
final double latitude = FastMath.toRadians(41.9028); | |
final double altitude = 53; | |
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(10.0); | |
final EventDetector sta1Visi = | |
new ElevationDetector(maxcheck, threshold, sta1Frame). | |
withConstantElevation(elevation). | |
withHandler(new MasterMode.VisibilityHandler()); | |
// Add event to be detected | |
propagator.addEventDetector(sta1Visi); | |
// Propagate from the initial date to the first raising or for the fixed duration | |
SpacecraftState finalState = propagator.propagate(initialDate.shiftedBy(25000000.)); | |
System.out.println(" Final state : " + finalState.getDate().durationFrom(initialDate)); | |
} catch (OrekitException oe) { | |
System.err.println(oe.getMessage()); | |
} | |
} | |
/** Handler for visibility event. */ | |
private static class VisibilityHandler implements EventHandler<ElevationDetector> { | |
public Action eventOccurred(final SpacecraftState s, final ElevationDetector detector, | |
final boolean increasing) { | |
if (increasing) { | |
System.out.println(" Visibility on " + detector.getTopocentricFrame().getName() | |
+ " begins at " + s.getDate()); | |
return Action.CONTINUE; | |
} else { | |
System.out.println(" Visibility on " + detector.getTopocentricFrame().getName() | |
+ " ends at " + s.getDate()); | |
return Action.STOP; | |
} | |
} | |
} | |
/** Specialized step handler. | |
* <p>This class extends the step handler in order to print on the output stream at the given step.<p> | |
* @author Pascal Parraud | |
*/ | |
private static class TutorialStepHandler implements OrekitFixedStepHandler { | |
private TutorialStepHandler() { | |
//private constructor | |
} | |
public void init(final SpacecraftState s0, final AbsoluteDate t) { | |
System.out.println(" date a e" + | |
" i \u03c9 \u03a9" + | |
" \u03bd"); | |
} | |
public void handleStep(SpacecraftState currentState, boolean isLast) { | |
KeplerianOrbit o = (KeplerianOrbit) OrbitType.KEPLERIAN.convertType(currentState.getOrbit()); | |
if (isLast) { | |
System.out.format(Locale.US, "%s %12.3f %10.8f %10.6f %10.6f %10.6f %10.6f%n", | |
currentState.getDate(), | |
o.getA(), o.getE(), | |
FastMath.toDegrees(o.getI()), | |
FastMath.toDegrees(o.getPerigeeArgument()), | |
FastMath.toDegrees(o.getRightAscensionOfAscendingNode()), | |
FastMath.toDegrees(o.getTrueAnomaly())); | |
System.out.println("this was the last step "); | |
System.out.println(); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment