1   /* Copyright 2022-2026 Romain Serra
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.signal;
18  
19  import org.hipparchus.geometry.euclidean.threed.Vector3D;
20  import org.hipparchus.optim.ConvergenceChecker;
21  import org.orekit.frames.Frame;
22  import org.orekit.time.AbsoluteDate;
23  import org.orekit.utils.PVCoordinatesProvider;
24  
25  /**
26   * Class for computing signal time of travel with an adjustable receiver and fixed emitter's position.
27   * The delay is calculated via a fixed-point algorithm with customizable settings (even enabling instantaneous transmission).
28   * Note that a couple of iterations are usually enough for Earth orbits.
29   * @since 14.0
30   * @author Romain Serra
31   */
32  public class AdjustableReceiverSignalTimer extends AbstractSignalTravelTime {
33  
34      /** Position/velocity provider of receiver. */
35      private final PVCoordinatesProvider adjustableReceiverPVProvider;
36  
37      /**
38       * Constructor.
39       * @param adjustableReceiverPVProvider adjustable receiver
40       */
41      public AdjustableReceiverSignalTimer(final PVCoordinatesProvider adjustableReceiverPVProvider) {
42          this(adjustableReceiverPVProvider, getDefaultConvergenceChecker());
43      }
44  
45      /**
46       * Constructor.
47       * @param adjustableReceiverPVProvider adjustable receiver
48       * @param checker convergence checker for fixed-point algorithm
49       */
50      public AdjustableReceiverSignalTimer(final PVCoordinatesProvider adjustableReceiverPVProvider,
51                                           final ConvergenceChecker<Double> checker) {
52          super(checker);
53          this.adjustableReceiverPVProvider = adjustableReceiverPVProvider;
54      }
55  
56      /** Compute signal reception condition on a link leg (typically downlink or uplink).
57       * @param emissionCondition signal emission conditions
58       * @param approxReceptionDate approximate reception date
59       * @return reception condition
60       */
61      public SignalReceptionCondition computeReceptionCondition(final SignalEmissionCondition emissionCondition,
62                                                                final AbsoluteDate approxReceptionDate) {
63          final double delay = computeDelay(emissionCondition, approxReceptionDate);
64          final AbsoluteDate receptionDate = approxReceptionDate.shiftedBy(delay);
65          final Frame frame = emissionCondition.referenceFrame();
66          return new SignalReceptionCondition(receptionDate, adjustableReceiverPVProvider.getPosition(receptionDate, frame), frame);
67      }
68  
69      /** Compute propagation delay on a link leg (typically downlink or uplink) without custom guess.
70       * @param emissionCondition signal emission conditions
71       * @return <em>positive</em> delay between signal emission and signal reception dates
72       */
73      public double computeDelay(final SignalEmissionCondition emissionCondition) {
74          final AbsoluteDate emissionDate = emissionCondition.emissionDate();
75          final Vector3D emitterPosition = emissionCondition.emitterPosition();
76          final Frame frame = emissionCondition.referenceFrame();
77          final Vector3D receiverPosition = adjustableReceiverPVProvider.getPosition(emissionDate, frame);
78          final double distance = receiverPosition.subtract(emitterPosition).getNorm2();
79          final AbsoluteDate approxReceptionDate = emissionDate.shiftedBy(distance * C_RECIPROCAL);
80          return computeDelay(emissionCondition, approxReceptionDate);
81      }
82  
83      /** Compute propagation delay on a link leg (typically downlink or uplink).
84       * @param emissionCondition signal emission conditions
85       * @param approxReceptionDate approximate reception date
86       * @return <em>positive</em> delay between signal emission and signal reception dates
87       */
88      public double computeDelay(final SignalEmissionCondition emissionCondition,
89                                 final AbsoluteDate approxReceptionDate) {
90          // initialize reception date search loop assuming the state is already correct
91          final double offset = approxReceptionDate.durationFrom(emissionCondition.emissionDate());
92  
93          return compute(adjustableReceiverPVProvider, offset, emissionCondition.emitterPosition(), approxReceptionDate,
94                  emissionCondition.referenceFrame());
95      }
96  
97      @Override
98      protected double computeShift(final double offset, final double delay) {
99          return delay - offset;
100     }
101 }