1   /* Copyright 2002-2026 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;
18  
19  import java.util.ArrayList;
20  import java.util.List;
21  
22  import org.hipparchus.analysis.solvers.BracketingNthOrderBrentSolver;
23  import org.hipparchus.analysis.solvers.UnivariateSolver;
24  import org.hipparchus.geometry.euclidean.threed.Vector3D;
25  import org.orekit.frames.Frame;
26  import org.orekit.frames.Transform;
27  import org.orekit.propagation.SpacecraftState;
28  import org.orekit.propagation.sampling.OrekitFixedStepHandler;
29  import org.orekit.time.AbsoluteDate;
30  import org.orekit.utils.Constants;
31  
32  public abstract class MeasurementCreator implements OrekitFixedStepHandler {
33  
34      private final List<ObservedMeasurement<?>> measurements;
35  
36      protected MeasurementCreator() {
37          measurements = new ArrayList<>();
38      }
39  
40      public List<ObservedMeasurement<?>> getMeasurements() {
41          return measurements;
42      }
43  
44      @Override
45      public void init(final SpacecraftState s0, final AbsoluteDate t, final double step) {
46          measurements.clear();
47      }
48  
49      protected double solveDownlinkDelay(final Observer observer, final SpacecraftState currentState, final Vector3D meanPosition) {
50                  
51          final UnivariateSolver solver = new BracketingNthOrderBrentSolver(1.0e-12, 5);
52          final AbsoluteDate date = currentState.getDate();
53          final Frame frame = currentState.getFrame();
54          final Vector3D position = currentState.getPosition();
55  
56          final double delay  = solver.solve(1000, x -> {
57                  final Transform t = observer.getOffsetToInertial(frame, date.shiftedBy(x), true);
58                  final double d = Vector3D.distance(position, t.transformPosition(meanPosition));
59                  return d - x * Constants.SPEED_OF_LIGHT;
60              }, -1.0, 1.0);
61  
62          return delay;
63      }
64  
65  
66      protected double solveUplinkDelay(final Observer observer, final SpacecraftState currentState, final Vector3D meanPosition) {
67                  
68          final UnivariateSolver solver = new BracketingNthOrderBrentSolver(1.0e-12, 5);
69          final AbsoluteDate date = currentState.getDate();
70          final Frame frame = currentState.getFrame();
71          final Vector3D position = currentState.getPosition();
72  
73          final double delay  = solver.solve(1000, x -> {
74                  final Transform t = observer.getOffsetToInertial(frame, date.shiftedBy(-x), true);
75                  final double d = Vector3D.distance(position, t.transformPosition(meanPosition));
76                  return d - x * Constants.SPEED_OF_LIGHT;
77              }, -1.0, 1.0);
78  
79          return delay;
80      }
81  
82      protected void addMeasurement(final ObservedMeasurement<?> measurement) {
83          measurements.add(measurement);
84      }
85  
86  }