TLEPropagatorBuilder.java

  1. /* Copyright 2002-2020 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 org.hipparchus.util.FastMath;
  19. import org.hipparchus.util.MathUtils;
  20. import org.orekit.annotation.DefaultDataContext;
  21. import org.orekit.data.DataContext;
  22. import org.orekit.errors.OrekitException;
  23. import org.orekit.errors.OrekitInternalError;
  24. import org.orekit.orbits.KeplerianOrbit;
  25. import org.orekit.orbits.Orbit;
  26. import org.orekit.orbits.OrbitType;
  27. import org.orekit.orbits.PositionAngle;
  28. import org.orekit.propagation.Propagator;
  29. import org.orekit.propagation.analytical.tle.TLE;
  30. import org.orekit.propagation.analytical.tle.TLEPropagator;
  31. import org.orekit.utils.ParameterDriver;
  32. import org.orekit.utils.ParameterObserver;

  33. /** Builder for TLEPropagator.
  34.  * @author Pascal Parraud
  35.  * @since 6.0
  36.  */
  37. public class TLEPropagatorBuilder extends AbstractPropagatorBuilder {

  38.     /** Parameter name for B* coefficient. */
  39.     public static final String B_STAR = "BSTAR";

  40.     /** B* scaling factor.
  41.      * <p>
  42.      * We use a power of 2 to avoid numeric noise introduction
  43.      * in the multiplications/divisions sequences.
  44.      * </p>
  45.      */
  46.     private static final double B_STAR_SCALE = FastMath.scalb(1.0, -20);

  47.     /** Satellite number. */
  48.     private final int satelliteNumber;

  49.     /** Classification (U for unclassified). */
  50.     private final char classification;

  51.     /** Launch year (all digits). */
  52.     private final int launchYear;

  53.     /** Launch number. */
  54.     private final int launchNumber;

  55.     /** Launch piece. */
  56.     private final String launchPiece;

  57.     /** Element number. */
  58.     private final int elementNumber;

  59.     /** Revolution number at epoch. */
  60.     private final int revolutionNumberAtEpoch;

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

  63.     /** Ballistic coefficient. */
  64.     private double bStar;

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

  87.     /** Build a new instance.
  88.      * <p>
  89.      * The template TLE is used as a model to {@link
  90.      * #createInitialOrbit() create initial orbit}. It defines the
  91.      * inertial frame, the central attraction coefficient, orbit type, satellite number,
  92.      * classification, .... and is also used together with the {@code positionScale} to
  93.      * convert from the {@link ParameterDriver#setNormalizedValue(double) normalized}
  94.      * parameters used by the callers of this builder to the real orbital parameters.
  95.      * </p>
  96.      * @param templateTLE reference TLE from which real orbits will be built
  97.      * @param positionAngle position angle type to use
  98.      * @param positionScale scaling factor used for orbital parameters normalization
  99.      * (typically set to the expected standard deviation of the position)
  100.      * @param dataContext used to access frames and time scales.
  101.      * @since 10.1
  102.      */
  103.     public TLEPropagatorBuilder(final TLE templateTLE,
  104.                                 final PositionAngle positionAngle,
  105.                                 final double positionScale,
  106.                                 final DataContext dataContext) {
  107.         super(TLEPropagator.selectExtrapolator(templateTLE, dataContext.getFrames())
  108.                         .getInitialState().getOrbit(),
  109.               positionAngle, positionScale, false,
  110.               Propagator.getDefaultLaw(dataContext.getFrames()));
  111.         this.satelliteNumber         = templateTLE.getSatelliteNumber();
  112.         this.classification          = templateTLE.getClassification();
  113.         this.launchYear              = templateTLE.getLaunchYear();
  114.         this.launchNumber            = templateTLE.getLaunchNumber();
  115.         this.launchPiece             = templateTLE.getLaunchPiece();
  116.         this.elementNumber           = templateTLE.getElementNumber();
  117.         this.revolutionNumberAtEpoch = templateTLE.getRevolutionNumberAtEpoch();
  118.         this.bStar                   = 0.0;
  119.         this.dataContext = dataContext;
  120.         try {
  121.             final ParameterDriver driver = new ParameterDriver(B_STAR, bStar, B_STAR_SCALE,
  122.                                                                Double.NEGATIVE_INFINITY,
  123.                                                                Double.POSITIVE_INFINITY);
  124.             driver.addObserver(new ParameterObserver() {
  125.                 /** {@inheritDoc} */
  126.                 @Override
  127.                 public void valueChanged(final double previousValue, final ParameterDriver driver) {
  128.                     TLEPropagatorBuilder.this.bStar = driver.getValue();
  129.                 }
  130.             });
  131.             addSupportedParameter(driver);
  132.         } catch (OrekitException oe) {
  133.             // this should never happen
  134.             throw new OrekitInternalError(oe);
  135.         }

  136.     }

  137.     /** {@inheritDoc} */
  138.     public Propagator buildPropagator(final double[] normalizedParameters) {

  139.         // create the orbit
  140.         setParameters(normalizedParameters);
  141.         final Orbit orbit = createInitialOrbit();

  142.         // we really need a Keplerian orbit type
  143.         final KeplerianOrbit kep = (KeplerianOrbit) OrbitType.KEPLERIAN.convertType(orbit);

  144.         final TLE tle = new TLE(satelliteNumber, classification, launchYear, launchNumber, launchPiece,
  145.                                 TLE.DEFAULT, elementNumber, orbit.getDate(),
  146.                                 kep.getKeplerianMeanMotion(), 0.0, 0.0,
  147.                                 kep.getE(), MathUtils.normalizeAngle(orbit.getI(), FastMath.PI),
  148.                                 MathUtils.normalizeAngle(kep.getPerigeeArgument(), FastMath.PI),
  149.                                 MathUtils.normalizeAngle(kep.getRightAscensionOfAscendingNode(), FastMath.PI),
  150.                                 MathUtils.normalizeAngle(kep.getMeanAnomaly(), FastMath.PI),
  151.                                 revolutionNumberAtEpoch, bStar,
  152.                                 dataContext.getTimeScales().getUTC());

  153.         return TLEPropagator.selectExtrapolator(
  154.                 tle,
  155.                 getAttitudeProvider(),
  156.                 Propagator.DEFAULT_MASS,
  157.                 dataContext.getFrames().getTEME());
  158.     }

  159. }