1 /* Copyright 2002-2021 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 import java.util.Collections;
21 import java.util.HashMap;
22 import java.util.Map;
23
24 import org.hipparchus.Field;
25 import org.hipparchus.analysis.differentiation.Gradient;
26 import org.hipparchus.analysis.differentiation.GradientField;
27 import org.hipparchus.geometry.euclidean.threed.FieldVector3D;
28 import org.orekit.frames.FieldTransform;
29 import org.orekit.propagation.SpacecraftState;
30 import org.orekit.time.AbsoluteDate;
31 import org.orekit.time.FieldAbsoluteDate;
32 import org.orekit.utils.Constants;
33 import org.orekit.utils.FieldPVCoordinates;
34 import org.orekit.utils.PVCoordinates;
35 import org.orekit.utils.ParameterDriver;
36 import org.orekit.utils.TimeStampedFieldPVCoordinates;
37 import org.orekit.utils.TimeStampedPVCoordinates;
38
39 /** Class modeling a turn-around range measurement using a primary ground station and a secondary ground station.
40 * <p>
41 * The measurement is considered to be a signal:
42 * - Emitted from the primary ground station
43 * - Reflected on the spacecraft
44 * - Reflected on the secondary ground station
45 * - Reflected on the spacecraft again
46 * - Received on the primary ground station
47 * Its value is the elapsed time between emission and reception
48 * divided by 2c were c is the speed of light.
49 * The motion of the stations and the spacecraft
50 * during the signal flight time are taken into account.
51 * The date of the measurement corresponds to the
52 * reception on ground of the reflected signal.
53 * </p>
54 * @author Thierry Ceolin
55 * @author Luc Maisonobe
56 * @author Maxime Journot
57 *
58 * @since 9.0
59 */
60 public class TurnAroundRange extends AbstractMeasurement<TurnAroundRange> {
61
62 /** Primary ground station from which measurement is performed. */
63 private final GroundStation primaryStation;
64
65 /** Secondary ground station reflecting the signal. */
66 private final GroundStation secondaryStation;
67
68 /** Simple constructor.
69 * @param primaryStation ground station from which measurement is performed
70 * @param secondaryStation ground station reflecting the signal
71 * @param date date of the measurement
72 * @param turnAroundRange observed value
73 * @param sigma theoretical standard deviation
74 * @param baseWeight base weight
75 * @param satellite satellite related to this measurement
76 * @since 9.3
77 */
78 public TurnAroundRange(final GroundStation primaryStation, final GroundStation secondaryStation,
79 final AbsoluteDate date, final double turnAroundRange,
80 final double sigma, final double baseWeight,
81 final ObservableSatellite satellite) {
82 super(date, turnAroundRange, sigma, baseWeight, Collections.singletonList(satellite));
83 addParameterDriver(primaryStation.getClockOffsetDriver());
84 addParameterDriver(primaryStation.getEastOffsetDriver());
85 addParameterDriver(primaryStation.getNorthOffsetDriver());
86 addParameterDriver(primaryStation.getZenithOffsetDriver());
87 addParameterDriver(primaryStation.getPrimeMeridianOffsetDriver());
88 addParameterDriver(primaryStation.getPrimeMeridianDriftDriver());
89 addParameterDriver(primaryStation.getPolarOffsetXDriver());
90 addParameterDriver(primaryStation.getPolarDriftXDriver());
91 addParameterDriver(primaryStation.getPolarOffsetYDriver());
92 addParameterDriver(primaryStation.getPolarDriftYDriver());
93 // the secondary station clock is not used at all, we ignore the corresponding parameter driver
94 addParameterDriver(secondaryStation.getEastOffsetDriver());
95 addParameterDriver(secondaryStation.getNorthOffsetDriver());
96 addParameterDriver(secondaryStation.getZenithOffsetDriver());
97 addParameterDriver(secondaryStation.getPrimeMeridianOffsetDriver());
98 addParameterDriver(secondaryStation.getPrimeMeridianDriftDriver());
99 addParameterDriver(secondaryStation.getPolarOffsetXDriver());
100 addParameterDriver(secondaryStation.getPolarDriftXDriver());
101 addParameterDriver(secondaryStation.getPolarOffsetYDriver());
102 addParameterDriver(secondaryStation.getPolarDriftYDriver());
103 this.primaryStation = primaryStation;
104 this.secondaryStation = secondaryStation;
105 }
106
107 /** Get the primary ground station from which measurement is performed.
108 * @return primary ground station from which measurement is performed
109 */
110 public GroundStation getPrimaryStation() {
111 return primaryStation;
112 }
113
114 /** Get the secondary ground station reflecting the signal.
115 * @return secondary ground station reflecting the signal
116 */
117 public GroundStation getSecondaryStation() {
118 return secondaryStation;
119 }
120
121 /** {@inheritDoc} */
122 @Override
123 protected EstimatedMeasurement<TurnAroundRange> theoreticalEvaluation(final int iteration, final int evaluation,
124 final SpacecraftState[] states) {
125
126 final SpacecraftState state = states[0];
127
128 // Turn around range derivatives are computed with respect to:
129 // - Spacecraft state in inertial frame
130 // - Primary station parameters
131 // - Secondary station parameters
132 // --------------------------
133 //
134 // - 0..2 - Position of the spacecraft in inertial frame
135 // - 3..5 - Velocity of the spacecraft in inertial frame
136 // - 6..n - stations' parameters (clock offset, station offsets, pole, prime meridian...)
137 int nbParams = 6;
138 final Map<String, Integer> indices = new HashMap<>();
139 for (ParameterDriver driver : getParametersDrivers()) {
140 // we have to check for duplicate keys because primary and secondary station share
141 // pole and prime meridian parameters names that must be considered
142 // as one set only (they are combined together by the estimation engine)
143 if (driver.isSelected() && !indices.containsKey(driver.getName())) {
144 indices.put(driver.getName(), nbParams++);
145 }
146 }
147 final Field<Gradient> field = GradientField.getField(nbParams);
148 final FieldVector3D<Gradient> zero = FieldVector3D.getZero(field);
149
150 // Place the gradient in a time-stamped PV
151 final TimeStampedFieldPVCoordinates<Gradient> pvaDS = getCoordinates(state, 0, nbParams);
152
153 // The path of the signal is divided in two legs.
154 // Leg1: Emission from primary station to satellite in primaryTauU seconds
155 // + Reflection from satellite to secondary station in secondaryTauD seconds
156 // Leg2: Reflection from secondary station to satellite in secondaryTauU seconds
157 // + Reflection from satellite to primary station in primaryTaudD seconds
158 // The measurement is considered to be time stamped at reception on ground
159 // by the primary station. All times are therefore computed as backward offsets
160 // with respect to this reception time.
161 //
162 // Two intermediate spacecraft states are defined:
163 // - transitStateLeg2: State of the satellite when it bounced back the signal
164 // from secondary station to primary station during the 2nd leg
165 // - transitStateLeg1: State of the satellite when it bounced back the signal
166 // from primary station to secondary station during the 1st leg
167
168 // Compute propagation time for the 2nd leg of the signal path
169 // --
170
171 // Time difference between t (date of the measurement) and t' (date tagged in spacecraft state)
172 // (if state has already been set up to pre-compensate propagation delay,
173 // we will have delta = primaryTauD + secondaryTauU)
174 final double delta = getDate().durationFrom(state.getDate());
175
176 // transform between primary station topocentric frame (east-north-zenith) and inertial frame expressed as gradients
177 final FieldTransform<Gradient> primaryToInert =
178 primaryStation.getOffsetToInertial(state.getFrame(), getDate(), nbParams, indices);
179 final FieldAbsoluteDate<Gradient> measurementDateDS = primaryToInert.getFieldDate();
180
181 // Primary station PV in inertial frame at measurement date
182 final TimeStampedFieldPVCoordinates<Gradient> primaryArrival =
183 primaryToInert.transformPVCoordinates(new TimeStampedFieldPVCoordinates<>(measurementDateDS,
184 zero, zero, zero));
185
186 // Compute propagation times
187 final Gradient primaryTauD = signalTimeOfFlight(pvaDS, primaryArrival.getPosition(), measurementDateDS);
188
189 // Elapsed time between state date t' and signal arrival to the transit state of the 2nd leg
190 final Gradient dtLeg2 = primaryTauD.negate().add(delta);
191
192 // Transit state where the satellite reflected the signal from secondary to primary station
193 final SpacecraftState transitStateLeg2 = state.shiftedBy(dtLeg2.getValue());
194
195 // Transit state pv of leg2 (re)computed with gradient
196 final TimeStampedFieldPVCoordinates<Gradient> transitStateLeg2PV = pvaDS.shiftedBy(dtLeg2);
197
198 // transform between secondary station topocentric frame (east-north-zenith) and inertial frame expressed as gradients
199 // The components of secondary station's position in offset frame are the 3 last derivative parameters
200 final FieldAbsoluteDate<Gradient> approxReboundDate = measurementDateDS.shiftedBy(-delta);
201 final FieldTransform<Gradient> secondaryToInertApprox =
202 secondaryStation.getOffsetToInertial(state.getFrame(), approxReboundDate, nbParams, indices);
203
204 // Secondary station PV in inertial frame at approximate rebound date on secondary station
205 final TimeStampedFieldPVCoordinates<Gradient> QSecondaryApprox =
206 secondaryToInertApprox.transformPVCoordinates(new TimeStampedFieldPVCoordinates<>(approxReboundDate,
207 zero, zero, zero));
208
209 // Uplink time of flight from secondary station to transit state of leg2
210 final Gradient secondaryTauU = signalTimeOfFlight(QSecondaryApprox,
211 transitStateLeg2PV.getPosition(),
212 transitStateLeg2PV.getDate());
213
214 // Total time of flight for leg 2
215 final Gradient tauLeg2 = primaryTauD.add(secondaryTauU);
216
217 // Compute propagation time for the 1st leg of the signal path
218 // --
219
220 // Absolute date of rebound of the signal to secondary station
221 final FieldAbsoluteDate<Gradient> reboundDateDS = measurementDateDS.shiftedBy(tauLeg2.negate());
222 final FieldTransform<Gradient> secondaryToInert =
223 secondaryStation.getOffsetToInertial(state.getFrame(), reboundDateDS, nbParams, indices);
224
225 // Secondary station PV in inertial frame at rebound date on secondary station
226 final TimeStampedFieldPVCoordinates<Gradient> secondaryRebound =
227 secondaryToInert.transformPVCoordinates(new TimeStampedFieldPVCoordinates<>(reboundDateDS,
228 FieldPVCoordinates.getZero(field)));
229
230 // Downlink time of flight from transitStateLeg1 to secondary station at rebound date
231 final Gradient secondaryTauD = signalTimeOfFlight(transitStateLeg2PV,
232 secondaryRebound.getPosition(),
233 reboundDateDS);
234
235
236 // Elapsed time between state date t' and signal arrival to the transit state of the 1st leg
237 final Gradient dtLeg1 = dtLeg2.subtract(secondaryTauU).subtract(secondaryTauD);
238
239 // Transit state pv of leg2 (re)computed with gradients
240 final TimeStampedFieldPVCoordinates<Gradient> transitStateLeg1PV = pvaDS.shiftedBy(dtLeg1);
241
242 // transform between primary station topocentric frame (east-north-zenith) and inertial frame expressed as gradients
243 // The components of primary station's position in offset frame are the 3 third derivative parameters
244 final FieldAbsoluteDate<Gradient> approxEmissionDate =
245 measurementDateDS.shiftedBy(-2 * (secondaryTauU.getValue() + primaryTauD.getValue()));
246 final FieldTransform<Gradient> primaryToInertApprox =
247 primaryStation.getOffsetToInertial(state.getFrame(), approxEmissionDate, nbParams, indices);
248
249 // Primary station PV in inertial frame at approximate emission date
250 final TimeStampedFieldPVCoordinates<Gradient> QPrimaryApprox =
251 primaryToInertApprox.transformPVCoordinates(new TimeStampedFieldPVCoordinates<>(approxEmissionDate,
252 zero, zero, zero));
253
254 // Uplink time of flight from primary station to transit state of leg1
255 final Gradient primaryTauU = signalTimeOfFlight(QPrimaryApprox,
256 transitStateLeg1PV.getPosition(),
257 transitStateLeg1PV.getDate());
258
259 // Primary station PV in inertial frame at exact emission date
260 final AbsoluteDate emissionDate = transitStateLeg1PV.getDate().toAbsoluteDate().shiftedBy(-primaryTauU.getValue());
261 final TimeStampedPVCoordinates primaryDeparture =
262 primaryToInertApprox.shiftedBy(emissionDate.durationFrom(primaryToInertApprox.getDate())).
263 transformPVCoordinates(new TimeStampedPVCoordinates(emissionDate, PVCoordinates.ZERO)).
264 toTimeStampedPVCoordinates();
265
266 // Total time of flight for leg 1
267 final Gradient tauLeg1 = secondaryTauD.add(primaryTauU);
268
269
270 // --
271 // Evaluate the turn-around range value and its derivatives
272 // --------------------------------------------------------
273
274 // The state we use to define the estimated measurement is a middle ground between the two transit states
275 // This is done to avoid calling "SpacecraftState.shiftedBy" function on long duration
276 // Thus we define the state at the date t" = date of rebound of the signal at the secondary station
277 // Or t" = t -primaryTauD -secondaryTauU
278 // The iterative process in the estimation ensures that, after several iterations, the date stamped in the
279 // state S in input of this function will be close to t"
280 // Therefore we will shift state S by:
281 // - +secondaryTauU to get transitStateLeg2
282 // - -secondaryTauD to get transitStateLeg1
283 final EstimatedMeasurement<TurnAroundRange> estimated =
284 new EstimatedMeasurement<>(this, iteration, evaluation,
285 new SpacecraftState[] {
286 transitStateLeg2.shiftedBy(-secondaryTauU.getValue())
287 },
288 new TimeStampedPVCoordinates[] {
289 primaryDeparture,
290 transitStateLeg1PV.toTimeStampedPVCoordinates(),
291 secondaryRebound.toTimeStampedPVCoordinates(),
292 transitStateLeg2.getPVCoordinates(),
293 primaryArrival.toTimeStampedPVCoordinates()
294 });
295
296 // Turn-around range value = Total time of flight for the 2 legs divided by 2 and multiplied by c
297 final double cOver2 = 0.5 * Constants.SPEED_OF_LIGHT;
298 final Gradient turnAroundRange = (tauLeg2.add(tauLeg1)).multiply(cOver2);
299 estimated.setEstimatedValue(turnAroundRange.getValue());
300
301 // Turn-around range partial derivatives with respect to state
302 final double[] derivatives = turnAroundRange.getGradient();
303 estimated.setStateDerivatives(0, Arrays.copyOfRange(derivatives, 0, 6));
304
305 // set partial derivatives with respect to parameters
306 // (beware element at index 0 is the value, not a derivative)
307 for (final ParameterDriver driver : getParametersDrivers()) {
308 final Integer index = indices.get(driver.getName());
309 if (index != null) {
310 estimated.setParameterDerivatives(driver, derivatives[index]);
311 }
312 }
313
314 return estimated;
315
316 }
317
318 }