TLEPropagatorBuilder.java

  1. /* Copyright 2002-2016 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 java.util.Iterator;

  19. import org.apache.commons.math3.util.FastMath;
  20. import org.apache.commons.math3.util.MathUtils;
  21. import org.orekit.errors.OrekitException;
  22. import org.orekit.errors.OrekitIllegalArgumentException;
  23. import org.orekit.frames.FramesFactory;
  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.time.AbsoluteDate;

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

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

  39.     /** Satellite number. */
  40.     private final int satelliteNumber;

  41.     /** Classification (U for unclassified). */
  42.     private final char classification;

  43.     /** Launch year (all digits). */
  44.     private final int launchYear;

  45.     /** Launch number. */
  46.     private final int launchNumber;

  47.     /** Launch piece. */
  48.     private final String launchPiece;

  49.     /** Element number. */
  50.     private final int elementNumber;

  51.     /** Revolution number at epoch. */
  52.     private final int revolutionNumberAtEpoch;

  53.     /** Ballistic coefficient. */
  54.     private double bStar;

  55.     /** Build a new instance.
  56.      * @param satelliteNumber satellite number
  57.      * @param classification classification (U for unclassified)
  58.      * @param launchYear launch year (all digits)
  59.      * @param launchNumber launch number
  60.      * @param launchPiece launch piece
  61.      * @param elementNumber element number
  62.      * @param revolutionNumberAtEpoch revolution number at epoch
  63.      * @throws OrekitException if the TEME frame cannot be set
  64.      * @deprecated as of 7.1, replaced with {@link #TLEPropagatorBuilder(int,
  65.      * char, int, int, String, int, int, OrbitType, PositionAngle)}
  66.      */
  67.     @Deprecated
  68.     public TLEPropagatorBuilder(final int satelliteNumber,
  69.                                 final char classification,
  70.                                 final int launchYear,
  71.                                 final int launchNumber,
  72.                                 final String launchPiece,
  73.                                 final int elementNumber,
  74.                                 final int revolutionNumberAtEpoch)
  75.         throws OrekitException {
  76.         this(satelliteNumber, classification, launchYear, launchNumber, launchPiece,
  77.              elementNumber, revolutionNumberAtEpoch, OrbitType.CARTESIAN, PositionAngle.TRUE);
  78.     }

  79.     /** Build a new instance.
  80.      * @param satelliteNumber satellite number
  81.      * @param classification classification (U for unclassified)
  82.      * @param launchYear launch year (all digits)
  83.      * @param launchNumber launch number
  84.      * @param launchPiece launch piece
  85.      * @param elementNumber element number
  86.      * @param revolutionNumberAtEpoch revolution number at epoch
  87.      * @param orbitType orbit type to use
  88.      * @param positionAngle position angle type to use
  89.      * @throws OrekitException if the TEME frame cannot be set
  90.      * @since 7.1
  91.      */
  92.     public TLEPropagatorBuilder(final int satelliteNumber,
  93.                                 final char classification,
  94.                                 final int launchYear,
  95.                                 final int launchNumber,
  96.                                 final String launchPiece,
  97.                                 final int elementNumber,
  98.                                 final int revolutionNumberAtEpoch,
  99.                                 final OrbitType orbitType, final PositionAngle positionAngle)
  100.         throws OrekitException {
  101.         super(FramesFactory.getTEME(), TLEPropagator.getMU(), orbitType, positionAngle);
  102.         addSupportedParameter(B_STAR);
  103.         this.satelliteNumber         = satelliteNumber;
  104.         this.classification          = classification;
  105.         this.launchYear              = launchYear;
  106.         this.launchNumber            = launchNumber;
  107.         this.launchPiece             = launchPiece;
  108.         this.elementNumber           = elementNumber;
  109.         this.revolutionNumberAtEpoch = revolutionNumberAtEpoch;
  110.         this.bStar                   = 0.0;
  111.     }

  112.     /** {@inheritDoc} */
  113.     public Propagator buildPropagator(final AbsoluteDate date, final double[] parameters)
  114.         throws OrekitException {

  115.         // create the orbit
  116.         checkParameters(parameters);
  117.         final Orbit orb = createInitialOrbit(date, parameters);

  118.         // we really need a Keplerian orbit type
  119.         final KeplerianOrbit kep = (KeplerianOrbit) OrbitType.KEPLERIAN.convertType(orb);

  120.         final Iterator<String> freeItr = getFreeParameters().iterator();
  121.         for (int i = 6; i < parameters.length; i++) {
  122.             final String free = freeItr.next();
  123.             for (String available : getSupportedParameters()) {
  124.                 if (free.equals(available)) {
  125.                     setParameter(free, parameters[i]);
  126.                 }
  127.             }
  128.         }

  129.         final TLE tle = new TLE(satelliteNumber, classification, launchYear, launchNumber, launchPiece,
  130.                                 TLE.DEFAULT, elementNumber, date,
  131.                                 kep.getKeplerianMeanMotion(), 0.0, 0.0,
  132.                                 kep.getE(), MathUtils.normalizeAngle(orb.getI(), FastMath.PI),
  133.                                 MathUtils.normalizeAngle(kep.getPerigeeArgument(), FastMath.PI),
  134.                                 MathUtils.normalizeAngle(kep.getRightAscensionOfAscendingNode(), FastMath.PI),
  135.                                 MathUtils.normalizeAngle(kep.getMeanAnomaly(), FastMath.PI),
  136.                                 revolutionNumberAtEpoch, bStar);

  137.         return TLEPropagator.selectExtrapolator(tle);
  138.     }

  139.     /** {@inheritDoc} */
  140.     @Override
  141.     public double getParameter(final String name)
  142.         throws OrekitIllegalArgumentException {
  143.         if (B_STAR.equals(name)) {
  144.             return bStar;
  145.         } else {
  146.             return super.getParameter(name);
  147.         }
  148.     }

  149.     /** {@inheritDoc} */
  150.     @Override
  151.     public void setParameter(final String name, final double value)
  152.         throws OrekitIllegalArgumentException {
  153.         if (B_STAR.equals(name)) {
  154.             bStar = value;
  155.         } else {
  156.             super.setParameter(name, value);
  157.         }
  158.     }

  159. }