TurnAroundRange.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.Field;
  23. import org.hipparchus.analysis.differentiation.Gradient;
  24. import org.hipparchus.analysis.differentiation.GradientField;
  25. import org.hipparchus.geometry.euclidean.threed.FieldVector3D;
  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.FieldPVCoordinates;
  32. import org.orekit.utils.PVCoordinates;
  33. import org.orekit.utils.ParameterDriver;
  34. import org.orekit.utils.TimeStampedFieldPVCoordinates;
  35. import org.orekit.utils.TimeStampedPVCoordinates;

  36. /** Class modeling a turn-around range measurement using a primary ground station and a secondary ground station.
  37.  * <p>
  38.  * The measurement is considered to be a signal:
  39.  * - Emitted from the primary ground station
  40.  * - Reflected on the spacecraft
  41.  * - Reflected on the secondary ground station
  42.  * - Reflected on the spacecraft again
  43.  * - Received on the primary ground station
  44.  * Its value is the elapsed time between emission and reception
  45.  * divided by 2c were c is the speed of light.
  46.  * The motion of the stations and the spacecraft
  47.  * during the signal flight time are taken into account.
  48.  * The date of the measurement corresponds to the
  49.  * reception on ground of the reflected signal.
  50.  * </p>
  51.  * @author Thierry Ceolin
  52.  * @author Luc Maisonobe
  53.  * @author Maxime Journot
  54.  *
  55.  * @since 9.0
  56.  */
  57. public class TurnAroundRange extends AbstractMeasurement<TurnAroundRange> {

  58.     /** Type of the measurement. */
  59.     public static final String MEASUREMENT_TYPE = "TurnAroundRange";

  60.     /** Primary ground station from which measurement is performed. */
  61.     private final GroundStation primaryStation;

  62.     /** Secondary ground station reflecting the signal. */
  63.     private final GroundStation secondaryStation;

  64.     /** Simple constructor.
  65.      * @param primaryStation ground station from which measurement is performed
  66.      * @param secondaryStation ground station reflecting the signal
  67.      * @param date date of the measurement
  68.      * @param turnAroundRange observed value
  69.      * @param sigma theoretical standard deviation
  70.      * @param baseWeight base weight
  71.      * @param satellite satellite related to this measurement
  72.      * @since 9.3
  73.      */
  74.     public TurnAroundRange(final GroundStation primaryStation, final GroundStation secondaryStation,
  75.                            final AbsoluteDate date, final double turnAroundRange,
  76.                            final double sigma, final double baseWeight,
  77.                            final ObservableSatellite satellite) {
  78.         super(date, turnAroundRange, sigma, baseWeight, Collections.singletonList(satellite));
  79.         addParameterDriver(primaryStation.getClockOffsetDriver());
  80.         addParameterDriver(primaryStation.getEastOffsetDriver());
  81.         addParameterDriver(primaryStation.getNorthOffsetDriver());
  82.         addParameterDriver(primaryStation.getZenithOffsetDriver());
  83.         addParameterDriver(primaryStation.getPrimeMeridianOffsetDriver());
  84.         addParameterDriver(primaryStation.getPrimeMeridianDriftDriver());
  85.         addParameterDriver(primaryStation.getPolarOffsetXDriver());
  86.         addParameterDriver(primaryStation.getPolarDriftXDriver());
  87.         addParameterDriver(primaryStation.getPolarOffsetYDriver());
  88.         addParameterDriver(primaryStation.getPolarDriftYDriver());
  89.         // the secondary station clock is not used at all, we ignore the corresponding parameter driver
  90.         addParameterDriver(secondaryStation.getEastOffsetDriver());
  91.         addParameterDriver(secondaryStation.getNorthOffsetDriver());
  92.         addParameterDriver(secondaryStation.getZenithOffsetDriver());
  93.         addParameterDriver(secondaryStation.getPrimeMeridianOffsetDriver());
  94.         addParameterDriver(secondaryStation.getPrimeMeridianDriftDriver());
  95.         addParameterDriver(secondaryStation.getPolarOffsetXDriver());
  96.         addParameterDriver(secondaryStation.getPolarDriftXDriver());
  97.         addParameterDriver(secondaryStation.getPolarOffsetYDriver());
  98.         addParameterDriver(secondaryStation.getPolarDriftYDriver());
  99.         this.primaryStation   = primaryStation;
  100.         this.secondaryStation = secondaryStation;
  101.     }

  102.     /** Get the primary ground station from which measurement is performed.
  103.      * @return primary ground station from which measurement is performed
  104.      */
  105.     public GroundStation getPrimaryStation() {
  106.         return primaryStation;
  107.     }

  108.     /** Get the secondary ground station reflecting the signal.
  109.      * @return secondary ground station reflecting the signal
  110.      */
  111.     public GroundStation getSecondaryStation() {
  112.         return secondaryStation;
  113.     }

  114.     /** {@inheritDoc} */
  115.     @Override
  116.     protected EstimatedMeasurement<TurnAroundRange> theoreticalEvaluation(final int iteration, final int evaluation,
  117.                                                                           final SpacecraftState[] states) {

  118.         final SpacecraftState state = states[0];

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

  140.         // Place the gradient in a time-stamped PV
  141.         final TimeStampedFieldPVCoordinates<Gradient> pvaDS = getCoordinates(state, 0, nbParams);

  142.         // The path of the signal is divided in two legs.
  143.         // Leg1: Emission from primary station to satellite in primaryTauU seconds
  144.         //     + Reflection from satellite to secondary station in secondaryTauD seconds
  145.         // Leg2: Reflection from secondary station to satellite in secondaryTauU seconds
  146.         //     + Reflection from satellite to primary station in primaryTaudD seconds
  147.         // The measurement is considered to be time stamped at reception on ground
  148.         // by the primary station. All times are therefore computed as backward offsets
  149.         // with respect to this reception time.
  150.         //
  151.         // Two intermediate spacecraft states are defined:
  152.         //  - transitStateLeg2: State of the satellite when it bounced back the signal
  153.         //                      from secondary station to primary station during the 2nd leg
  154.         //  - transitStateLeg1: State of the satellite when it bounced back the signal
  155.         //                      from primary station to secondary station during the 1st leg

  156.         // Compute propagation time for the 2nd leg of the signal path
  157.         // --

  158.         // Time difference between t (date of the measurement) and t' (date tagged in spacecraft state)
  159.         // (if state has already been set up to pre-compensate propagation delay,
  160.         // we will have delta = primaryTauD + secondaryTauU)
  161.         final double delta = getDate().durationFrom(state.getDate());

  162.         // transform between primary station topocentric frame (east-north-zenith) and inertial frame expressed as gradients
  163.         final FieldTransform<Gradient> primaryToInert =
  164.                         primaryStation.getOffsetToInertial(state.getFrame(), getDate(), nbParams, indices);
  165.         final FieldAbsoluteDate<Gradient> measurementDateDS = primaryToInert.getFieldDate();

  166.         // Primary station PV in inertial frame at measurement date
  167.         final TimeStampedFieldPVCoordinates<Gradient> primaryArrival =
  168.                         primaryToInert.transformPVCoordinates(new TimeStampedFieldPVCoordinates<>(measurementDateDS,
  169.                                                                                                   zero, zero, zero));

  170.         // Compute propagation times
  171.         final Gradient primaryTauD = signalTimeOfFlight(pvaDS, primaryArrival.getPosition(), measurementDateDS);

  172.         // Elapsed time between state date t' and signal arrival to the transit state of the 2nd leg
  173.         final Gradient dtLeg2 = primaryTauD.negate().add(delta);

  174.         // Transit state where the satellite reflected the signal from secondary to primary station
  175.         final SpacecraftState transitStateLeg2 = state.shiftedBy(dtLeg2.getValue());

  176.         // Transit state pv of leg2 (re)computed with gradient
  177.         final TimeStampedFieldPVCoordinates<Gradient> transitStateLeg2PV = pvaDS.shiftedBy(dtLeg2);

  178.         // transform between secondary station topocentric frame (east-north-zenith) and inertial frame expressed as gradients
  179.         // The components of secondary station's position in offset frame are the 3 last derivative parameters
  180.         final FieldAbsoluteDate<Gradient> approxReboundDate = measurementDateDS.shiftedBy(-delta);
  181.         final FieldTransform<Gradient> secondaryToInertApprox =
  182.                         secondaryStation.getOffsetToInertial(state.getFrame(), approxReboundDate, nbParams, indices);

  183.         // Secondary station PV in inertial frame at approximate rebound date on secondary station
  184.         final TimeStampedFieldPVCoordinates<Gradient> QSecondaryApprox =
  185.                         secondaryToInertApprox.transformPVCoordinates(new TimeStampedFieldPVCoordinates<>(approxReboundDate,
  186.                                                                                                           zero, zero, zero));

  187.         // Uplink time of flight from secondary station to transit state of leg2
  188.         final Gradient secondaryTauU = signalTimeOfFlight(QSecondaryApprox,
  189.                                                           transitStateLeg2PV.getPosition(),
  190.                                                           transitStateLeg2PV.getDate());

  191.         // Total time of flight for leg 2
  192.         final Gradient tauLeg2 = primaryTauD.add(secondaryTauU);

  193.         // Compute propagation time for the 1st leg of the signal path
  194.         // --

  195.         // Absolute date of rebound of the signal to secondary station
  196.         final FieldAbsoluteDate<Gradient> reboundDateDS = measurementDateDS.shiftedBy(tauLeg2.negate());
  197.         final FieldTransform<Gradient> secondaryToInert =
  198.                         secondaryStation.getOffsetToInertial(state.getFrame(), reboundDateDS, nbParams, indices);

  199.         // Secondary station PV in inertial frame at rebound date on secondary station
  200.         final TimeStampedFieldPVCoordinates<Gradient> secondaryRebound =
  201.                         secondaryToInert.transformPVCoordinates(new TimeStampedFieldPVCoordinates<>(reboundDateDS,
  202.                                                                                                     FieldPVCoordinates.getZero(field)));

  203.         // Downlink time of flight from transitStateLeg1 to secondary station at rebound date
  204.         final Gradient secondaryTauD = signalTimeOfFlight(transitStateLeg2PV,
  205.                                                           secondaryRebound.getPosition(),
  206.                                                           reboundDateDS);


  207.         // Elapsed time between state date t' and signal arrival to the transit state of the 1st leg
  208.         final Gradient dtLeg1 = dtLeg2.subtract(secondaryTauU).subtract(secondaryTauD);

  209.         // Transit state pv of leg2 (re)computed with gradients
  210.         final TimeStampedFieldPVCoordinates<Gradient> transitStateLeg1PV = pvaDS.shiftedBy(dtLeg1);

  211.         // transform between primary station topocentric frame (east-north-zenith) and inertial frame expressed as gradients
  212.         // The components of primary station's position in offset frame are the 3 third derivative parameters
  213.         final FieldAbsoluteDate<Gradient> approxEmissionDate =
  214.                         measurementDateDS.shiftedBy(-2 * (secondaryTauU.getValue() + primaryTauD.getValue()));
  215.         final FieldTransform<Gradient> primaryToInertApprox =
  216.                         primaryStation.getOffsetToInertial(state.getFrame(), approxEmissionDate, nbParams, indices);

  217.         // Primary station PV in inertial frame at approximate emission date
  218.         final TimeStampedFieldPVCoordinates<Gradient> QPrimaryApprox =
  219.                         primaryToInertApprox.transformPVCoordinates(new TimeStampedFieldPVCoordinates<>(approxEmissionDate,
  220.                                                                                                         zero, zero, zero));

  221.         // Uplink time of flight from primary station to transit state of leg1
  222.         final Gradient primaryTauU = signalTimeOfFlight(QPrimaryApprox,
  223.                                                         transitStateLeg1PV.getPosition(),
  224.                                                         transitStateLeg1PV.getDate());

  225.         // Primary station PV in inertial frame at exact emission date
  226.         final AbsoluteDate emissionDate = transitStateLeg1PV.getDate().toAbsoluteDate().shiftedBy(-primaryTauU.getValue());
  227.         final TimeStampedPVCoordinates primaryDeparture =
  228.                         primaryToInertApprox.shiftedBy(emissionDate.durationFrom(primaryToInertApprox.getDate())).
  229.                         transformPVCoordinates(new TimeStampedPVCoordinates(emissionDate, PVCoordinates.ZERO)).
  230.                         toTimeStampedPVCoordinates();

  231.         // Total time of flight for leg 1
  232.         final Gradient tauLeg1 = secondaryTauD.add(primaryTauU);


  233.         // --
  234.         // Evaluate the turn-around range value and its derivatives
  235.         // --------------------------------------------------------

  236.         // The state we use to define the estimated measurement is a middle ground between the two transit states
  237.         // This is done to avoid calling "SpacecraftState.shiftedBy" function on long duration
  238.         // Thus we define the state at the date t" = date of rebound of the signal at the secondary station
  239.         // Or t" = t -primaryTauD -secondaryTauU
  240.         // The iterative process in the estimation ensures that, after several iterations, the date stamped in the
  241.         // state S in input of this function will be close to t"
  242.         // Therefore we will shift state S by:
  243.         //  - +secondaryTauU to get transitStateLeg2
  244.         //  - -secondaryTauD to get transitStateLeg1
  245.         final EstimatedMeasurement<TurnAroundRange> estimated =
  246.                         new EstimatedMeasurement<>(this, iteration, evaluation,
  247.                                                    new SpacecraftState[] {
  248.                                                        transitStateLeg2.shiftedBy(-secondaryTauU.getValue())
  249.                                                    },
  250.                                                    new TimeStampedPVCoordinates[] {
  251.                                                        primaryDeparture,
  252.                                                        transitStateLeg1PV.toTimeStampedPVCoordinates(),
  253.                                                        secondaryRebound.toTimeStampedPVCoordinates(),
  254.                                                        transitStateLeg2.getPVCoordinates(),
  255.                                                        primaryArrival.toTimeStampedPVCoordinates()
  256.                                                    });

  257.         // Turn-around range value = Total time of flight for the 2 legs divided by 2 and multiplied by c
  258.         final double cOver2 = 0.5 * Constants.SPEED_OF_LIGHT;
  259.         final Gradient turnAroundRange = (tauLeg2.add(tauLeg1)).multiply(cOver2);
  260.         estimated.setEstimatedValue(turnAroundRange.getValue());

  261.         // Turn-around range partial derivatives with respect to state
  262.         final double[] derivatives = turnAroundRange.getGradient();
  263.         estimated.setStateDerivatives(0, Arrays.copyOfRange(derivatives, 0, 6));

  264.         // set partial derivatives with respect to parameters
  265.         // (beware element at index 0 is the value, not a derivative)
  266.         for (final ParameterDriver driver : getParametersDrivers()) {
  267.             final Integer index = indices.get(driver.getName());
  268.             if (index != null) {
  269.                 estimated.setParameterDerivatives(driver, derivatives[index]);
  270.             }
  271.         }

  272.         return estimated;

  273.     }

  274. }