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.     /** Primary ground station from which measurement is performed. */
  59.     private final GroundStation primaryStation;

  60.     /** Secondary ground station reflecting the signal. */
  61.     private final GroundStation secondaryStation;

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

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

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

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

  116.         final SpacecraftState state = states[0];

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

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

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

  154.         // Compute propagation time for the 2nd leg of the signal path
  155.         // --

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

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

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

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

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

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

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

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

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

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

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

  191.         // Compute propagation time for the 1st leg of the signal path
  192.         // --

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

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

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


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

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

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

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

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

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

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


  231.         // --
  232.         // Evaluate the turn-around range value and its derivatives
  233.         // --------------------------------------------------------

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

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

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

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

  270.         return estimated;

  271.     }

  272. }