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.estimation.measurements.modifiers;
18  
19  import java.util.List;
20  
21  import org.hipparchus.geometry.euclidean.threed.Vector3D;
22  import org.junit.jupiter.api.Assertions;
23  import org.junit.jupiter.api.Test;
24  import org.orekit.attitudes.LofOffset;
25  import org.orekit.estimation.Context;
26  import org.orekit.estimation.EstimationTestUtils;
27  import org.orekit.estimation.measurements.EstimatedMeasurementBase;
28  import org.orekit.estimation.measurements.ObservedMeasurement;
29  import org.orekit.estimation.measurements.TurnAroundRange;
30  import org.orekit.estimation.measurements.TurnAroundRangeMeasurementCreator;
31  import org.orekit.frames.LOFType;
32  import org.orekit.orbits.OrbitType;
33  import org.orekit.orbits.PositionAngleType;
34  import org.orekit.propagation.Propagator;
35  import org.orekit.propagation.SpacecraftState;
36  import org.orekit.propagation.conversion.NumericalPropagatorBuilder;
37  
38  public class OnBoardAntennaTurnAroundRangeModifierTest {
39  
40      @Test
41      public void testPreliminary() {
42  
43          // this test does not check OnBoardAntennaTurnAroundRangeModifier at all,
44          // it just checks TurnAroundRangeMeasurementCreator behaves as necessary for the other test
45          // the *real* test is testEffect below
46          Context context = EstimationTestUtils.eccentricContext("regular-data:potential:tides");
47  
48          final NumericalPropagatorBuilder propagatorBuilder =
49                          context.createBuilder(OrbitType.KEPLERIAN, PositionAngleType.TRUE, true,
50                                                1.0e-6, 60.0, 0.001);
51          propagatorBuilder.setAttitudeProvider(new LofOffset(propagatorBuilder.getFrame(), LOFType.LVLH));
52  
53          // create perfect turn-around range measurements without antenna offset
54          final Propagator p1 = EstimationTestUtils.createPropagator(context.initialOrbit,
55                                                                             propagatorBuilder);
56          final List<ObservedMeasurement<?>> spacecraftCenteredMeasurements =
57                          EstimationTestUtils.createMeasurements(p1,
58                                                                 new TurnAroundRangeMeasurementCreator(context, Vector3D.ZERO),
59                                                                 1.0, 3.0, 300.0);
60  
61          // create perfect turn-around range measurements with antenna offset
62          final double xOffset = -2.5;
63          final Propagator p2 = EstimationTestUtils.createPropagator(context.initialOrbit,
64                                                                     propagatorBuilder);
65          final List<ObservedMeasurement<?>> antennaCenteredMeasurements =
66                          EstimationTestUtils.createMeasurements(p2,
67                                                                 new TurnAroundRangeMeasurementCreator(context, new Vector3D(xOffset, 0, 0)),
68                                                                 1.0, 3.0, 300.0);
69  
70          for (int i = 0; i < spacecraftCenteredMeasurements.size(); ++i) {
71              TurnAroundRange sr = (TurnAroundRange) spacecraftCenteredMeasurements.get(i);
72              TurnAroundRange ar = (TurnAroundRange) antennaCenteredMeasurements.get(i);
73              Assertions.assertEquals(0.0, sr.getDate().durationFrom(ar.getDate()), 2.0e-8);
74              Assertions.assertTrue(ar.getObservedValue()[0] - sr.getObservedValue()[0] >= 2.0 * xOffset);
75              Assertions.assertTrue(ar.getObservedValue()[0] - sr.getObservedValue()[0] <= 1.8 * xOffset);
76          }
77      }
78  
79      @Test
80      public void testEffect() {
81  
82          Context context = EstimationTestUtils.eccentricContext("regular-data:potential:tides");
83  
84          final NumericalPropagatorBuilder propagatorBuilder =
85                          context.createBuilder(OrbitType.KEPLERIAN, PositionAngleType.TRUE, true,
86                                                1.0e-6, 60.0, 0.001);
87          propagatorBuilder.setAttitudeProvider(new LofOffset(propagatorBuilder.getFrame(), LOFType.LVLH));
88  
89          // create perfect turn-around range measurements without antenna offset
90          final Propagator p1 = EstimationTestUtils.createPropagator(context.initialOrbit,
91                                                                             propagatorBuilder);
92          final List<ObservedMeasurement<?>> spacecraftCenteredMeasurements =
93                          EstimationTestUtils.createMeasurements(p1,
94                                                                 new TurnAroundRangeMeasurementCreator(context, Vector3D.ZERO),
95                                                                 1.0, 3.0, 300.0);
96  
97          // create perfect turn-around range measurements with antenna offset
98          final Vector3D apc = new Vector3D(-2.5,  0,  0);
99          final Propagator p2 = EstimationTestUtils.createPropagator(context.initialOrbit,
100                                                                    propagatorBuilder);
101         final List<ObservedMeasurement<?>> antennaCenteredMeasurements =
102                         EstimationTestUtils.createMeasurements(p2,
103                                                                new TurnAroundRangeMeasurementCreator(context, apc),
104                                                                1.0, 3.0, 300.0);
105 
106         final Propagator p3 = EstimationTestUtils.createPropagator(context.initialOrbit,
107                                                                    propagatorBuilder);
108 
109         OnBoardAntennaTurnAroundRangeModifier modifier = new OnBoardAntennaTurnAroundRangeModifier(apc);
110         for (int i = 0; i < spacecraftCenteredMeasurements.size(); ++i) {
111             TurnAroundRange sr = (TurnAroundRange) spacecraftCenteredMeasurements.get(i);
112             sr.addModifier(modifier);
113             EstimatedMeasurementBase<TurnAroundRange> estimated = sr.estimateWithoutDerivatives(new SpacecraftState[] { p3.propagate(sr.getDate()) });
114             TurnAroundRange ar = (TurnAroundRange) antennaCenteredMeasurements.get(i);
115             Assertions.assertEquals(0.0, sr.getDate().durationFrom(ar.getDate()), 2.0e-8);
116             Assertions.assertEquals(ar.getObservedValue()[0], estimated.getEstimatedValue()[0], 5.0e-7);
117             Assertions.assertEquals(1,
118                                     estimated.getAppliedEffects().entrySet().stream().
119                                     filter(e -> e.getKey().getEffectName().equals("mean phase center")).count());
120         }
121 
122     }
123 
124 }
125 
126