TleGenerationUtil.java

  1. /* Copyright 2002-2025 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.analytical.tle.generation;

  18. import org.hipparchus.CalculusFieldElement;
  19. import org.hipparchus.util.FastMath;
  20. import org.hipparchus.util.MathUtils;
  21. import org.orekit.orbits.FieldKeplerianOrbit;
  22. import org.orekit.orbits.KeplerianOrbit;
  23. import org.orekit.propagation.analytical.tle.FieldTLE;
  24. import org.orekit.propagation.analytical.tle.TLE;
  25. import org.orekit.time.AbsoluteDate;
  26. import org.orekit.time.FieldAbsoluteDate;
  27. import org.orekit.time.TimeScale;

  28. /**
  29.  * Utility class for TLE generation algorithm.
  30.  * @author Bryan Cazabonne
  31.  * @author Thomas Paulet
  32.  * @author Mark Rutten
  33.  */
  34. public final class TleGenerationUtil {

  35.     /** Private constructor.
  36.      * <p>This class is a utility class, it should neither have a public
  37.      * nor a default constructor. This private constructor prevents
  38.      * the compiler from generating one automatically.</p>
  39.      */
  40.     private TleGenerationUtil() {
  41.     }

  42.     /**
  43.      * Builds a new TLE from Keplerian parameters and a template for TLE data.
  44.      * @param keplerianOrbit the Keplerian parameters to build the TLE from
  45.      * @param templateTLE TLE used to get object identification
  46.      * @param bStar TLE B* parameter
  47.      * @param utc UTC scale
  48.      * @return TLE with template identification and new orbital parameters
  49.      */
  50.     public static TLE newTLE(final KeplerianOrbit keplerianOrbit, final TLE templateTLE,
  51.                              final double bStar, final TimeScale utc) {

  52.         // Keplerian parameters
  53.         final double meanMotion  = keplerianOrbit.getKeplerianMeanMotion();
  54.         final double e           = keplerianOrbit.getE();
  55.         final double i           = keplerianOrbit.getI();
  56.         final double raan        = keplerianOrbit.getRightAscensionOfAscendingNode();
  57.         final double pa          = keplerianOrbit.getPerigeeArgument();
  58.         final double meanAnomaly = keplerianOrbit.getMeanAnomaly();

  59.         // TLE epoch is state epoch
  60.         final AbsoluteDate epoch = keplerianOrbit.getDate();

  61.         // Identification
  62.         final int satelliteNumber = templateTLE.getSatelliteNumber();
  63.         final char classification = templateTLE.getClassification();
  64.         final int launchYear      = templateTLE.getLaunchYear();
  65.         final int launchNumber    = templateTLE.getLaunchNumber();
  66.         final String launchPiece  = templateTLE.getLaunchPiece();
  67.         final int ephemerisType   = templateTLE.getEphemerisType();
  68.         final int elementNumber   = templateTLE.getElementNumber();

  69.         // Updates revolutionNumberAtEpoch
  70.         final int revolutionNumberAtEpoch = templateTLE.getRevolutionNumberAtEpoch();
  71.         final double dt = epoch.durationFrom(templateTLE.getDate());
  72.         final int newRevolutionNumberAtEpoch = (int) (revolutionNumberAtEpoch + FastMath.floor((MathUtils.normalizeAngle(meanAnomaly, FastMath.PI) + dt * meanMotion) / (MathUtils.TWO_PI)));

  73.         // Gets Mean Motion derivatives
  74.         final double meanMotionFirstDerivative  = templateTLE.getMeanMotionFirstDerivative();
  75.         final double meanMotionSecondDerivative = templateTLE.getMeanMotionSecondDerivative();

  76.         // Returns the new TLE
  77.         return new TLE(satelliteNumber, classification, launchYear, launchNumber, launchPiece, ephemerisType,
  78.                        elementNumber, epoch, meanMotion, meanMotionFirstDerivative, meanMotionSecondDerivative,
  79.                        e, i, pa, raan, meanAnomaly, newRevolutionNumberAtEpoch, bStar, utc);

  80.     }

  81.     /**
  82.      * Builds a new TLE from Keplerian parameters and a template for TLE data.
  83.      * @param keplerianOrbit the Keplerian parameters to build the TLE from
  84.      * @param templateTLE TLE used to get object identification
  85.      * @param bStar TLE B* parameter
  86.      * @param utc UTC scale
  87.      * @param <T> type of the element
  88.      * @return TLE with template identification and new orbital parameters
  89.      */
  90.     public static <T extends CalculusFieldElement<T>> FieldTLE<T> newTLE(final FieldKeplerianOrbit<T> keplerianOrbit,
  91.                                                                          final FieldTLE<T> templateTLE, final T bStar,
  92.                                                                          final TimeScale utc) {

  93.         // Keplerian parameters
  94.         final T meanMotion  = keplerianOrbit.getKeplerianMeanMotion();
  95.         final T e           = keplerianOrbit.getE();
  96.         final T i           = keplerianOrbit.getI();
  97.         final T raan        = keplerianOrbit.getRightAscensionOfAscendingNode();
  98.         final T pa          = keplerianOrbit.getPerigeeArgument();
  99.         final T meanAnomaly = keplerianOrbit.getMeanAnomaly();

  100.         // TLE epoch is state epoch
  101.         final FieldAbsoluteDate<T> epoch = keplerianOrbit.getDate();

  102.         // Identification
  103.         final int satelliteNumber = templateTLE.getSatelliteNumber();
  104.         final char classification = templateTLE.getClassification();
  105.         final int launchYear      = templateTLE.getLaunchYear();
  106.         final int launchNumber    = templateTLE.getLaunchNumber();
  107.         final String launchPiece  = templateTLE.getLaunchPiece();
  108.         final int ephemerisType   = templateTLE.getEphemerisType();
  109.         final int elementNumber   = templateTLE.getElementNumber();

  110.         // Updates revolutionNumberAtEpoch
  111.         final int revolutionNumberAtEpoch = templateTLE.getRevolutionNumberAtEpoch();
  112.         final T dt = epoch.durationFrom(templateTLE.getDate());
  113.         final int newRevolutionNumberAtEpoch = (int) ((int) revolutionNumberAtEpoch + FastMath.floor(MathUtils.normalizeAngle(meanAnomaly, e.getPi()).add(dt.multiply(meanMotion)).divide(MathUtils.TWO_PI)).getReal());

  114.         // Gets Mean Motion derivatives
  115.         final T meanMotionFirstDerivative  = templateTLE.getMeanMotionFirstDerivative();
  116.         final T meanMotionSecondDerivative = templateTLE.getMeanMotionSecondDerivative();

  117.         // Returns the new TLE
  118.         return new FieldTLE<>(satelliteNumber, classification, launchYear, launchNumber, launchPiece, ephemerisType,
  119.                               elementNumber, epoch, meanMotion, meanMotionFirstDerivative, meanMotionSecondDerivative,
  120.                               e, i, pa, raan, meanAnomaly, newRevolutionNumberAtEpoch, bStar.getReal(), utc);

  121.     }

  122. }