RangeRate.java

  1. /* Copyright 2002-2020 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.orekit.frames.FieldTransform;
  25. import org.orekit.propagation.SpacecraftState;
  26. import org.orekit.time.AbsoluteDate;
  27. import org.orekit.time.FieldAbsoluteDate;
  28. import org.orekit.utils.Constants;
  29. import org.orekit.utils.ParameterDriver;
  30. import org.orekit.utils.TimeStampedFieldPVCoordinates;
  31. import org.orekit.utils.TimeStampedPVCoordinates;

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

  47.     /** Ground station from which measurement is performed. */
  48.     private final GroundStation station;

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

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

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

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

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

  96.         final SpacecraftState state = states[0];

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

  189.         return estimated;

  190.     }

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

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

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

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

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

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

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

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

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

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

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

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

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

  249.         return estimated;

  250.     }

  251. }