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.     /** Type of the measurement. */
  52.     public static final String MEASUREMENT_TYPE = "TDOA";

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

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

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

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

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

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

  111.         final SpacecraftState state = states[0];

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

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

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

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

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

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

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

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

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

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

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

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

  192.         // set TDOA value
  193.         estimated.setEstimatedValue(tdoa);

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

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

  204.         return estimated;

  205.     }

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