1 /* Copyright 2002-2021 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.conversion;
18
19 import java.util.List;
20
21 import org.orekit.annotation.DefaultDataContext;
22 import org.orekit.attitudes.InertialProvider;
23 import org.orekit.data.DataContext;
24 import org.orekit.estimation.leastsquares.AbstractBatchLSModel;
25 import org.orekit.estimation.leastsquares.ModelObserver;
26 import org.orekit.estimation.leastsquares.TLEBatchLSModel;
27 import org.orekit.estimation.measurements.ObservedMeasurement;
28 import org.orekit.estimation.sequential.AbstractKalmanModel;
29 import org.orekit.estimation.sequential.CovarianceMatrixProvider;
30 import org.orekit.estimation.sequential.TLEKalmanModel;
31 import org.orekit.frames.Frame;
32 import org.orekit.orbits.Orbit;
33 import org.orekit.orbits.PositionAngle;
34 import org.orekit.propagation.Propagator;
35 import org.orekit.propagation.SpacecraftState;
36 import org.orekit.propagation.analytical.tle.TLE;
37 import org.orekit.propagation.analytical.tle.TLEPropagator;
38 import org.orekit.time.TimeScale;
39 import org.orekit.utils.ParameterDriver;
40 import org.orekit.utils.ParameterDriversList;
41
42 /** Builder for TLEPropagator.
43 * @author Pascal Parraud
44 * @author Thomas Paulet
45 * @since 6.0
46 */
47 public class TLEPropagatorBuilder extends AbstractPropagatorBuilder implements OrbitDeterminationPropagatorBuilder {
48
49 /** Default value for epsilon. */
50 private static final double EPSILON_DEFAULT = 1.0e-10;
51
52 /** Default value for maxIterations. */
53 private static final int MAX_ITERATIONS_DEFAULT = 100;
54
55 /** Data context used to access frames and time scales. */
56 private final DataContext dataContext;
57
58 /** Template TLE. */
59 private final TLE templateTLE;
60
61 /** Threshold for convergence used in TLE generation. */
62 private final double epsilon;
63
64 /** Maximum number of iterations for convergence used in TLE generation. */
65 private final int maxIterations;
66
67 /** Build a new instance. This constructor uses the {@link DataContext#getDefault()
68 * default data context}.
69 * <p>
70 * The template TLE is used as a model to {@link
71 * #createInitialOrbit() create initial orbit}. It defines the
72 * inertial frame, the central attraction coefficient, orbit type, satellite number,
73 * classification, .... and is also used together with the {@code positionScale} to
74 * convert from the {@link ParameterDriver#setNormalizedValue(double) normalized}
75 * parameters used by the callers of this builder to the real orbital parameters.
76 * </p><p>
77 * Using this constructor, {@link #EPSILON_DEFAULT} and {@link #MAX_ITERATIONS_DEFAULT}
78 * are used for spacecraft's state to TLE transformation
79 * </p>
80 * @param templateTLE reference TLE from which real orbits will be built
81 * @param positionAngle position angle type to use
82 * @param positionScale scaling factor used for orbital parameters normalization
83 * (typically set to the expected standard deviation of the position)
84 * @since 7.1
85 * @see #TLEPropagatorBuilder(TLE, PositionAngle, double, DataContext)
86 */
87 @DefaultDataContext
88 public TLEPropagatorBuilder(final TLE templateTLE, final PositionAngle positionAngle,
89 final double positionScale) {
90 this(templateTLE, positionAngle, positionScale, DataContext.getDefault());
91 }
92
93 /** Build a new instance.
94 * <p>
95 * The template TLE is used as a model to {@link
96 * #createInitialOrbit() create initial orbit}. It defines the
97 * inertial frame, the central attraction coefficient, orbit type, satellite number,
98 * classification, .... and is also used together with the {@code positionScale} to
99 * convert from the {@link ParameterDriver#setNormalizedValue(double) normalized}
100 * parameters used by the callers of this builder to the real orbital parameters.
101 * </p><p>
102 * Using this constructor, {@link #EPSILON_DEFAULT} and {@link #MAX_ITERATIONS_DEFAULT}
103 * are used for spacecraft's state to TLE transformation
104 * </p>
105 * @param templateTLE reference TLE from which real orbits will be built
106 * @param positionAngle position angle type to use
107 * @param positionScale scaling factor used for orbital parameters normalization
108 * (typically set to the expected standard deviation of the position)
109 * @param dataContext used to access frames and time scales.
110 * @since 10.1
111 * @see #TLEPropagatorBuilder(TLE, PositionAngle, double, DataContext, double, int)
112 */
113 public TLEPropagatorBuilder(final TLE templateTLE,
114 final PositionAngle positionAngle,
115 final double positionScale,
116 final DataContext dataContext) {
117 this(templateTLE, positionAngle, positionScale, dataContext, EPSILON_DEFAULT, MAX_ITERATIONS_DEFAULT);
118 }
119
120 /** Build a new instance. This constructor uses the {@link DataContext#getDefault()
121 * default data context}.
122 * <p>
123 * The template TLE is used as a model to {@link
124 * #createInitialOrbit() create initial orbit}. It defines the
125 * inertial frame, the central attraction coefficient, orbit type, satellite number,
126 * classification, .... and is also used together with the {@code positionScale} to
127 * convert from the {@link ParameterDriver#setNormalizedValue(double) normalized}
128 * parameters used by the callers of this builder to the real orbital parameters.
129 * </p>
130 * @param templateTLE reference TLE from which real orbits will be built
131 * @param positionAngle position angle type to use
132 * @param positionScale scaling factor used for orbital parameters normalization
133 * (typically set to the expected standard deviation of the position)
134 * @param epsilon used to compute threshold for convergence check
135 * @param maxIterations maximum number of iterations for convergence
136 * @since 11.0.2
137 * @see #TLEPropagatorBuilder(TLE, PositionAngle, double, DataContext, double, int)
138 */
139 @DefaultDataContext
140 public TLEPropagatorBuilder(final TLE templateTLE, final PositionAngle positionAngle,
141 final double positionScale, final double epsilon,
142 final int maxIterations) {
143 this(templateTLE, positionAngle, positionScale, DataContext.getDefault(), epsilon, maxIterations);
144 }
145
146 /** Build a new instance.
147 * <p>
148 * The template TLE is used as a model to {@link
149 * #createInitialOrbit() create initial orbit}. It defines the
150 * inertial frame, the central attraction coefficient, orbit type, satellite number,
151 * classification, .... and is also used together with the {@code positionScale} to
152 * convert from the {@link ParameterDriver#setNormalizedValue(double) normalized}
153 * parameters used by the callers of this builder to the real orbital parameters.
154 * </p>
155 * @param templateTLE reference TLE from which real orbits will be built
156 * @param positionAngle position angle type to use
157 * @param positionScale scaling factor used for orbital parameters normalization
158 * (typically set to the expected standard deviation of the position)
159 * @param dataContext used to access frames and time scales.
160 * @param epsilon used to compute threshold for convergence check
161 * @param maxIterations maximum number of iterations for convergence
162 * @since 11.0.2
163 */
164 public TLEPropagatorBuilder(final TLE templateTLE,
165 final PositionAngle positionAngle,
166 final double positionScale,
167 final DataContext dataContext,
168 final double epsilon,
169 final int maxIterations) {
170 super(TLEPropagator.selectExtrapolator(templateTLE, dataContext.getFrames())
171 .getInitialState().getOrbit(),
172 positionAngle, positionScale, false,
173 InertialProvider.of(dataContext.getFrames().getTEME()));
174 for (final ParameterDriver driver : templateTLE.getParametersDrivers()) {
175 addSupportedParameter(driver);
176 }
177 this.templateTLE = templateTLE;
178 this.dataContext = dataContext;
179 this.epsilon = epsilon;
180 this.maxIterations = maxIterations;
181 }
182
183 /** {@inheritDoc} */
184 @Override
185 public TLEPropagator buildPropagator(final double[] normalizedParameters) {
186
187 // create the orbit
188 setParameters(normalizedParameters);
189 final Orbit orbit = createInitialOrbit();
190 final SpacecraftState state = new SpacecraftState(orbit);
191 final Frame teme = dataContext.getFrames().getTEME();
192 final TimeScale utc = dataContext.getTimeScales().getUTC();
193
194 // TLE related to the orbit
195 final TLE tle = TLE.stateToTLE(state, templateTLE, utc, teme, epsilon, maxIterations);
196 final List<ParameterDriver> drivers = templateTLE.getParametersDrivers();
197 for (int index = 0; index < drivers.size(); index++) {
198 if (drivers.get(index).isSelected()) {
199 tle.getParametersDrivers().get(index).setSelected(true);
200 }
201 }
202
203 // propagator
204 return TLEPropagator.selectExtrapolator(tle,
205 getAttitudeProvider(),
206 Propagator.DEFAULT_MASS,
207 teme);
208
209 }
210
211 /** Getter for the template TLE.
212 * @return the template TLE
213 */
214 public TLE getTemplateTLE() {
215 return templateTLE;
216 }
217
218 /** {@inheritDoc} */
219 public AbstractBatchLSModel buildLSModel(final OrbitDeterminationPropagatorBuilder[] builders,
220 final List<ObservedMeasurement<?>> measurements,
221 final ParameterDriversList estimatedMeasurementsParameters,
222 final ModelObserver observer) {
223 return new TLEBatchLSModel(builders, measurements, estimatedMeasurementsParameters, observer);
224 }
225
226 @Override
227 public AbstractKalmanModel
228 buildKalmanModel(final List<OrbitDeterminationPropagatorBuilder> propagatorBuilders,
229 final List<CovarianceMatrixProvider> covarianceMatricesProviders,
230 final ParameterDriversList estimatedMeasurementsParameters,
231 final CovarianceMatrixProvider measurementProcessNoiseMatrix) {
232 return new TLEKalmanModel(propagatorBuilders, covarianceMatricesProviders, estimatedMeasurementsParameters, measurementProcessNoiseMatrix);
233 }
234
235 }