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.conversion;
18  
19  import org.junit.jupiter.api.Assertions;
20  import org.junit.jupiter.api.BeforeEach;
21  import org.junit.jupiter.api.Test;
22  import org.orekit.Utils;
23  import org.orekit.errors.OrekitException;
24  import org.orekit.errors.OrekitMessages;
25  import org.orekit.orbits.PositionAngleType;
26  import org.orekit.propagation.analytical.tle.TLE;
27  import org.orekit.propagation.analytical.tle.TLEPropagator;
28  import org.orekit.propagation.analytical.tle.generation.FixedPointTleGenerationAlgorithm;
29  import org.orekit.utils.ParameterDriver;
30  
31  public class TLEConverterTest {
32  
33      @Test
34      public void testDeselectOrbitals() {
35  
36          final TLE tle = new TLE("1 27508U 02040A   12021.25695307 -.00000113  00000-0  10000-3 0  7326",
37                                  "2 27508   0.0571 356.7800 0005033 344.4621 218.7816  1.00271798 34501");
38  
39          TLEPropagatorBuilder builder = new TLEPropagatorBuilder(tle, PositionAngleType.MEAN, 1.0,
40                                                                  new FixedPointTleGenerationAlgorithm());
41          for (ParameterDriver driver : builder.getOrbitalParametersDrivers().getDrivers()) {
42              Assertions.assertTrue(driver.isSelected());
43          }
44          builder.deselectDynamicParameters();
45          for (ParameterDriver driver : builder.getOrbitalParametersDrivers().getDrivers()) {
46              Assertions.assertFalse(driver.isSelected());
47          }
48      }
49  
50      @Test
51      public void testIssue859() {
52  
53          // INTELSAT 25 TLE taken from Celestrak the 2021-11-24T07:45:00.000
54          // Because the satellite eccentricity and inclination are closed to zero, this satellite
55          // reach convergence issues when converting the spacecraft's state to TLE.
56          final TLE tle = new TLE("1 33153U 08034A   21327.46310733 -.00000207  00000+0  00000+0 0  9990",
57                                  "2 33153   0.0042  20.7353 0003042 213.9370 323.2156  1.00270917 48929");
58  
59          // Verify convergence issue
60          final TLEPropagatorBuilder propagatorBuilderError = new TLEPropagatorBuilder(tle, PositionAngleType.MEAN, 1.,
61                                                                                       new FixedPointTleGenerationAlgorithm());
62          try {
63              propagatorBuilderError.buildPropagator();
64          } catch (OrekitException oe) {
65              System.out.println(oe.getMessage());
66              Assertions.assertEquals(OrekitMessages.UNABLE_TO_COMPUTE_MEAN_PARAMETERS, oe.getSpecifier());
67          }
68  
69          // Now try using different convergence threshold
70          FixedPointTleGenerationAlgorithm algorithm =
71                          new FixedPointTleGenerationAlgorithm(FixedPointTleGenerationAlgorithm.EPSILON_DEFAULT,
72                                                               1000, 0.5);
73          final TLEPropagatorBuilder propagatorBuilder = new TLEPropagatorBuilder(tle, PositionAngleType.MEAN, 1., algorithm);
74          final TLEPropagator propagator = propagatorBuilder.buildPropagator(propagatorBuilderError.getSelectedNormalizedParameters());
75          final TLE newTLE = propagator.getTLE();
76  
77          // Verify
78          Assertions.assertEquals(0.0, newTLE.getDate().durationFrom(tle.getDate()), Utils.epsilonTest);
79  
80      }
81  
82      @BeforeEach
83      public void setUp() {
84          Utils.setDataRoot("regular-data");
85      }
86  
87  }