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.     /** Ground station from which measurement is performed. */
  49.     private final GroundStation station;

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

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

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

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

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

  97.         final SpacecraftState state = states[0];

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

  187.         } else {
  188.             estimated = evalOneWay1;
  189.         }

  190.         return estimated;

  191.     }

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

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

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

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

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

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

  228.         // range rate
  229.         Gradient rangeRate = lineOfSightVelocity;

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

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

  236.             rangeRate = rangeRate.add(clockDriftBiais);
  237.         }

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

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

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

  250.         return estimated;

  251.     }

  252. }