TDOA.java

  1. /* Copyright 2002-2022 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. import java.util.Arrays;
  19. import java.util.Collections;
  20. import java.util.HashMap;
  21. import java.util.Map;

  22. import org.hipparchus.analysis.differentiation.Gradient;
  23. import org.hipparchus.analysis.differentiation.GradientField;
  24. import org.hipparchus.geometry.euclidean.threed.FieldVector3D;
  25. import org.hipparchus.util.FastMath;
  26. import org.orekit.frames.FieldTransform;
  27. import org.orekit.propagation.SpacecraftState;
  28. import org.orekit.time.AbsoluteDate;
  29. import org.orekit.time.FieldAbsoluteDate;
  30. import org.orekit.utils.Constants;
  31. import org.orekit.utils.ParameterDriver;
  32. import org.orekit.utils.TimeStampedFieldPVCoordinates;
  33. import org.orekit.utils.TimeStampedPVCoordinates;

  34. /** Class modeling a Time Difference of Arrival measurement with a satellite as emitter
  35.  * and two ground stations as receivers.
  36.  * <p>
  37.  * TDOA measures the difference in signal arrival time between the emitter and receivers,
  38.  * corresponding to a difference in ranges from the two receivers to the emitter.
  39.  * </p><p>
  40.  * The date of the measurement corresponds to the reception of the signal by the prime station.
  41.  * The measurement corresponds to the date of the measurement minus
  42.  * the date of reception of the signal by the second station:
  43.  * <code>tdoa = tr<sub>1</sub> - tr<sub>2</sub></code>
  44.  * </p><p>
  45.  * The motion of the stations and the satellite during the signal flight time are taken into account.
  46.  * </p>
  47.  * @author Pascal Parraud
  48.  * @since 11.2
  49.  */
  50. public class TDOA extends AbstractMeasurement<TDOA> {

  51.     /** Prime ground station, the one that gives the date of the measurement. */
  52.     private final GroundStation primeStation;

  53.     /** Second ground station, the one that gives the measurement, i.e. the delay. */
  54.     private final GroundStation secondStation;

  55.     /** Simple constructor.
  56.      * @param primeStation ground station that gives the date of the measurement
  57.      * @param secondStation ground station that gives the measurement
  58.      * @param date date of the measurement
  59.      * @param tdoa observed value (s)
  60.      * @param sigma theoretical standard deviation
  61.      * @param baseWeight base weight
  62.      * @param satellite satellite related to this measurement
  63.      */
  64.     public TDOA(final GroundStation primeStation, final GroundStation secondStation,
  65.                 final AbsoluteDate date, final double tdoa, final double sigma,
  66.                 final double baseWeight, final ObservableSatellite satellite) {
  67.         super(date, tdoa, sigma, baseWeight, Collections.singletonList(satellite));
  68.         // add parameter drivers for the primary station
  69.         addParameterDriver(primeStation.getClockOffsetDriver());
  70.         addParameterDriver(primeStation.getEastOffsetDriver());
  71.         addParameterDriver(primeStation.getNorthOffsetDriver());
  72.         addParameterDriver(primeStation.getZenithOffsetDriver());
  73.         addParameterDriver(primeStation.getPrimeMeridianOffsetDriver());
  74.         addParameterDriver(primeStation.getPrimeMeridianDriftDriver());
  75.         addParameterDriver(primeStation.getPolarOffsetXDriver());
  76.         addParameterDriver(primeStation.getPolarDriftXDriver());
  77.         addParameterDriver(primeStation.getPolarOffsetYDriver());
  78.         addParameterDriver(primeStation.getPolarDriftYDriver());
  79.         // add parameter drivers for the secondary station
  80.         addParameterDriver(secondStation.getClockOffsetDriver());
  81.         addParameterDriver(secondStation.getEastOffsetDriver());
  82.         addParameterDriver(secondStation.getNorthOffsetDriver());
  83.         addParameterDriver(secondStation.getZenithOffsetDriver());
  84.         addParameterDriver(secondStation.getPrimeMeridianOffsetDriver());
  85.         addParameterDriver(secondStation.getPrimeMeridianDriftDriver());
  86.         addParameterDriver(secondStation.getPolarOffsetXDriver());
  87.         addParameterDriver(secondStation.getPolarDriftXDriver());
  88.         addParameterDriver(secondStation.getPolarOffsetYDriver());
  89.         addParameterDriver(secondStation.getPolarDriftYDriver());
  90.         this.primeStation  = primeStation;
  91.         this.secondStation = secondStation;
  92.     }

  93.     /** Get the prime ground station, the one that gives the date of the measurement.
  94.      * @return prime ground station
  95.      */
  96.     public GroundStation getPrimeStation() {
  97.         return primeStation;
  98.     }

  99.     /** Get the second ground station, the one that gives the measurement.
  100.      * @return second ground station
  101.      */
  102.     public GroundStation getSecondStation() {
  103.         return secondStation;
  104.     }

  105.     /** {@inheritDoc} */
  106.     @Override
  107.     protected EstimatedMeasurement<TDOA> theoreticalEvaluation(final int iteration, final int evaluation,
  108.                                                                final SpacecraftState[] states) {

  109.         final SpacecraftState state = states[0];

  110.         // TDOA derivatives are computed with respect to:
  111.         // - Spacecraft state in inertial frame
  112.         // - Prime station parameters
  113.         // - Second station parameters
  114.         // --------------------------
  115.         //  - 0..2 - Position of the spacecraft in inertial frame
  116.         //  - 3..5 - Velocity of the spacecraft in inertial frame
  117.         //  - 6..n - stations' parameters (clock offset, station offsets, pole, prime meridian...)
  118.         int nbParams = 6;
  119.         final Map<String, Integer> indices = new HashMap<>();
  120.         for (ParameterDriver driver : getParametersDrivers()) {
  121.             // we have to check for duplicate keys because primary and secondary station share
  122.             // pole and prime meridian parameters names that must be considered
  123.             // as one set only (they are combined together by the estimation engine)
  124.             if (driver.isSelected() && !indices.containsKey(driver.getName())) {
  125.                 indices.put(driver.getName(), nbParams++);
  126.             }
  127.         }
  128.         final FieldVector3D<Gradient> zero = FieldVector3D.getZero(GradientField.getField(nbParams));

  129.         // coordinates of the spacecraft as a gradient
  130.         final TimeStampedFieldPVCoordinates<Gradient> pvaG = getCoordinates(state, 0, nbParams);

  131.         // transform between prime station frame and inertial frame
  132.         // at the real date of measurement, i.e. taking station clock offset into account
  133.         final FieldTransform<Gradient> primeToInert =
  134.                         primeStation.getOffsetToInertial(state.getFrame(), getDate(), nbParams, indices);
  135.         final FieldAbsoluteDate<Gradient> measurementDateG = primeToInert.getFieldDate();

  136.         // prime station PV in inertial frame at the real date of the measurement
  137.         final TimeStampedFieldPVCoordinates<Gradient> primePV =
  138.                         primeToInert.transformPVCoordinates(new TimeStampedFieldPVCoordinates<>(measurementDateG,
  139.                                                                                                 zero, zero, zero));

  140.         // compute downlink delay from emitter to prime receiver
  141.         final Gradient tau1 = signalTimeOfFlight(pvaG, primePV.getPosition(), measurementDateG);

  142.         // elapsed time between state date and signal arrival to the prime receiver
  143.         final Gradient dtMtau1 = measurementDateG.durationFrom(state.getDate()).subtract(tau1);

  144.         // satellite state at signal emission
  145.         final SpacecraftState emitterState = state.shiftedBy(dtMtau1.getValue());

  146.         // satellite pv at signal emission (re)computed with gradient
  147.         final TimeStampedFieldPVCoordinates<Gradient> emitterPV = pvaG.shiftedBy(dtMtau1);

  148.         // second station PV in inertial frame at real date of signal reception
  149.         TimeStampedFieldPVCoordinates<Gradient> secondPV;
  150.         // initialize search loop of the reception date by second station
  151.         Gradient tau2 = tau1;
  152.         double delta;
  153.         int count = 0;
  154.         do {
  155.             final double previous = tau2.getValue();
  156.             // date of signal arrival on second receiver
  157.             final AbsoluteDate dateAt2 = emitterState.getDate().shiftedBy(previous);
  158.             // transform between second station frame and inertial frame
  159.             // at the date of signal arrival, taking clock offset into account
  160.             final FieldTransform<Gradient> secondToInert =
  161.                             secondStation.getOffsetToInertial(state.getFrame(), dateAt2,
  162.                                                               nbParams, indices);
  163.             // second receiver position in inertial frame at the real date of signal reception
  164.             secondPV = secondToInert.transformPVCoordinates(new TimeStampedFieldPVCoordinates<>(secondToInert.getFieldDate(),
  165.                                                                                                 zero, zero, zero));
  166.             // downlink delay from emitter to second receiver
  167.             tau2 = linkDelay(emitterPV.getPosition(), secondPV.getPosition());

  168.             // Change in the computed downlink delay
  169.             delta = FastMath.abs(tau2.getValue() - previous);
  170.         } while (count++ < 10 && delta >= 2 * FastMath.ulp(tau2.getValue()));

  171.         // The measured TDOA is (tau1 + clockOffset1) - (tau2 + clockOffset2)
  172.         final Gradient offset1 = primeStation.getClockOffsetDriver().getValue(nbParams, indices);
  173.         final Gradient offset2 = secondStation.getClockOffsetDriver().getValue(nbParams, indices);
  174.         final Gradient tdoaG   = tau1.add(offset1).subtract(tau2.add(offset2));
  175.         final double tdoa      = tdoaG.getValue();

  176.         // Evaluate the TDOA value and derivatives
  177.         // -------------------------------------------
  178.         final TimeStampedPVCoordinates pv1 = primePV.toTimeStampedPVCoordinates();
  179.         final TimeStampedPVCoordinates pv2 = secondPV.toTimeStampedPVCoordinates();
  180.         final EstimatedMeasurement<TDOA> estimated =
  181.                         new EstimatedMeasurement<>(this, iteration, evaluation,
  182.                                                    new SpacecraftState[] {
  183.                                                        emitterState
  184.                                                    },
  185.                                                    new TimeStampedPVCoordinates[] {
  186.                                                        emitterPV.toTimeStampedPVCoordinates(),
  187.                                                        tdoa > 0 ? pv2 : pv1,
  188.                                                        tdoa > 0 ? pv1 : pv2
  189.                                                    });

  190.         // set TDOA value
  191.         estimated.setEstimatedValue(tdoa);

  192.         // set partial derivatives with respect to state
  193.         final double[] derivatives = tdoaG.getGradient();
  194.         estimated.setStateDerivatives(0, Arrays.copyOfRange(derivatives, 0, 6));

  195.         // set partial derivatives with respect to parameters
  196.         for (final ParameterDriver driver : getParametersDrivers()) {
  197.             final Integer index = indices.get(driver.getName());
  198.             if (index != null) {
  199.                 estimated.setParameterDerivatives(driver, derivatives[index]);
  200.             }
  201.         }

  202.         return estimated;

  203.     }

  204.     /** Compute propagation delay on a link.
  205.      * @param emitter  the position of the emitter
  206.      * @param receiver the position of the receiver (same frame as emitter)
  207.      * @return the propagation delay
  208.      */
  209.     private Gradient linkDelay(final FieldVector3D<Gradient> emitter,
  210.                                final FieldVector3D<Gradient> receiver) {
  211.         return receiver.distance(emitter).divide(Constants.SPEED_OF_LIGHT);
  212.     }
  213. }