TLEPropagatorBuilder.java

  1. /* Copyright 2002-2018 CS Systèmes d'Information
  2.  * Licensed to CS Systèmes d'Information (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.errors.OrekitException;
  21. import org.orekit.errors.OrekitInternalError;
  22. import org.orekit.orbits.KeplerianOrbit;
  23. import org.orekit.orbits.Orbit;
  24. import org.orekit.orbits.OrbitType;
  25. import org.orekit.orbits.PositionAngle;
  26. import org.orekit.propagation.Propagator;
  27. import org.orekit.propagation.analytical.tle.TLE;
  28. import org.orekit.propagation.analytical.tle.TLEPropagator;
  29. import org.orekit.utils.ParameterDriver;
  30. import org.orekit.utils.ParameterObserver;

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

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

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

  45.     /** Satellite number. */
  46.     private final int satelliteNumber;

  47.     /** Classification (U for unclassified). */
  48.     private final char classification;

  49.     /** Launch year (all digits). */
  50.     private final int launchYear;

  51.     /** Launch number. */
  52.     private final int launchNumber;

  53.     /** Launch piece. */
  54.     private final String launchPiece;

  55.     /** Element number. */
  56.     private final int elementNumber;

  57.     /** Revolution number at epoch. */
  58.     private final int revolutionNumberAtEpoch;

  59.     /** Ballistic coefficient. */
  60.     private double bStar;

  61.     /** Build a new instance.
  62.      * <p>
  63.      * The template TLE is used as a model to {@link
  64.      * #createInitialOrbit() create initial orbit}. It defines the
  65.      * inertial frame, the central attraction coefficient, orbit type, satellite number,
  66.      * classification, .... and is also used together with the {@code positionScale} to
  67.      * convert from the {@link ParameterDriver#setNormalizedValue(double) normalized}
  68.      * parameters used by the callers of this builder to the real orbital parameters.
  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.      * @throws OrekitException if the TEME frame cannot be set
  75.      * @since 7.1
  76.      */
  77.     public TLEPropagatorBuilder(final TLE templateTLE, final PositionAngle positionAngle,
  78.                                 final double positionScale)
  79.         throws OrekitException {
  80.         super(TLEPropagator.selectExtrapolator(templateTLE).getInitialState().getOrbit(),
  81.               positionAngle, positionScale, false);
  82.         this.satelliteNumber         = templateTLE.getSatelliteNumber();
  83.         this.classification          = templateTLE.getClassification();
  84.         this.launchYear              = templateTLE.getLaunchYear();
  85.         this.launchNumber            = templateTLE.getLaunchNumber();
  86.         this.launchPiece             = templateTLE.getLaunchPiece();
  87.         this.elementNumber           = templateTLE.getElementNumber();
  88.         this.revolutionNumberAtEpoch = templateTLE.getRevolutionNumberAtEpoch();
  89.         this.bStar                   = 0.0;
  90.         try {
  91.             final ParameterDriver driver = new ParameterDriver(B_STAR, bStar, B_STAR_SCALE,
  92.                                                                Double.NEGATIVE_INFINITY,
  93.                                                                Double.POSITIVE_INFINITY);
  94.             driver.addObserver(new ParameterObserver() {
  95.                 /** {@inheritDoc} */
  96.                 @Override
  97.                 public void valueChanged(final double previousValue, final ParameterDriver driver) {
  98.                     TLEPropagatorBuilder.this.bStar = driver.getValue();
  99.                 }
  100.             });
  101.             addSupportedParameter(driver);
  102.         } catch (OrekitException oe) {
  103.             // this should never happen
  104.             throw new OrekitInternalError(oe);
  105.         }

  106.     }

  107.     /** {@inheritDoc} */
  108.     public Propagator buildPropagator(final double[] normalizedParameters)
  109.         throws OrekitException {

  110.         // create the orbit
  111.         setParameters(normalizedParameters);
  112.         final Orbit orbit = createInitialOrbit();

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

  115.         final TLE tle = new TLE(satelliteNumber, classification, launchYear, launchNumber, launchPiece,
  116.                                 TLE.DEFAULT, elementNumber, orbit.getDate(),
  117.                                 kep.getKeplerianMeanMotion(), 0.0, 0.0,
  118.                                 kep.getE(), MathUtils.normalizeAngle(orbit.getI(), FastMath.PI),
  119.                                 MathUtils.normalizeAngle(kep.getPerigeeArgument(), FastMath.PI),
  120.                                 MathUtils.normalizeAngle(kep.getRightAscensionOfAscendingNode(), FastMath.PI),
  121.                                 MathUtils.normalizeAngle(kep.getMeanAnomaly(), FastMath.PI),
  122.                                 revolutionNumberAtEpoch, bStar);

  123.         return TLEPropagator.selectExtrapolator(tle);
  124.     }

  125. }