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;
18  
19  import java.util.Arrays;
20  
21  import org.hipparchus.analysis.differentiation.Gradient;
22  import org.hipparchus.geometry.euclidean.threed.FieldVector3D;
23  import org.hipparchus.geometry.euclidean.threed.Vector3D;
24  import org.orekit.frames.FieldTransform;
25  import org.orekit.frames.Transform;
26  import org.orekit.propagation.SpacecraftState;
27  import org.orekit.time.AbsoluteDate;
28  import org.orekit.time.FieldAbsoluteDate;
29  import org.orekit.utils.ParameterDriver;
30  import org.orekit.utils.TimeSpanMap.Span;
31  import org.orekit.utils.TimeStampedFieldPVCoordinates;
32  import org.orekit.utils.TimeStampedPVCoordinates;
33  
34  /** Class modeling a bistatic range rate measurement using
35   *  an emitter ground station and a receiver ground station.
36   * <p>
37   * The measurement is considered to be a signal:
38   * <ul>
39   * <li>Emitted from the emitter ground station</li>
40   * <li>Reflected on the spacecraft</li>
41   * <li>Received on the receiver ground station</li>
42   * </ul>
43   * The date of the measurement corresponds to the reception on ground of the reflected signal.
44   * The quantity measured at the receiver is the bistatic radial velocity as the sum of the radial
45   * velocities with respect to the two stations.
46   * <p>
47   * The motion of the stations and the spacecraft during the signal flight time are taken into account.
48   * </p><p>
49   * The Doppler measurement can be obtained by multiplying the velocity by (fe/c), where
50   * fe is the emission frequency.
51   * </p>
52   *
53   * @author Pascal Parraud
54   * @since 11.2
55   */
56  public class BistaticRangeRate extends GroundReceiverMeasurement<BistaticRangeRate> {
57  
58      /** Type of the measurement. */
59      public static final String MEASUREMENT_TYPE = "BistaticRangeRate";
60  
61      /** Emitter ground station. */
62      private final GroundStation emitter;
63  
64      /** Simple constructor.
65       * @param emitter emitter ground station
66       * @param receiver receiver ground station
67       * @param date date of the measurement
68       * @param rangeRate observed value, m/s
69       * @param sigma theoretical standard deviation
70       * @param baseWeight base weight
71       * @param satellite satellite related to this measurement
72       */
73      public BistaticRangeRate(final GroundStation emitter, final GroundStation receiver,
74                               final AbsoluteDate date, final double rangeRate, final double sigma,
75                               final double baseWeight, final ObservableSatellite satellite) {
76          super(receiver, true, date, rangeRate, sigma, baseWeight, satellite);
77  
78          // add parameter drivers for the emitter, clock offset is not used
79          addParameterDriver(emitter.getEastOffsetDriver());
80          addParameterDriver(emitter.getNorthOffsetDriver());
81          addParameterDriver(emitter.getZenithOffsetDriver());
82          addParameterDriver(emitter.getPrimeMeridianOffsetDriver());
83          addParameterDriver(emitter.getPrimeMeridianDriftDriver());
84          addParameterDriver(emitter.getPolarOffsetXDriver());
85          addParameterDriver(emitter.getPolarDriftXDriver());
86          addParameterDriver(emitter.getPolarOffsetYDriver());
87          addParameterDriver(emitter.getPolarDriftYDriver());
88  
89          this.emitter  = emitter;
90  
91      }
92  
93      /** Get the emitter ground station.
94       * @return emitter ground station
95       */
96      public GroundStation getEmitterStation() {
97          return emitter;
98      }
99  
100     /** Get the receiver ground station.
101      * @return receiver ground station
102      */
103     public GroundStation getReceiverStation() {
104         return getStation();
105     }
106 
107     /** {@inheritDoc} */
108     @Override
109     protected EstimatedMeasurementBase<BistaticRangeRate> theoreticalEvaluationWithoutDerivatives(final int iteration,
110                                                                                                   final int evaluation,
111                                                                                                   final SpacecraftState[] states) {
112         final GroundReceiverCommonParametersWithoutDerivatives common = computeCommonParametersWithout(states[0]);
113         final TimeStampedPVCoordinates transitPV = common.getTransitPV();
114         final AbsoluteDate transitDate = transitPV.getDate();
115 
116         // Approximate emitter location at transit time
117         final Transform emitterToInertial =
118                 getEmitterStation().getOffsetToInertial(common.getState().getFrame(), transitDate, true);
119         final TimeStampedPVCoordinates emitterApprox =
120                 emitterToInertial.transformPVCoordinates(new TimeStampedPVCoordinates(transitDate,
121                         Vector3D.ZERO, Vector3D.ZERO, Vector3D.ZERO));
122 
123         // Uplink time of flight from emitter station to transit state
124         final double tauU = signalTimeOfFlightAdjustableEmitter(emitterApprox, transitPV.getPosition(), transitDate,
125                                                                 common.getState().getFrame());
126 
127         // Secondary station PV in inertial frame at rebound date on secondary station
128         final TimeStampedPVCoordinates emitterPV = emitterApprox.shiftedBy(-tauU);
129 
130         // Prepare the evaluation
131         final EstimatedMeasurementBase<BistaticRangeRate> estimated =
132                 new EstimatedMeasurementBase<>(this,
133                         iteration, evaluation,
134                         new SpacecraftState[] {
135                             common.getTransitState()
136                         },
137                         new TimeStampedPVCoordinates[] {
138                             common.getStationDownlink(),
139                             transitPV,
140                             emitterPV
141                         });
142 
143         // Range-rate components
144         final Vector3D receiverDirection = common.getStationDownlink().getPosition()
145                 .subtract(transitPV.getPosition()).normalize();
146         final Vector3D emitterDirection = emitterPV.getPosition()
147                 .subtract(transitPV.getPosition()).normalize();
148 
149         final Vector3D receiverVelocity = common.getStationDownlink().getVelocity()
150                 .subtract(transitPV.getVelocity());
151         final Vector3D emitterVelocity = emitterPV.getVelocity()
152                 .subtract(transitPV.getVelocity());
153 
154         // range rate
155         final double rangeRate = Vector3D.dotProduct(receiverDirection, receiverVelocity) +
156                  Vector3D.dotProduct(emitterDirection, emitterVelocity);
157         estimated.setEstimatedValue(rangeRate);
158 
159         return estimated;
160 
161     }
162 
163     /** {@inheritDoc} */
164     @Override
165     protected EstimatedMeasurement<BistaticRangeRate> theoreticalEvaluation(final int iteration,
166                                                                             final int evaluation,
167                                                                             final SpacecraftState[] states) {
168 
169         final SpacecraftState state = states[0];
170 
171         // Bistatic range-rate derivatives are computed with respect to spacecraft state in inertial frame
172         // and station parameters
173         // ----------------------
174         //
175         // Parameters:
176         //  - 0..2 - Position of the spacecraft in inertial frame
177         //  - 3..5 - Velocity of the spacecraft in inertial frame
178         //  - 6..n - measurements parameters (clock offset, station offsets, pole, prime meridian, sat clock offset...)
179         final GroundReceiverCommonParametersWithDerivatives common = computeCommonParametersWithDerivatives(state);
180         final int nbParams = common.getTauD().getFreeParameters();
181         final TimeStampedFieldPVCoordinates<Gradient> transitPV = common.getTransitPV();
182         final FieldAbsoluteDate<Gradient> transitDate = transitPV.getDate();
183 
184         // Approximate emitter location (at transit time)
185         final FieldVector3D<Gradient> zero = FieldVector3D.getZero(common.getTauD().getField());
186         final FieldTransform<Gradient> emitterToInertial =
187                 getEmitterStation().getOffsetToInertial(state.getFrame(), transitDate, nbParams, common.getIndices());
188         final TimeStampedFieldPVCoordinates<Gradient> emitterApprox =
189                 emitterToInertial.transformPVCoordinates(new TimeStampedFieldPVCoordinates<>(transitDate,
190                         zero, zero, zero));
191 
192         // Uplink time of flight from emiiter to transit state
193         final Gradient tauU = signalTimeOfFlightAdjustableEmitter(emitterApprox, transitPV.getPosition(), transitPV.getDate(),
194                                                                   state.getFrame());
195 
196         // Emitter coordinates at transmit time
197         final TimeStampedFieldPVCoordinates<Gradient> emitterPV = emitterApprox.shiftedBy(tauU.negate());
198 
199         // Prepare the evaluation
200         final EstimatedMeasurement<BistaticRangeRate> estimated = new EstimatedMeasurement<>(this,
201                 iteration, evaluation,
202                 new SpacecraftState[] {
203                         common.getTransitState()
204                 },
205                 new TimeStampedPVCoordinates[] {
206                         common.getStationDownlink().toTimeStampedPVCoordinates(),
207                         common.getTransitPV().toTimeStampedPVCoordinates(),
208                         emitterPV.toTimeStampedPVCoordinates()
209                 });
210 
211         // Range-rate components
212         final FieldVector3D<Gradient> receiverDirection = common.getStationDownlink().getPosition()
213                 .subtract(transitPV.getPosition()).normalize();
214         final FieldVector3D<Gradient> emitterDirection = emitterPV.getPosition()
215                 .subtract(transitPV.getPosition()).normalize();
216 
217         final FieldVector3D<Gradient> receiverVelocity = common.getStationDownlink().getVelocity()
218                 .subtract(transitPV.getVelocity());
219         final FieldVector3D<Gradient> emitterVelocity = emitterPV.getVelocity()
220                 .subtract(transitPV.getVelocity());
221 
222         // range rate
223         final Gradient rangeRate = FieldVector3D.dotProduct(receiverDirection, receiverVelocity)
224                 .add(FieldVector3D.dotProduct(emitterDirection, emitterVelocity));
225         estimated.setEstimatedValue(rangeRate.getValue());
226 
227         // Range first order derivatives with respect to state
228         final double[] derivatives = rangeRate.getGradient();
229         estimated.setStateDerivatives(0, Arrays.copyOfRange(derivatives, 0, 6));
230 
231         // Set first order derivatives with respect to parameters
232         for (final ParameterDriver driver : getParametersDrivers()) {
233             for (Span<String> span = driver.getNamesSpanMap().getFirstSpan(); span != null; span = span.next()) {
234                 final Integer index = common.getIndices().get(span.getData());
235                 if (index != null) {
236                     estimated.setParameterDerivatives(driver, span.getStart(), derivatives[index]);
237                 }
238             }
239         }
240 
241         return estimated;
242 
243     }
244 
245 }