TDOA.java

  1. /* Copyright 2002-2023 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.HashMap;
  20. import java.util.Map;

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

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

  53.     /** Type of the measurement. */
  54.     public static final String MEASUREMENT_TYPE = "TDOA";

  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(primeStation, false, date, tdoa, sigma, baseWeight, satellite);

  70.         // add parameter drivers for the secondary station
  71.         addParameterDriver(secondStation.getClockOffsetDriver());
  72.         addParameterDriver(secondStation.getEastOffsetDriver());
  73.         addParameterDriver(secondStation.getNorthOffsetDriver());
  74.         addParameterDriver(secondStation.getZenithOffsetDriver());
  75.         addParameterDriver(secondStation.getPrimeMeridianOffsetDriver());
  76.         addParameterDriver(secondStation.getPrimeMeridianDriftDriver());
  77.         addParameterDriver(secondStation.getPolarOffsetXDriver());
  78.         addParameterDriver(secondStation.getPolarDriftXDriver());
  79.         addParameterDriver(secondStation.getPolarOffsetYDriver());
  80.         addParameterDriver(secondStation.getPolarDriftYDriver());
  81.         this.secondStation = secondStation;

  82.     }

  83.     /** Get the prime ground station, the one that gives the date of the measurement.
  84.      * @return prime ground station
  85.      */
  86.     public GroundStation getPrimeStation() {
  87.         return getStation();
  88.     }

  89.     /** Get the second ground station, the one that gives the measurement.
  90.      * @return second ground station
  91.      */
  92.     public GroundStation getSecondStation() {
  93.         return secondStation;
  94.     }

  95.     /** {@inheritDoc} */
  96.     @Override
  97.     protected EstimatedMeasurementBase<TDOA> theoreticalEvaluationWithoutDerivatives(final int iteration, final int evaluation,
  98.                                                                                      final SpacecraftState[] states) {

  99.         final SpacecraftState state = states[0];

  100.         // coordinates of the spacecraft
  101.         final TimeStampedPVCoordinates pva = state.getPVCoordinates();

  102.         // transform between prime station frame and inertial frame
  103.         // at the real date of measurement, i.e. taking station clock offset into account
  104.         final Transform primeToInert = getStation().getOffsetToInertial(state.getFrame(), getDate(), false);
  105.         final AbsoluteDate measurementDate = primeToInert.getDate();

  106.         // prime station PV in inertial frame at the real date of the measurement
  107.         final TimeStampedPVCoordinates primePV =
  108.                         primeToInert.transformPVCoordinates(new TimeStampedPVCoordinates(measurementDate,
  109.                                                                                          Vector3D.ZERO, Vector3D.ZERO, Vector3D.ZERO));

  110.         // compute downlink delay from emitter to prime receiver
  111.         final double tau1 = signalTimeOfFlight(pva, primePV.getPosition(), measurementDate);

  112.         // elapsed time between state date and signal arrival to the prime receiver
  113.         final double dtMtau1 = measurementDate.durationFrom(state.getDate()) - tau1;

  114.         // satellite state at signal emission
  115.         final SpacecraftState emitterState = state.shiftedBy(dtMtau1);

  116.         // satellite pv at signal emission (re)computed with gradient
  117.         final TimeStampedPVCoordinates emitterPV = pva.shiftedBy(dtMtau1);

  118.         // second station PV in inertial frame at real date of signal reception
  119.         TimeStampedPVCoordinates secondPV;
  120.         // initialize search loop of the reception date by second station
  121.         double tau2 = tau1;
  122.         double delta;
  123.         int count = 0;
  124.         do {
  125.             final double previous = tau2;
  126.             // date of signal arrival on second receiver
  127.             final AbsoluteDate dateAt2 = emitterState.getDate().shiftedBy(previous);
  128.             // transform between second station frame and inertial frame
  129.             // at the date of signal arrival, taking clock offset into account
  130.             final Transform secondToInert =
  131.                             secondStation.getOffsetToInertial(state.getFrame(), dateAt2, true);
  132.             // second receiver position in inertial frame at the real date of signal reception
  133.             secondPV = secondToInert.transformPVCoordinates(new TimeStampedPVCoordinates(secondToInert.getDate(),
  134.                                                                                          Vector3D.ZERO, Vector3D.ZERO, Vector3D.ZERO));
  135.             // downlink delay from emitter to second receiver
  136.             tau2 = linkDelay(emitterPV.getPosition(), secondPV.getPosition());

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

  140.         // The measured TDOA is (tau1 + clockOffset1) - (tau2 + clockOffset2)
  141.         final double offset1 = getStation().getClockOffsetDriver().getValue(emitterState.getDate());
  142.         final double offset2 = secondStation.getClockOffsetDriver().getValue(emitterState.getDate());
  143.         final double tdoa   = (tau1 + offset1) - (tau2 + offset2);

  144.         // Evaluate the TDOA value and derivatives
  145.         // -------------------------------------------
  146.         final EstimatedMeasurement<TDOA> estimated =
  147.                         new EstimatedMeasurement<>(this, iteration, evaluation,
  148.                                                    new SpacecraftState[] {
  149.                                                        emitterState
  150.                                                    },
  151.                                                    new TimeStampedPVCoordinates[] {
  152.                                                        emitterPV,
  153.                                                        tdoa > 0 ? secondPV : primePV,
  154.                                                        tdoa > 0 ? primePV : secondPV
  155.                                                    });

  156.         // set TDOA value
  157.         estimated.setEstimatedValue(tdoa);

  158.         return estimated;

  159.     }

  160.     /** {@inheritDoc} */
  161.     @Override
  162.     protected EstimatedMeasurement<TDOA> theoreticalEvaluation(final int iteration, final int evaluation,
  163.                                                                final SpacecraftState[] states) {

  164.         final SpacecraftState state = states[0];

  165.         // TDOA derivatives are computed with respect to:
  166.         // - Spacecraft state in inertial frame
  167.         // - Prime station parameters
  168.         // - Second station parameters
  169.         // --------------------------
  170.         //  - 0..2 - Position of the spacecraft in inertial frame
  171.         //  - 3..5 - Velocity of the spacecraft in inertial frame
  172.         //  - 6..n - stations' parameters (clock offset, station offsets, pole, prime meridian...)
  173.         int nbParams = 6;
  174.         final Map<String, Integer> indices = new HashMap<>();
  175.         for (ParameterDriver driver : getParametersDrivers()) {
  176.             // we have to check for duplicate keys because primary and secondary station share
  177.             // pole and prime meridian parameters names that must be considered
  178.             // as one set only (they are combined together by the estimation engine)
  179.             if (driver.isSelected()) {
  180.                 for (Span<String> span = driver.getNamesSpanMap().getFirstSpan(); span != null; span = span.next()) {

  181.                     if (!indices.containsKey(span.getData())) {
  182.                         indices.put(span.getData(), nbParams++);
  183.                     }
  184.                 }
  185.             }
  186.         }
  187.         final FieldVector3D<Gradient> zero = FieldVector3D.getZero(GradientField.getField(nbParams));

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

  190.         // transform between prime station frame and inertial frame
  191.         // at the real date of measurement, i.e. taking station clock offset into account
  192.         final FieldTransform<Gradient> primeToInert =
  193.                         getStation().getOffsetToInertial(state.getFrame(), getDate(), nbParams, indices);
  194.         final FieldAbsoluteDate<Gradient> measurementDateG = primeToInert.getFieldDate();

  195.         // prime station PV in inertial frame at the real date of the measurement
  196.         final TimeStampedFieldPVCoordinates<Gradient> primePV =
  197.                         primeToInert.transformPVCoordinates(new TimeStampedFieldPVCoordinates<>(measurementDateG,
  198.                                                                                                 zero, zero, zero));

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

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

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

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

  207.         // second station PV in inertial frame at real date of signal reception
  208.         TimeStampedFieldPVCoordinates<Gradient> secondPV;
  209.         // initialize search loop of the reception date by second station
  210.         Gradient tau2 = tau1;
  211.         double delta;
  212.         int count = 0;
  213.         do {
  214.             final double previous = tau2.getValue();
  215.             // date of signal arrival on second receiver
  216.             final AbsoluteDate dateAt2 = emitterState.getDate().shiftedBy(previous);
  217.             // transform between second station frame and inertial frame
  218.             // at the date of signal arrival, taking clock offset into account
  219.             final FieldTransform<Gradient> secondToInert =
  220.                             secondStation.getOffsetToInertial(state.getFrame(), dateAt2,
  221.                                                               nbParams, indices);
  222.             // second receiver position in inertial frame at the real date of signal reception
  223.             secondPV = secondToInert.transformPVCoordinates(new TimeStampedFieldPVCoordinates<>(secondToInert.getFieldDate(),
  224.                                                                                                 zero, zero, zero));
  225.             // downlink delay from emitter to second receiver
  226.             tau2 = linkDelay(emitterPV.getPosition(), secondPV.getPosition());

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

  230.         // The measured TDOA is (tau1 + clockOffset1) - (tau2 + clockOffset2)
  231.         final Gradient offset1 = getStation().getClockOffsetDriver().getValue(nbParams, indices, emitterState.getDate());
  232.         final Gradient offset2 = secondStation.getClockOffsetDriver().getValue(nbParams, indices, emitterState.getDate());
  233.         final Gradient tdoaG   = tau1.add(offset1).subtract(tau2.add(offset2));
  234.         final double tdoa      = tdoaG.getValue();

  235.         // Evaluate the TDOA value and derivatives
  236.         // -------------------------------------------
  237.         final TimeStampedPVCoordinates pv1 = primePV.toTimeStampedPVCoordinates();
  238.         final TimeStampedPVCoordinates pv2 = secondPV.toTimeStampedPVCoordinates();
  239.         final EstimatedMeasurement<TDOA> estimated =
  240.                         new EstimatedMeasurement<>(this, iteration, evaluation,
  241.                                                    new SpacecraftState[] {
  242.                                                        emitterState
  243.                                                    },
  244.                                                    new TimeStampedPVCoordinates[] {
  245.                                                        emitterPV.toTimeStampedPVCoordinates(),
  246.                                                        tdoa > 0 ? pv2 : pv1,
  247.                                                        tdoa > 0 ? pv1 : pv2
  248.                                                    });

  249.         // set TDOA value
  250.         estimated.setEstimatedValue(tdoa);

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

  254.         // set partial derivatives with respect to parameters
  255.         for (final ParameterDriver driver : getParametersDrivers()) {
  256.             for (Span<String> span = driver.getNamesSpanMap().getFirstSpan(); span != null; span = span.next()) {
  257.                 final Integer index = indices.get(span.getData());
  258.                 if (index != null) {
  259.                     estimated.setParameterDerivatives(driver, span.getStart(), derivatives[index]);
  260.                 }
  261.             }
  262.         }

  263.         return estimated;

  264.     }

  265.     /** Compute propagation delay on a link.
  266.      * @param emitter  the position of the emitter
  267.      * @param receiver the position of the receiver (same frame as emitter)
  268.      * @return the propagation delay
  269.      * @since 12.0
  270.      */
  271.     private double linkDelay(final Vector3D emitter,
  272.                              final Vector3D receiver) {
  273.         return receiver.distance(emitter) / Constants.SPEED_OF_LIGHT;
  274.     }

  275.     /** Compute propagation delay on a link.
  276.      * @param emitter  the position of the emitter
  277.      * @param receiver the position of the receiver (same frame as emitter)
  278.      * @return the propagation delay
  279.      */
  280.     private Gradient linkDelay(final FieldVector3D<Gradient> emitter,
  281.                                final FieldVector3D<Gradient> receiver) {
  282.         return receiver.distance(emitter).divide(Constants.SPEED_OF_LIGHT);
  283.     }

  284. }