1   /* Copyright 2002-2024 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  
18  package org.orekit.estimation;
19  
20  import org.hipparchus.geometry.euclidean.threed.Vector3D;
21  import org.hipparchus.util.FastMath;
22  import org.orekit.bodies.CelestialBody;
23  import org.orekit.bodies.GeodeticPoint;
24  import org.orekit.bodies.OneAxisEllipsoid;
25  import org.orekit.estimation.measurements.GroundStation;
26  import org.orekit.frames.TopocentricFrame;
27  import org.orekit.models.earth.displacement.StationDisplacement;
28  import org.orekit.models.earth.troposphere.TroposphericModelUtils;
29  import org.orekit.orbits.CartesianOrbit;
30  import org.orekit.orbits.Orbit;
31  import org.orekit.orbits.PositionAngleType;
32  import org.orekit.propagation.conversion.KeplerianPropagatorBuilder;
33  import org.orekit.time.TimeScale;
34  import org.orekit.time.UT1Scale;
35  import org.orekit.utils.IERSConventions;
36  import org.orekit.utils.PVCoordinates;
37  
38  import java.util.List;
39  
40  public class KeplerianContext implements StationDataProvider {
41  
42      public IERSConventions                        conventions;
43      public OneAxisEllipsoid                       earth;
44      public CelestialBody                          sun;
45      public CelestialBody                          moon;
46      public TimeScale                              utc;
47      public UT1Scale                               ut1;
48      public Orbit                                  initialOrbit;
49      public StationDisplacement[]                  displacements;
50      public List<GroundStation>                    stations;
51  
52      public KeplerianPropagatorBuilder createBuilder(final PositionAngleType angleType, final boolean perfectStart, final double dP) {
53  
54          final Orbit startOrbit;
55          if (perfectStart) {
56              // orbit estimation will start from a perfect orbit
57              startOrbit = initialOrbit;
58          } else {
59              // orbit estimation will start from a wrong point
60              final Vector3D initialPosition = initialOrbit.getPosition();
61              final Vector3D initialVelocity = initialOrbit.getPVCoordinates().getVelocity();
62              final Vector3D wrongPosition   = initialPosition.add(new Vector3D(1000.0, 0, 0));
63              final Vector3D wrongVelocity   = initialVelocity.add(new Vector3D(0, 0, 0.01));
64              startOrbit                     = new CartesianOrbit(new PVCoordinates(wrongPosition, wrongVelocity),
65                                                                  initialOrbit.getFrame(),
66                                                                  initialOrbit.getDate(),
67                                                                  initialOrbit.getMu());
68          }
69  
70          // Initialize builder
71          final KeplerianPropagatorBuilder propagatorBuilder =
72                          new KeplerianPropagatorBuilder(startOrbit, angleType, dP);
73  
74          // Return
75          return propagatorBuilder;
76  
77      }
78  
79      GroundStation createStation(double latitudeInDegrees, double longitudeInDegrees,
80                                  double altitude, String name) {
81          final GeodeticPoint gp = new GeodeticPoint(FastMath.toRadians(latitudeInDegrees),
82                                                     FastMath.toRadians(longitudeInDegrees),
83                                                     altitude);
84          return new GroundStation(new TopocentricFrame(earth, gp, name),
85                                   TroposphericModelUtils.STANDARD_ATMOSPHERE_PROVIDER,
86                                   ut1.getEOPHistory(), displacements);
87      }
88  
89      @Override
90      public List<GroundStation> getStations() {
91          return stations;
92      }
93  
94  }