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.gnss.attitude;
18  
19  import org.junit.jupiter.api.Test;
20  
21  
22  class GPSBlockIIATest extends AbstractGNSSAttitudeProviderTest {
23  
24      @Test
25      void testPatchedLargeNegativeBeta() {
26          doTestAxes("patched-eclips/beta-large-negative-BLOCK-IIA.txt", 6.3e-15, 1.1e-15, false);
27      }
28  
29      @Test
30      void testPatchedSmallNegativeBeta() {
31          doTestAxes("patched-eclips/beta-small-negative-BLOCK-IIA.txt", 5.1e-6, 1.2e-15, false);
32      }
33  
34      @Test
35      void testPatchedCrossingBeta() {
36          doTestAxes("patched-eclips/beta-crossing-BLOCK-IIA.txt", 5.2e-4, 8.3e-16, false);
37      }
38  
39      @Test
40      void testPatchedSmallPositiveBeta() {
41          doTestAxes("patched-eclips/beta-small-positive-BLOCK-IIA.txt", 1.1e-5, 1.1e-15, false);
42      }
43  
44      @Test
45      void testPatchedLargePositiveBeta() {
46          doTestAxes("patched-eclips/beta-large-positive-BLOCK-IIA.txt", 7.2e-15, 8.8e-16, false);
47      }
48  
49      @Test
50      void testOriginalLargeNegativeBeta() {
51          doTestAxes("original-eclips/beta-large-negative-BLOCK-IIA.txt", 6.3e-15, 1.1e-15, false);
52      }
53  
54      @Test
55      void testOriginalSmallNegativeBeta() {
56          doTestAxes("original-eclips/beta-small-negative-BLOCK-IIA.txt", 1.2e-3, 1.2e-15, false);
57      }
58  
59      @Test
60      void testOriginalCrossingBeta() {
61          // the very high threshold (2.13 radians) is due to a probable bug in original eclips
62          // the output of the routine is limited to the x-sat vector, the yaw angle itself
63          // is not output. However, in some cases the x-sat vector is not normalized at all.
64          // looking in the reference data file original-eclips/beta-crossing-BLOCK-IIA.txt,
65          // one can see that the axis at line 9 is about (-11.3028, -4.4295, -8.8996). The
66          // yaw angle extracted from this wrong vector and written as the last field in the
67          // same line reads 86.4797°, whereas Orekit value is 21.2256°. However, looking
68          // at the log from the original routine, we get:
69          // S           8   494903.73200000002        179.46493246830718        22.444691559239963 ...
70          // so we see that the yaw value is 22.4447°, very close to Orekit value.
71          // As the testOriginal...() series of tests explicitly do *not* patch the original routine
72          // at all, it was not possible to output the internal phi variable to write reference
73          // data properly. We also decided to not edit the file to set the correct angle value,
74          // as this would imply cheating on the reference
75          // This point however does not explain the 2.13 radians error. The 2.13 radians comes
76          // from the following point. Here, the original eclips considers the turn has already
77          // converged and it jump backs to nominal attitude. The reason is another probable
78          // bug in original eclips (which was addressed by our patch number 04). As the Sun
79          // crosses plane, the sign of beta changes and the sign of nominal yaw changes. However,
80          // the sign of the *linear* yaw is normalized according to the initial beta (betaini),
81          // not to the current beta. Near the end of the computation, a test (PHI/YANGLE).LT.0.d0
82          // fails and the attitude is set back to nominal, despite it should not (the yaw angle
83          // should be about 58.4° and jumps directly to 180.5°).
84          // As a conclusion, we consider here that the reference output is wrong and that
85          // Orekit behavior is correct, so we increased the threshold so the test pass,
86          // and wrote this big comment to explain the situation
87          doTestAxes("original-eclips/beta-crossing-BLOCK-IIA.txt", 2.13, 8.3e-16, false);
88      }
89  
90      @Test
91      void testOriginalSmallPositiveBeta() {
92          doTestAxes("original-eclips/beta-small-positive-BLOCK-IIA.txt", 1.2e-3, 1.1e-15, false);
93      }
94  
95      @Test
96      void testOriginalLargePositiveBeta() {
97          doTestAxes("original-eclips/beta-large-positive-BLOCK-IIA.txt", 7.2e-15, 8.8e-16, false);
98      }
99  
100 }