RangeRate.java

  1. /* Copyright 2002-2024 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.Map;

  20. import org.hipparchus.analysis.differentiation.Gradient;
  21. import org.hipparchus.geometry.euclidean.threed.FieldVector3D;
  22. import org.hipparchus.geometry.euclidean.threed.Vector3D;
  23. import org.orekit.frames.FieldTransform;
  24. import org.orekit.frames.Transform;
  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.TimeSpanMap.Span;
  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 GroundReceiverMeasurement<RangeRate> {

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

  50.     /** Simple constructor.
  51.      * @param station ground station from which measurement is performed
  52.      * @param date date of the measurement
  53.      * @param rangeRate observed value, m/s
  54.      * @param sigma theoretical standard deviation
  55.      * @param baseWeight base weight
  56.      * @param twoway if true, this is a two-way measurement
  57.      * @param satellite satellite related to this measurement
  58.      * @since 9.3
  59.      */
  60.     public RangeRate(final GroundStation station, final AbsoluteDate date,
  61.                      final double rangeRate, final double sigma, final double baseWeight,
  62.                      final boolean twoway, final ObservableSatellite satellite) {
  63.         super(station, twoway, date, rangeRate, sigma, baseWeight, satellite);
  64.     }

  65.     /** {@inheritDoc} */
  66.     @Override
  67.     protected EstimatedMeasurementBase<RangeRate> theoreticalEvaluationWithoutDerivatives(final int iteration,
  68.                                                                                           final int evaluation,
  69.                                                                                           final SpacecraftState[] states) {

  70.         final GroundReceiverCommonParametersWithoutDerivatives common = computeCommonParametersWithout(states[0]);
  71.         final TimeStampedPVCoordinates transitPV = common.getTransitPV();

  72.         // one-way (downlink) range-rate
  73.         final EstimatedMeasurementBase<RangeRate> evalOneWay1 =
  74.                         oneWayTheoreticalEvaluation(iteration, evaluation, true,
  75.                                                     common.getStationDownlink(),
  76.                                                     transitPV,
  77.                                                     common.getTransitState());
  78.         final EstimatedMeasurementBase<RangeRate> estimated;
  79.         if (isTwoWay()) {
  80.             // one-way (uplink) light time correction
  81.             final Transform offsetToInertialApproxUplink =
  82.                             getStation().getOffsetToInertial(common.getState().getFrame(),
  83.                                                              common.getStationDownlink().getDate().shiftedBy(-2 * common.getTauD()),
  84.                                                              false);
  85.             final AbsoluteDate approxUplinkDate = offsetToInertialApproxUplink.getDate();

  86.             final TimeStampedPVCoordinates stationApproxUplink =
  87.                             offsetToInertialApproxUplink.transformPVCoordinates(new TimeStampedPVCoordinates(approxUplinkDate,
  88.                                                                                                              Vector3D.ZERO, Vector3D.ZERO, Vector3D.ZERO));

  89.             final double tauU = signalTimeOfFlight(stationApproxUplink, transitPV.getPosition(), transitPV.getDate());

  90.             final TimeStampedPVCoordinates stationUplink =
  91.                             stationApproxUplink.shiftedBy(transitPV.getDate().durationFrom(approxUplinkDate) - tauU);

  92.             final EstimatedMeasurementBase<RangeRate> evalOneWay2 =
  93.                             oneWayTheoreticalEvaluation(iteration, evaluation, false,
  94.                                                         stationUplink, transitPV, common.getTransitState());

  95.             // combine uplink and downlink values
  96.             estimated = new EstimatedMeasurementBase<>(this, iteration, evaluation,
  97.                                                        evalOneWay1.getStates(),
  98.                                                        new TimeStampedPVCoordinates[] {
  99.                                                            evalOneWay2.getParticipants()[0],
  100.                                                            evalOneWay1.getParticipants()[0],
  101.                                                            evalOneWay1.getParticipants()[1]
  102.                                                        });
  103.             estimated.setEstimatedValue(0.5 * (evalOneWay1.getEstimatedValue()[0] + evalOneWay2.getEstimatedValue()[0]));

  104.         } else {
  105.             estimated = evalOneWay1;
  106.         }

  107.         return estimated;

  108.     }

  109.     /** {@inheritDoc} */
  110.     @Override
  111.     protected EstimatedMeasurement<RangeRate> theoreticalEvaluation(final int iteration, final int evaluation,
  112.                                                                     final SpacecraftState[] states) {

  113.         final SpacecraftState state = states[0];

  114.         // Range-rate derivatives are computed with respect to spacecraft state in inertial frame
  115.         // and station position in station's offset frame
  116.         // -------
  117.         //
  118.         // Parameters:
  119.         //  - 0..2 - Position of the spacecraft in inertial frame
  120.         //  - 3..5 - Velocity of the spacecraft in inertial frame
  121.         //  - 6..n - station parameters (clock offset, clock drift, station offsets, pole, prime meridian...)
  122.         final GroundReceiverCommonParametersWithDerivatives common = computeCommonParametersWithDerivatives(state);
  123.         final int nbParams = common.getTauD().getFreeParameters();
  124.         final TimeStampedFieldPVCoordinates<Gradient> transitPV = common.getTransitPV();

  125.         // one-way (downlink) range-rate
  126.         final EstimatedMeasurement<RangeRate> evalOneWay1 =
  127.                         oneWayTheoreticalEvaluation(iteration, evaluation, true,
  128.                                                     common.getStationDownlink(), transitPV,
  129.                                                     common.getTransitState(), common.getIndices(), nbParams);
  130.         final EstimatedMeasurement<RangeRate> estimated;
  131.         if (isTwoWay()) {
  132.             // one-way (uplink) light time correction
  133.             final FieldTransform<Gradient> offsetToInertialApproxUplink =
  134.                             getStation().getOffsetToInertial(state.getFrame(),
  135.                                                              common.getStationDownlink().getDate().shiftedBy(common.getTauD().multiply(-2)),
  136.                                                              nbParams, common.getIndices());
  137.             final FieldAbsoluteDate<Gradient> approxUplinkDateDS =
  138.                             offsetToInertialApproxUplink.getFieldDate();

  139.             final FieldVector3D<Gradient> zero = FieldVector3D.getZero(common.getTauD().getField());
  140.             final TimeStampedFieldPVCoordinates<Gradient> stationApproxUplink =
  141.                             offsetToInertialApproxUplink.transformPVCoordinates(new TimeStampedFieldPVCoordinates<>(approxUplinkDateDS,
  142.                                                                                                                     zero, zero, zero));

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

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

  146.             final EstimatedMeasurement<RangeRate> evalOneWay2 =
  147.                             oneWayTheoreticalEvaluation(iteration, evaluation, false,
  148.                                                         stationUplink, transitPV, common.getTransitState(),
  149.                                                         common.getIndices(), nbParams);

  150.             // combine uplink and downlink values
  151.             estimated = new EstimatedMeasurement<>(this, iteration, evaluation,
  152.                                                    evalOneWay1.getStates(),
  153.                                                    new TimeStampedPVCoordinates[] {
  154.                                                        evalOneWay2.getParticipants()[0],
  155.                                                        evalOneWay1.getParticipants()[0],
  156.                                                        evalOneWay1.getParticipants()[1]
  157.                                                    });
  158.             estimated.setEstimatedValue(0.5 * (evalOneWay1.getEstimatedValue()[0] + evalOneWay2.getEstimatedValue()[0]));

  159.             // combine uplink and downlink partial derivatives with respect to state
  160.             final double[][] sd1 = evalOneWay1.getStateDerivatives(0);
  161.             final double[][] sd2 = evalOneWay2.getStateDerivatives(0);
  162.             final double[][] sd = new double[sd1.length][sd1[0].length];
  163.             for (int i = 0; i < sd.length; ++i) {
  164.                 for (int j = 0; j < sd[0].length; ++j) {
  165.                     sd[i][j] = 0.5 * (sd1[i][j] + sd2[i][j]);
  166.                 }
  167.             }
  168.             estimated.setStateDerivatives(0, sd);

  169.             // combine uplink and downlink partial derivatives with respect to parameters
  170.             evalOneWay1.getDerivativesDrivers().forEach(driver -> {
  171.                 for (Span<String> span = driver.getNamesSpanMap().getFirstSpan(); span != null; span = span.next()) {
  172.                     final double[] pd1 = evalOneWay1.getParameterDerivatives(driver, span.getStart());
  173.                     final double[] pd2 = evalOneWay2.getParameterDerivatives(driver, span.getStart());
  174.                     final double[] pd = new double[pd1.length];
  175.                     for (int i = 0; i < pd.length; ++i) {
  176.                         pd[i] = 0.5 * (pd1[i] + pd2[i]);
  177.                     }
  178.                     estimated.setParameterDerivatives(driver, span.getStart(), pd);
  179.                 }
  180.             });

  181.         } else {
  182.             estimated = evalOneWay1;
  183.         }

  184.         return estimated;

  185.     }

  186.     /** Evaluate measurement in one-way without derivatives.
  187.      * @param iteration iteration number
  188.      * @param evaluation evaluations counter
  189.      * @param downlink indicator for downlink leg
  190.      * @param stationPV station coordinates when signal is at station
  191.      * @param transitPV spacecraft coordinates at onboard signal transit
  192.      * @param transitState orbital state at onboard signal transit
  193.      * @return theoretical value
  194.      * @see #evaluate(SpacecraftStatet)
  195.      * @since 12.0
  196.      */
  197.     private EstimatedMeasurementBase<RangeRate> oneWayTheoreticalEvaluation(final int iteration, final int evaluation, final boolean downlink,
  198.                                                                             final TimeStampedPVCoordinates stationPV,
  199.                                                                             final TimeStampedPVCoordinates transitPV,
  200.                                                                             final SpacecraftState transitState) {

  201.         // prepare the evaluation
  202.         final EstimatedMeasurementBase<RangeRate> estimated =
  203.                         new EstimatedMeasurementBase<>(this, iteration, evaluation,
  204.                                                        new SpacecraftState[] {
  205.                                                            transitState
  206.                                                        }, new TimeStampedPVCoordinates[] {
  207.                                                            downlink ? transitPV : stationPV,
  208.                                                            downlink ? stationPV : transitPV
  209.                                                        });

  210.         // range rate value
  211.         final Vector3D stationPosition  = stationPV.getPosition();
  212.         final Vector3D relativePosition = stationPosition.subtract(transitPV.getPosition());

  213.         final Vector3D stationVelocity  = stationPV.getVelocity();
  214.         final Vector3D relativeVelocity = stationVelocity.subtract(transitPV.getVelocity());

  215.         // radial direction
  216.         final Vector3D lineOfSight      = relativePosition.normalize();

  217.         // line of sight velocity
  218.         final double lineOfSightVelocity = Vector3D.dotProduct(relativeVelocity, lineOfSight);

  219.         // range rate
  220.         double rangeRate = lineOfSightVelocity;

  221.         if (!isTwoWay()) {
  222.             // clock drifts, taken in account only in case of one way
  223.             final ObservableSatellite satellite    = getSatellites().get(0);
  224.             final double              dtsDot       = satellite.getClockDriftDriver().getValue(transitState.getDate());
  225.             final double              dtgDot       = getStation().getClockDriftDriver().getValue(stationPV.getDate());

  226.             final double clockDriftBiais = (dtgDot - dtsDot) * Constants.SPEED_OF_LIGHT;

  227.             rangeRate = rangeRate + clockDriftBiais;
  228.         }

  229.         estimated.setEstimatedValue(rangeRate);

  230.         return estimated;

  231.     }

  232.     /** Evaluate measurement in one-way.
  233.      * @param iteration iteration number
  234.      * @param evaluation evaluations counter
  235.      * @param downlink indicator for downlink leg
  236.      * @param stationPV station coordinates when signal is at station
  237.      * @param transitPV spacecraft coordinates at onboard signal transit
  238.      * @param transitState orbital state at onboard signal transit
  239.      * @param indices indices of the estimated parameters in derivatives computations
  240.      * @param nbParams the number of estimated parameters in derivative computations
  241.      * @return theoretical value
  242.      * @see #evaluate(SpacecraftStatet)
  243.      */
  244.     private EstimatedMeasurement<RangeRate> oneWayTheoreticalEvaluation(final int iteration, final int evaluation, final boolean downlink,
  245.                                                                         final TimeStampedFieldPVCoordinates<Gradient> stationPV,
  246.                                                                         final TimeStampedFieldPVCoordinates<Gradient> transitPV,
  247.                                                                         final SpacecraftState transitState,
  248.                                                                         final Map<String, Integer> indices,
  249.                                                                         final int nbParams) {

  250.         // prepare the evaluation
  251.         final EstimatedMeasurement<RangeRate> estimated =
  252.                         new EstimatedMeasurement<RangeRate>(this, iteration, evaluation,
  253.                                                             new SpacecraftState[] {
  254.                                                                 transitState
  255.                                                             }, new TimeStampedPVCoordinates[] {
  256.                                                                 (downlink ? transitPV : stationPV).toTimeStampedPVCoordinates(),
  257.                                                                 (downlink ? stationPV : transitPV).toTimeStampedPVCoordinates()
  258.                                                             });

  259.         // range rate value
  260.         final FieldVector3D<Gradient> stationPosition  = stationPV.getPosition();
  261.         final FieldVector3D<Gradient> relativePosition = stationPosition.subtract(transitPV.getPosition());

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

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

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

  268.         // range rate
  269.         Gradient rangeRate = lineOfSightVelocity;

  270.         if (!isTwoWay()) {
  271.             // clock drifts, taken in account only in case of one way
  272.             final ObservableSatellite satellite    = getSatellites().get(0);
  273.             final Gradient            dtsDot       = satellite.getClockDriftDriver().getValue(nbParams, indices, transitState.getDate());
  274.             final Gradient            dtgDot       = getStation().getClockDriftDriver().getValue(nbParams, indices, stationPV.getDate().toAbsoluteDate());

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

  276.             rangeRate = rangeRate.add(clockDriftBiais);
  277.         }

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

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

  282.         // set partial derivatives with respect to parameters
  283.         // (beware element at index 0 is the value, not a derivative)
  284.         for (final ParameterDriver driver : getParametersDrivers()) {
  285.             for (Span<String> span = driver.getNamesSpanMap().getFirstSpan(); span != null; span = span.next()) {
  286.                 final Integer index = indices.get(span.getData());
  287.                 if (index != null) {
  288.                     estimated.setParameterDerivatives(driver, span.getStart(), derivatives[index]);
  289.                 }
  290.             }
  291.         }

  292.         return estimated;

  293.     }

  294. }