TLEPropagatorBuilder.java

  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.conversion;

  18. import java.util.List;

  19. import org.orekit.annotation.DefaultDataContext;
  20. import org.orekit.attitudes.InertialProvider;
  21. import org.orekit.data.DataContext;
  22. import org.orekit.estimation.leastsquares.AbstractBatchLSModel;
  23. import org.orekit.estimation.leastsquares.BatchLSModel;
  24. import org.orekit.estimation.leastsquares.ModelObserver;
  25. import org.orekit.estimation.measurements.ObservedMeasurement;
  26. import org.orekit.estimation.sequential.AbstractKalmanModel;
  27. import org.orekit.estimation.sequential.CovarianceMatrixProvider;
  28. import org.orekit.estimation.sequential.KalmanModel;
  29. import org.orekit.frames.Frame;
  30. import org.orekit.orbits.Orbit;
  31. import org.orekit.orbits.PositionAngle;
  32. import org.orekit.propagation.Propagator;
  33. import org.orekit.propagation.SpacecraftState;
  34. import org.orekit.propagation.analytical.tle.TLE;
  35. import org.orekit.propagation.analytical.tle.TLEPropagator;
  36. import org.orekit.time.TimeScale;
  37. import org.orekit.utils.ParameterDriver;
  38. import org.orekit.utils.ParameterDriversList;

  39. /** Builder for TLEPropagator.
  40.  * @author Pascal Parraud
  41.  * @author Thomas Paulet
  42.  * @since 6.0
  43.  */
  44. public class TLEPropagatorBuilder extends AbstractPropagatorBuilder implements OrbitDeterminationPropagatorBuilder {

  45.     /** Default value for epsilon. */
  46.     private static final double EPSILON_DEFAULT = 1.0e-10;

  47.     /** Default value for maxIterations. */
  48.     private static final int MAX_ITERATIONS_DEFAULT = 100;

  49.     /** Data context used to access frames and time scales. */
  50.     private final DataContext dataContext;

  51.     /** Template TLE. */
  52.     private final TLE templateTLE;

  53.     /** Threshold for convergence used in TLE generation. */
  54.     private final double epsilon;

  55.     /** Maximum number of iterations for convergence used in TLE generation. */
  56.     private final int maxIterations;

  57.     /** Build a new instance. This constructor uses the {@link DataContext#getDefault()
  58.      * default data context}.
  59.      * <p>
  60.      * The template TLE is used as a model to {@link
  61.      * #createInitialOrbit() create initial orbit}. It defines the
  62.      * inertial frame, the central attraction coefficient, orbit type, satellite number,
  63.      * classification, .... and is also used together with the {@code positionScale} to
  64.      * convert from the {@link ParameterDriver#setNormalizedValue(double) normalized}
  65.      * parameters used by the callers of this builder to the real orbital parameters.
  66.      * </p><p>
  67.      * Using this constructor, {@link #EPSILON_DEFAULT} and {@link #MAX_ITERATIONS_DEFAULT}
  68.      * are used for spacecraft's state to TLE transformation
  69.      * </p>
  70.      * @param templateTLE reference TLE from which real orbits will be built
  71.      * @param positionAngle position angle type to use
  72.      * @param positionScale scaling factor used for orbital parameters normalization
  73.      * (typically set to the expected standard deviation of the position)
  74.      * @since 7.1
  75.      * @see #TLEPropagatorBuilder(TLE, PositionAngle, double, DataContext)
  76.      */
  77.     @DefaultDataContext
  78.     public TLEPropagatorBuilder(final TLE templateTLE, final PositionAngle positionAngle,
  79.                                 final double positionScale) {
  80.         this(templateTLE, positionAngle, positionScale, DataContext.getDefault());
  81.     }

  82.     /** Build a new instance.
  83.      * <p>
  84.      * The template TLE is used as a model to {@link
  85.      * #createInitialOrbit() create initial orbit}. It defines the
  86.      * inertial frame, the central attraction coefficient, orbit type, satellite number,
  87.      * classification, .... and is also used together with the {@code positionScale} to
  88.      * convert from the {@link ParameterDriver#setNormalizedValue(double) normalized}
  89.      * parameters used by the callers of this builder to the real orbital parameters.
  90.      * </p><p>
  91.      * Using this constructor, {@link #EPSILON_DEFAULT} and {@link #MAX_ITERATIONS_DEFAULT}
  92.      * are used for spacecraft's state to TLE transformation
  93.      * </p>
  94.      * @param templateTLE reference TLE from which real orbits will be built
  95.      * @param positionAngle position angle type to use
  96.      * @param positionScale scaling factor used for orbital parameters normalization
  97.      * (typically set to the expected standard deviation of the position)
  98.      * @param dataContext used to access frames and time scales.
  99.      * @since 10.1
  100.      * @see #TLEPropagatorBuilder(TLE, PositionAngle, double, DataContext, double, int)
  101.      */
  102.     public TLEPropagatorBuilder(final TLE templateTLE,
  103.                                 final PositionAngle positionAngle,
  104.                                 final double positionScale,
  105.                                 final DataContext dataContext) {
  106.         this(templateTLE, positionAngle, positionScale, dataContext, EPSILON_DEFAULT, MAX_ITERATIONS_DEFAULT);
  107.     }

  108.     /** Build a new instance. This constructor uses the {@link DataContext#getDefault()
  109.      * default data context}.
  110.      * <p>
  111.      * The template TLE is used as a model to {@link
  112.      * #createInitialOrbit() create initial orbit}. It defines the
  113.      * inertial frame, the central attraction coefficient, orbit type, satellite number,
  114.      * classification, .... and is also used together with the {@code positionScale} to
  115.      * convert from the {@link ParameterDriver#setNormalizedValue(double) normalized}
  116.      * parameters used by the callers of this builder to the real orbital parameters.
  117.      * </p>
  118.      * @param templateTLE reference TLE from which real orbits will be built
  119.      * @param positionAngle position angle type to use
  120.      * @param positionScale scaling factor used for orbital parameters normalization
  121.      * (typically set to the expected standard deviation of the position)
  122.      * @param epsilon used to compute threshold for convergence check
  123.      * @param maxIterations maximum number of iterations for convergence
  124.      * @since 11.0.2
  125.      * @see #TLEPropagatorBuilder(TLE, PositionAngle, double, DataContext, double, int)
  126.      */
  127.     @DefaultDataContext
  128.     public TLEPropagatorBuilder(final TLE templateTLE, final PositionAngle positionAngle,
  129.                                 final double positionScale, final double epsilon,
  130.                                 final int maxIterations) {
  131.         this(templateTLE, positionAngle, positionScale, DataContext.getDefault(), epsilon, maxIterations);
  132.     }

  133.     /** Build a new instance.
  134.      * <p>
  135.      * The template TLE is used as a model to {@link
  136.      * #createInitialOrbit() create initial orbit}. It defines the
  137.      * inertial frame, the central attraction coefficient, orbit type, satellite number,
  138.      * classification, .... and is also used together with the {@code positionScale} to
  139.      * convert from the {@link ParameterDriver#setNormalizedValue(double) normalized}
  140.      * parameters used by the callers of this builder to the real orbital parameters.
  141.      * </p>
  142.      * @param templateTLE reference TLE from which real orbits will be built
  143.      * @param positionAngle position angle type to use
  144.      * @param positionScale scaling factor used for orbital parameters normalization
  145.      * (typically set to the expected standard deviation of the position)
  146.      * @param dataContext used to access frames and time scales.
  147.      * @param epsilon used to compute threshold for convergence check
  148.      * @param maxIterations maximum number of iterations for convergence
  149.      * @since 11.0.2
  150.      */
  151.     public TLEPropagatorBuilder(final TLE templateTLE,
  152.                                 final PositionAngle positionAngle,
  153.                                 final double positionScale,
  154.                                 final DataContext dataContext,
  155.                                 final double epsilon,
  156.                                 final int maxIterations) {
  157.         super(TLEPropagator.selectExtrapolator(templateTLE, dataContext.getFrames())
  158.                         .getInitialState().getOrbit(),
  159.               positionAngle, positionScale, false,
  160.               InertialProvider.of(dataContext.getFrames().getTEME()));
  161.         for (final ParameterDriver driver : templateTLE.getParametersDrivers()) {
  162.             addSupportedParameter(driver);
  163.         }
  164.         this.templateTLE   = templateTLE;
  165.         this.dataContext   = dataContext;
  166.         this.epsilon       = epsilon;
  167.         this.maxIterations = maxIterations;
  168.     }

  169.     /** {@inheritDoc} */
  170.     @Override
  171.     public TLEPropagator buildPropagator(final double[] normalizedParameters) {

  172.         // create the orbit
  173.         setParameters(normalizedParameters);
  174.         final Orbit           orbit = createInitialOrbit();
  175.         final SpacecraftState state = new SpacecraftState(orbit);
  176.         final Frame           teme  = dataContext.getFrames().getTEME();
  177.         final TimeScale       utc   = dataContext.getTimeScales().getUTC();

  178.         // TLE related to the orbit
  179.         final TLE tle = TLE.stateToTLE(state, templateTLE, utc, teme, epsilon, maxIterations);
  180.         final List<ParameterDriver> drivers = templateTLE.getParametersDrivers();
  181.         for (int index = 0; index < drivers.size(); index++) {
  182.             if (drivers.get(index).isSelected()) {
  183.                 tle.getParametersDrivers().get(index).setSelected(true);
  184.             }
  185.         }

  186.         // propagator
  187.         return TLEPropagator.selectExtrapolator(tle,
  188.                                                 getAttitudeProvider(),
  189.                                                 Propagator.DEFAULT_MASS,
  190.                                                 teme);

  191.     }

  192.     /** Getter for the template TLE.
  193.      * @return the template TLE
  194.      */
  195.     public TLE getTemplateTLE() {
  196.         return templateTLE;
  197.     }

  198.     /** {@inheritDoc} */
  199.     public AbstractBatchLSModel buildLSModel(final OrbitDeterminationPropagatorBuilder[] builders,
  200.                                 final List<ObservedMeasurement<?>> measurements,
  201.                                 final ParameterDriversList estimatedMeasurementsParameters,
  202.                                 final ModelObserver observer) {
  203.         return new BatchLSModel(builders, measurements, estimatedMeasurementsParameters, observer);
  204.     }

  205.     @Override
  206.     public AbstractKalmanModel
  207.         buildKalmanModel(final List<OrbitDeterminationPropagatorBuilder> propagatorBuilders,
  208.                          final List<CovarianceMatrixProvider> covarianceMatricesProviders,
  209.                          final ParameterDriversList estimatedMeasurementsParameters,
  210.                          final CovarianceMatrixProvider measurementProcessNoiseMatrix) {
  211.         return new KalmanModel(propagatorBuilders, covarianceMatricesProviders, estimatedMeasurementsParameters, measurementProcessNoiseMatrix);
  212.     }

  213. }