1   /* Copyright 2002-2022 CS GROUP
2    * Licensed to CS GROUP (CS) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * CS licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *   http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  package org.orekit.propagation.events;
18  
19  import org.hipparchus.ode.events.Action;
20  import org.hipparchus.util.FastMath;
21  import org.junit.After;
22  import org.junit.Assert;
23  import org.junit.Before;
24  import org.junit.Test;
25  import org.orekit.Utils;
26  import org.orekit.bodies.BodyShape;
27  import org.orekit.bodies.GeodeticPoint;
28  import org.orekit.bodies.OneAxisEllipsoid;
29  import org.orekit.frames.FramesFactory;
30  import org.orekit.frames.TopocentricFrame;
31  import org.orekit.orbits.KeplerianOrbit;
32  import org.orekit.orbits.Orbit;
33  import org.orekit.orbits.PositionAngle;
34  import org.orekit.propagation.SpacecraftState;
35  import org.orekit.propagation.analytical.KeplerianPropagator;
36  import org.orekit.propagation.events.handlers.EventHandler;
37  import org.orekit.time.AbsoluteDate;
38  import org.orekit.time.TimeScale;
39  import org.orekit.time.TimeScalesFactory;
40  import org.orekit.utils.Constants;
41  import org.orekit.utils.IERSConventions;
42  
43  public class BackAndForthDetectorTest {
44  
45      @Test
46      public void testBackAndForth() {
47  
48          final TimeScale utc = TimeScalesFactory.getUTC();
49  
50          final AbsoluteDate date0 = new AbsoluteDate(2006, 12, 27, 12,  0, 0.0, utc);
51          final AbsoluteDate date1 = new AbsoluteDate(2006, 12, 27, 22, 50, 0.0, utc);
52          final AbsoluteDate date2 = new AbsoluteDate(2006, 12, 27, 22, 58, 0.0, utc);
53  
54          // Orbit
55          final double a = 7274000.;
56          final double e = 0.00127;
57          final double i = FastMath.toRadians(90.);
58          final double w = FastMath.toRadians(0.);
59          final double raan = FastMath.toRadians(12.5);
60          final double lM = FastMath.toRadians(60.);
61          Orbit iniOrb = new KeplerianOrbit(a, e, i, w, raan, lM,
62                                            PositionAngle.MEAN, FramesFactory.getEME2000(), date0,
63                                            Constants.WGS84_EARTH_MU);
64  
65          // Propagator
66          KeplerianPropagator propagator = new KeplerianPropagator(iniOrb);
67  
68          // Station
69          final GeodeticPoint stationPosition = new GeodeticPoint(FastMath.toRadians(0.), FastMath.toRadians(100.), 110.);
70          final BodyShape earth = new OneAxisEllipsoid(Constants.WGS84_EARTH_EQUATORIAL_RADIUS,
71                                                       Constants.WGS84_EARTH_FLATTENING,
72                                                       FramesFactory.getITRF(IERSConventions.IERS_2010, true));
73          final TopocentricFrame stationFrame = new TopocentricFrame(earth, stationPosition, "");
74  
75          // Detector
76          final Visibility visi = new Visibility();
77          propagator.addEventDetector(new ElevationDetector(stationFrame).
78                                      withConstantElevation(FastMath.toRadians(10.)).
79                                      withHandler(visi));
80  
81          // Forward propagation (AOS + LOS)
82          propagator.propagate(date1);
83          propagator.propagate(date2);
84          // Backward propagation (AOS + LOS)
85          propagator.propagate(date1);
86          propagator.propagate(date0);
87  
88          Assert.assertEquals(4, visi.getVisiNb());
89  
90      }
91  
92      private static class Visibility implements EventHandler<ElevationDetector> {
93          private int _visiNb;
94  
95          public Visibility() {
96              _visiNb = 0;
97          }
98  
99          public int getVisiNb() {
100             return _visiNb;
101         }
102 
103         public Action eventOccurred(SpacecraftState s, ElevationDetector ed, boolean increasing) {
104             _visiNb++;
105             return Action.CONTINUE;
106         }
107 
108     }
109 
110     @Before
111     public void setUp() {
112         Utils.setDataRoot("regular-data");
113     }
114 
115     @After
116     public void tearDown() {
117     }
118 
119 }
120