RangeRate.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.orekit.frames.FieldTransform;
  26. import org.orekit.propagation.SpacecraftState;
  27. import org.orekit.time.AbsoluteDate;
  28. import org.orekit.time.FieldAbsoluteDate;
  29. import org.orekit.utils.Constants;
  30. import org.orekit.utils.ParameterDriver;
  31. import org.orekit.utils.TimeStampedFieldPVCoordinates;
  32. import org.orekit.utils.TimeStampedPVCoordinates;

  33. /** Class modeling one-way or two-way range rate measurement between two vehicles.
  34.  * One-way range rate (or Doppler) measurements generally apply to specific satellites
  35.  * (e.g. GNSS, DORIS), where a signal is transmitted from a satellite to a
  36.  * measuring station.
  37.  * Two-way range rate measurements are applicable to any system. The signal is
  38.  * transmitted to the (non-spinning) satellite and returned by a transponder
  39.  * (or reflected back)to the same measuring station.
  40.  * The Doppler measurement can be obtained by multiplying the velocity by (fe/c), where
  41.  * fe is the emission frequency.
  42.  *
  43.  * @author Thierry Ceolin
  44.  * @author Joris Olympio
  45.  * @since 8.0
  46.  */
  47. public class RangeRate extends AbstractMeasurement<RangeRate> {

  48.     /** Type of the measurement. */
  49.     public static final String MEASUREMENT_TYPE = "RangeRate";

  50.     /** Ground station from which measurement is performed. */
  51.     private final GroundStation station;

  52.     /** Flag indicating whether it is a two-way measurement. */
  53.     private final boolean twoway;

  54.     /** Simple constructor.
  55.      * @param station ground station from which measurement is performed
  56.      * @param date date of the measurement
  57.      * @param rangeRate observed value, m/s
  58.      * @param sigma theoretical standard deviation
  59.      * @param baseWeight base weight
  60.      * @param twoway if true, this is a two-way measurement
  61.      * @param satellite satellite related to this measurement
  62.      * @since 9.3
  63.      */
  64.     public RangeRate(final GroundStation station, final AbsoluteDate date,
  65.                      final double rangeRate, final double sigma, final double baseWeight,
  66.                      final boolean twoway, final ObservableSatellite satellite) {
  67.         super(date, rangeRate, sigma, baseWeight, Collections.singletonList(satellite));
  68.         addParameterDriver(station.getClockOffsetDriver());
  69.         addParameterDriver(station.getClockDriftDriver());
  70.         addParameterDriver(satellite.getClockDriftDriver());
  71.         addParameterDriver(station.getEastOffsetDriver());
  72.         addParameterDriver(station.getNorthOffsetDriver());
  73.         addParameterDriver(station.getZenithOffsetDriver());
  74.         addParameterDriver(station.getPrimeMeridianOffsetDriver());
  75.         addParameterDriver(station.getPrimeMeridianDriftDriver());
  76.         addParameterDriver(station.getPolarOffsetXDriver());
  77.         addParameterDriver(station.getPolarDriftXDriver());
  78.         addParameterDriver(station.getPolarOffsetYDriver());
  79.         addParameterDriver(station.getPolarDriftYDriver());
  80.         this.station = station;
  81.         this.twoway  = twoway;
  82.     }

  83.     /** Check if the instance represents a two-way measurement.
  84.      * @return true if the instance represents a two-way measurement
  85.      */
  86.     public boolean isTwoWay() {
  87.         return twoway;
  88.     }

  89.     /** Get the ground station from which measurement is performed.
  90.      * @return ground station from which measurement is performed
  91.      */
  92.     public GroundStation getStation() {
  93.         return station;
  94.     }

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

  99.         final SpacecraftState state = states[0];

  100.         // Range-rate derivatives are computed with respect to spacecraft state in inertial frame
  101.         // and station position in station's offset frame
  102.         // -------
  103.         //
  104.         // Parameters:
  105.         //  - 0..2 - Position of the spacecraft in inertial frame
  106.         //  - 3..5 - Velocity of the spacecraft in inertial frame
  107.         //  - 6..n - station parameters (clock offset, clock drift, station offsets, pole, prime meridian...)
  108.         int nbParams = 6;
  109.         final Map<String, Integer> indices = new HashMap<>();
  110.         for (ParameterDriver driver : getParametersDrivers()) {
  111.             if (driver.isSelected()) {
  112.                 indices.put(driver.getName(), nbParams++);
  113.             }
  114.         }
  115.         final FieldVector3D<Gradient> zero = FieldVector3D.getZero(GradientField.getField(nbParams));

  116.         // Coordinates of the spacecraft expressed as a gradient
  117.         final TimeStampedFieldPVCoordinates<Gradient> pvaDS = getCoordinates(state, 0, nbParams);

  118.         // transform between station and inertial frame, expressed as a gradient
  119.         // The components of station's position in offset frame are the 3 last derivative parameters
  120.         final FieldTransform<Gradient> offsetToInertialDownlink =
  121.                         station.getOffsetToInertial(state.getFrame(), getDate(), nbParams, indices);
  122.         final FieldAbsoluteDate<Gradient> downlinkDateDS =
  123.                         offsetToInertialDownlink.getFieldDate();

  124.         // Station position in inertial frame at end of the downlink leg
  125.         final TimeStampedFieldPVCoordinates<Gradient> stationDownlink =
  126.                         offsetToInertialDownlink.transformPVCoordinates(new TimeStampedFieldPVCoordinates<>(downlinkDateDS,
  127.                                                                                                             zero, zero, zero));

  128.         // Compute propagation times
  129.         // (if state has already been set up to pre-compensate propagation delay,
  130.         //  we will have delta == tauD and transitState will be the same as state)

  131.         // Downlink delay
  132.         final Gradient tauD = signalTimeOfFlight(pvaDS, stationDownlink.getPosition(), downlinkDateDS);

  133.         // Transit state
  134.         final Gradient        delta        = downlinkDateDS.durationFrom(state.getDate());
  135.         final Gradient        deltaMTauD   = tauD.negate().add(delta);
  136.         final SpacecraftState transitState = state.shiftedBy(deltaMTauD.getValue());

  137.         // Transit state (re)computed with gradients
  138.         final TimeStampedFieldPVCoordinates<Gradient> transitPV = pvaDS.shiftedBy(deltaMTauD);

  139.         // one-way (downlink) range-rate
  140.         final EstimatedMeasurement<RangeRate> evalOneWay1 =
  141.                         oneWayTheoreticalEvaluation(iteration, evaluation, true,
  142.                                                     stationDownlink, transitPV, transitState, indices, nbParams);
  143.         final EstimatedMeasurement<RangeRate> estimated;
  144.         if (twoway) {
  145.             // one-way (uplink) light time correction
  146.             final FieldTransform<Gradient> offsetToInertialApproxUplink =
  147.                             station.getOffsetToInertial(state.getFrame(),
  148.                                                         downlinkDateDS.shiftedBy(tauD.multiply(-2)), nbParams, indices);
  149.             final FieldAbsoluteDate<Gradient> approxUplinkDateDS =
  150.                             offsetToInertialApproxUplink.getFieldDate();

  151.             final TimeStampedFieldPVCoordinates<Gradient> stationApproxUplink =
  152.                             offsetToInertialApproxUplink.transformPVCoordinates(new TimeStampedFieldPVCoordinates<>(approxUplinkDateDS,
  153.                                                                                                                     zero, zero, zero));

  154.             final Gradient tauU = signalTimeOfFlight(stationApproxUplink, transitPV.getPosition(), transitPV.getDate());

  155.             final TimeStampedFieldPVCoordinates<Gradient> stationUplink =
  156.                             stationApproxUplink.shiftedBy(transitPV.getDate().durationFrom(approxUplinkDateDS).subtract(tauU));

  157.             final EstimatedMeasurement<RangeRate> evalOneWay2 =
  158.                             oneWayTheoreticalEvaluation(iteration, evaluation, false,
  159.                                                         stationUplink, transitPV, transitState, indices, nbParams);

  160.             // combine uplink and downlink values
  161.             estimated = new EstimatedMeasurement<>(this, iteration, evaluation,
  162.                                                    evalOneWay1.getStates(),
  163.                                                    new TimeStampedPVCoordinates[] {
  164.                                                        evalOneWay2.getParticipants()[0],
  165.                                                        evalOneWay1.getParticipants()[0],
  166.                                                        evalOneWay1.getParticipants()[1]
  167.                                                    });
  168.             estimated.setEstimatedValue(0.5 * (evalOneWay1.getEstimatedValue()[0] + evalOneWay2.getEstimatedValue()[0]));

  169.             // combine uplink and downlink partial derivatives with respect to state
  170.             final double[][] sd1 = evalOneWay1.getStateDerivatives(0);
  171.             final double[][] sd2 = evalOneWay2.getStateDerivatives(0);
  172.             final double[][] sd = new double[sd1.length][sd1[0].length];
  173.             for (int i = 0; i < sd.length; ++i) {
  174.                 for (int j = 0; j < sd[0].length; ++j) {
  175.                     sd[i][j] = 0.5 * (sd1[i][j] + sd2[i][j]);
  176.                 }
  177.             }
  178.             estimated.setStateDerivatives(0, sd);

  179.             // combine uplink and downlink partial derivatives with respect to parameters
  180.             evalOneWay1.getDerivativesDrivers().forEach(driver -> {
  181.                 final double[] pd1 = evalOneWay1.getParameterDerivatives(driver);
  182.                 final double[] pd2 = evalOneWay2.getParameterDerivatives(driver);
  183.                 final double[] pd = new double[pd1.length];
  184.                 for (int i = 0; i < pd.length; ++i) {
  185.                     pd[i] = 0.5 * (pd1[i] + pd2[i]);
  186.                 }
  187.                 estimated.setParameterDerivatives(driver, pd);
  188.             });

  189.         } else {
  190.             estimated = evalOneWay1;
  191.         }

  192.         return estimated;

  193.     }

  194.     /** Evaluate measurement in one-way.
  195.      * @param iteration iteration number
  196.      * @param evaluation evaluations counter
  197.      * @param downlink indicator for downlink leg
  198.      * @param stationPV station coordinates when signal is at station
  199.      * @param transitPV spacecraft coordinates at onboard signal transit
  200.      * @param transitState orbital state at onboard signal transit
  201.      * @param indices indices of the estimated parameters in derivatives computations
  202.      * @param nbParams the number of estimated parameters in derivative computations
  203.      * @return theoretical value
  204.      * @see #evaluate(SpacecraftStatet)
  205.      */
  206.     private EstimatedMeasurement<RangeRate> oneWayTheoreticalEvaluation(final int iteration, final int evaluation, final boolean downlink,
  207.                                                                         final TimeStampedFieldPVCoordinates<Gradient> stationPV,
  208.                                                                         final TimeStampedFieldPVCoordinates<Gradient> transitPV,
  209.                                                                         final SpacecraftState transitState,
  210.                                                                         final Map<String, Integer> indices,
  211.                                                                         final int nbParams) {

  212.         // prepare the evaluation
  213.         final EstimatedMeasurement<RangeRate> estimated =
  214.                         new EstimatedMeasurement<RangeRate>(this, iteration, evaluation,
  215.                                                             new SpacecraftState[] {
  216.                                                                 transitState
  217.                                                             }, new TimeStampedPVCoordinates[] {
  218.                                                                 (downlink ? transitPV : stationPV).toTimeStampedPVCoordinates(),
  219.                                                                 (downlink ? stationPV : transitPV).toTimeStampedPVCoordinates()
  220.                                                             });

  221.         // range rate value
  222.         final FieldVector3D<Gradient> stationPosition  = stationPV.getPosition();
  223.         final FieldVector3D<Gradient> relativePosition = stationPosition.subtract(transitPV.getPosition());

  224.         final FieldVector3D<Gradient> stationVelocity  = stationPV.getVelocity();
  225.         final FieldVector3D<Gradient> relativeVelocity = stationVelocity.subtract(transitPV.getVelocity());

  226.         // radial direction
  227.         final FieldVector3D<Gradient> lineOfSight      = relativePosition.normalize();

  228.         // line of sight velocity
  229.         final Gradient lineOfSightVelocity = FieldVector3D.dotProduct(relativeVelocity, lineOfSight);

  230.         // range rate
  231.         Gradient rangeRate = lineOfSightVelocity;

  232.         if (!twoway) {
  233.             // clock drifts, taken in account only in case of one way
  234.             final ObservableSatellite satellite    = getSatellites().get(0);
  235.             final Gradient            dtsDot       = satellite.getClockDriftDriver().getValue(nbParams, indices);
  236.             final Gradient            dtgDot       = station.getClockDriftDriver().getValue(nbParams, indices);

  237.             final Gradient clockDriftBiais = dtgDot.subtract(dtsDot).multiply(Constants.SPEED_OF_LIGHT);

  238.             rangeRate = rangeRate.add(clockDriftBiais);
  239.         }

  240.         estimated.setEstimatedValue(rangeRate.getValue());

  241.         // compute partial derivatives of (rr) with respect to spacecraft state Cartesian coordinates
  242.         final double[] derivatives = rangeRate.getGradient();
  243.         estimated.setStateDerivatives(0, Arrays.copyOfRange(derivatives, 0, 6));

  244.         // set partial derivatives with respect to parameters
  245.         // (beware element at index 0 is the value, not a derivative)
  246.         for (final ParameterDriver driver : getParametersDrivers()) {
  247.             final Integer index = indices.get(driver.getName());
  248.             if (index != null) {
  249.                 estimated.setParameterDerivatives(driver, derivatives[index]);
  250.             }
  251.         }

  252.         return estimated;

  253.     }

  254. }