RangeRate.java

  1. /* Copyright 2002-2019 CS Systèmes d'Information
  2.  * Licensed to CS Systèmes d'Information (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.Field;
  22. import org.hipparchus.analysis.differentiation.DSFactory;
  23. import org.hipparchus.analysis.differentiation.DerivativeStructure;
  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.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.      * <p>
  53.      * This constructor uses 0 as the index of the propagator related
  54.      * to this measurement, thus being well suited for mono-satellite
  55.      * orbit determination.
  56.      * </p>
  57.      * @param station ground station from which measurement is performed
  58.      * @param date date of the measurement
  59.      * @param rangeRate observed value, m/s
  60.      * @param sigma theoretical standard deviation
  61.      * @param baseWeight base weight
  62.      * @param twoway if true, this is a two-way measurement
  63.      * @deprecated since 9.3 replaced by {@link #RangeRate(GroundStation, AbsoluteDate,
  64.      * double, double, double, boolean, ObservableSatellite)}
  65.      */
  66.     @Deprecated
  67.     public RangeRate(final GroundStation station, final AbsoluteDate date,
  68.                      final double rangeRate,
  69.                      final double sigma,
  70.                      final double baseWeight,
  71.                      final boolean twoway) {
  72.         this(station, date, rangeRate, sigma, baseWeight, twoway, new ObservableSatellite(0));
  73.     }

  74.     /** Simple constructor.
  75.      * @param station ground station from which measurement is performed
  76.      * @param date date of the measurement
  77.      * @param rangeRate observed value, m/s
  78.      * @param sigma theoretical standard deviation
  79.      * @param baseWeight base weight
  80.      * @param twoway if true, this is a two-way measurement
  81.      * @param propagatorIndex index of the propagator related to this measurement
  82.      * @since 9.0
  83.      * @deprecated since 9.3 replaced by {@link #RangeRate(GroundStation, AbsoluteDate,
  84.      * double, double, double, boolean, ObservableSatellite)}
  85.      */
  86.     @Deprecated
  87.     public RangeRate(final GroundStation station, final AbsoluteDate date,
  88.                      final double rangeRate,
  89.                      final double sigma,
  90.                      final double baseWeight,
  91.                      final boolean twoway,
  92.                      final int propagatorIndex) {
  93.         this(station, date, rangeRate, sigma, baseWeight, twoway, new ObservableSatellite(propagatorIndex));
  94.     }

  95.     /** Simple constructor.
  96.      * @param station ground station from which measurement is performed
  97.      * @param date date of the measurement
  98.      * @param rangeRate observed value, m/s
  99.      * @param sigma theoretical standard deviation
  100.      * @param baseWeight base weight
  101.      * @param twoway if true, this is a two-way measurement
  102.      * @param satellite satellite related to this measurement
  103.      * @since 9.3
  104.      */
  105.     public RangeRate(final GroundStation station, final AbsoluteDate date,
  106.                      final double rangeRate, final double sigma, final double baseWeight,
  107.                      final boolean twoway, final ObservableSatellite satellite) {
  108.         super(date, rangeRate, sigma, baseWeight, Arrays.asList(satellite));
  109.         addParameterDriver(station.getClockOffsetDriver());
  110.         addParameterDriver(station.getEastOffsetDriver());
  111.         addParameterDriver(station.getNorthOffsetDriver());
  112.         addParameterDriver(station.getZenithOffsetDriver());
  113.         addParameterDriver(station.getPrimeMeridianOffsetDriver());
  114.         addParameterDriver(station.getPrimeMeridianDriftDriver());
  115.         addParameterDriver(station.getPolarOffsetXDriver());
  116.         addParameterDriver(station.getPolarDriftXDriver());
  117.         addParameterDriver(station.getPolarOffsetYDriver());
  118.         addParameterDriver(station.getPolarDriftYDriver());
  119.         this.station = station;
  120.         this.twoway  = twoway;
  121.     }

  122.     /** Check if the instance represents a two-way measurement.
  123.      * @return true if the instance represents a two-way measurement
  124.      */
  125.     public boolean isTwoWay() {
  126.         return twoway;
  127.     }

  128.     /** Get the ground station from which measurement is performed.
  129.      * @return ground station from which measurement is performed
  130.      */
  131.     public GroundStation getStation() {
  132.         return station;
  133.     }

  134.     /** {@inheritDoc} */
  135.     @Override
  136.     protected EstimatedMeasurement<RangeRate> theoreticalEvaluation(final int iteration, final int evaluation,
  137.                                                                     final SpacecraftState[] states) {

  138.         final ObservableSatellite satellite = getSatellites().get(0);
  139.         final SpacecraftState     state     = states[satellite.getPropagatorIndex()];

  140.         // Range-rate derivatives are computed with respect to spacecraft state in inertial frame
  141.         // and station position in station's offset frame
  142.         // -------
  143.         //
  144.         // Parameters:
  145.         //  - 0..2 - Position of the spacecraft in inertial frame
  146.         //  - 3..5 - Velocity of the spacecraft in inertial frame
  147.         //  - 6..n - station parameters (clock offset, station offsets, pole, prime meridian...)
  148.         int nbParams = 6;
  149.         final Map<String, Integer> indices = new HashMap<>();
  150.         for (ParameterDriver driver : getParametersDrivers()) {
  151.             if (driver.isSelected()) {
  152.                 indices.put(driver.getName(), nbParams++);
  153.             }
  154.         }
  155.         final DSFactory factory = new DSFactory(nbParams, 1);
  156.         final Field<DerivativeStructure> field = factory.getDerivativeField();
  157.         final FieldVector3D<DerivativeStructure> zero = FieldVector3D.getZero(field);

  158.         // Coordinates of the spacecraft expressed as a derivative structure
  159.         final TimeStampedFieldPVCoordinates<DerivativeStructure> pvaDS = getCoordinates(state, 0, factory);

  160.         // transform between station and inertial frame, expressed as a derivative structure
  161.         // The components of station's position in offset frame are the 3 last derivative parameters
  162.         final FieldTransform<DerivativeStructure> offsetToInertialDownlink =
  163.                         station.getOffsetToInertial(state.getFrame(), getDate(), factory, indices);
  164.         final FieldAbsoluteDate<DerivativeStructure> downlinkDateDS =
  165.                         offsetToInertialDownlink.getFieldDate();

  166.         // Station position in inertial frame at end of the downlink leg
  167.         final TimeStampedFieldPVCoordinates<DerivativeStructure> stationDownlink =
  168.                         offsetToInertialDownlink.transformPVCoordinates(new TimeStampedFieldPVCoordinates<>(downlinkDateDS,
  169.                                                                                                             zero, zero, zero));

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

  173.         // Downlink delay
  174.         final DerivativeStructure tauD = signalTimeOfFlight(pvaDS, stationDownlink.getPosition(), downlinkDateDS);

  175.         // Transit state
  176.         final DerivativeStructure   delta        = downlinkDateDS.durationFrom(state.getDate());
  177.         final DerivativeStructure   deltaMTauD   = tauD.negate().add(delta);
  178.         final SpacecraftState       transitState = state.shiftedBy(deltaMTauD.getValue());

  179.         // Transit state (re)computed with derivative structures
  180.         final TimeStampedFieldPVCoordinates<DerivativeStructure> transitPV = pvaDS.shiftedBy(deltaMTauD);

  181.         // one-way (downlink) range-rate
  182.         final EstimatedMeasurement<RangeRate> evalOneWay1 =
  183.                         oneWayTheoreticalEvaluation(iteration, evaluation, true,
  184.                                                     stationDownlink, transitPV, transitState, indices);
  185.         final EstimatedMeasurement<RangeRate> estimated;
  186.         if (twoway) {
  187.             // one-way (uplink) light time correction
  188.             final FieldTransform<DerivativeStructure> offsetToInertialApproxUplink =
  189.                             station.getOffsetToInertial(state.getFrame(),
  190.                                                         downlinkDateDS.shiftedBy(tauD.multiply(-2)), factory, indices);
  191.             final FieldAbsoluteDate<DerivativeStructure> approxUplinkDateDS =
  192.                             offsetToInertialApproxUplink.getFieldDate();

  193.             final TimeStampedFieldPVCoordinates<DerivativeStructure> stationApproxUplink =
  194.                             offsetToInertialApproxUplink.transformPVCoordinates(new TimeStampedFieldPVCoordinates<>(approxUplinkDateDS,
  195.                                                                                                                     zero, zero, zero));

  196.             final DerivativeStructure tauU = signalTimeOfFlight(stationApproxUplink, transitPV.getPosition(), transitPV.getDate());

  197.             final TimeStampedFieldPVCoordinates<DerivativeStructure> stationUplink =
  198.                             stationApproxUplink.shiftedBy(transitPV.getDate().durationFrom(approxUplinkDateDS).subtract(tauU));

  199.             final EstimatedMeasurement<RangeRate> evalOneWay2 =
  200.                             oneWayTheoreticalEvaluation(iteration, evaluation, false,
  201.                                                         stationUplink, transitPV, transitState, indices);

  202.             // combine uplink and downlink values
  203.             estimated = new EstimatedMeasurement<>(this, iteration, evaluation,
  204.                                                    evalOneWay1.getStates(),
  205.                                                    new TimeStampedPVCoordinates[] {
  206.                                                        evalOneWay2.getParticipants()[0],
  207.                                                        evalOneWay1.getParticipants()[0],
  208.                                                        evalOneWay1.getParticipants()[1]
  209.                                                    });
  210.             estimated.setEstimatedValue(0.5 * (evalOneWay1.getEstimatedValue()[0] + evalOneWay2.getEstimatedValue()[0]));

  211.             // combine uplink and downlink partial derivatives with respect to state
  212.             final double[][] sd1 = evalOneWay1.getStateDerivatives(0);
  213.             final double[][] sd2 = evalOneWay2.getStateDerivatives(0);
  214.             final double[][] sd = new double[sd1.length][sd1[0].length];
  215.             for (int i = 0; i < sd.length; ++i) {
  216.                 for (int j = 0; j < sd[0].length; ++j) {
  217.                     sd[i][j] = 0.5 * (sd1[i][j] + sd2[i][j]);
  218.                 }
  219.             }
  220.             estimated.setStateDerivatives(0, sd);

  221.             // combine uplink and downlink partial derivatives with respect to parameters
  222.             evalOneWay1.getDerivativesDrivers().forEach(driver -> {
  223.                 final double[] pd1 = evalOneWay1.getParameterDerivatives(driver);
  224.                 final double[] pd2 = evalOneWay2.getParameterDerivatives(driver);
  225.                 final double[] pd = new double[pd1.length];
  226.                 for (int i = 0; i < pd.length; ++i) {
  227.                     pd[i] = 0.5 * (pd1[i] + pd2[i]);
  228.                 }
  229.                 estimated.setParameterDerivatives(driver, pd);
  230.             });

  231.         } else {
  232.             estimated = evalOneWay1;
  233.         }

  234.         return estimated;

  235.     }

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

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

  261.         // range rate value
  262.         final FieldVector3D<DerivativeStructure> stationPosition  = stationPV.getPosition();
  263.         final FieldVector3D<DerivativeStructure> relativePosition = stationPosition.subtract(transitPV.getPosition());

  264.         final FieldVector3D<DerivativeStructure> stationVelocity  = stationPV.getVelocity();
  265.         final FieldVector3D<DerivativeStructure> relativeVelocity = stationVelocity.subtract(transitPV.getVelocity());

  266.         // radial direction
  267.         final FieldVector3D<DerivativeStructure> lineOfSight      = relativePosition.normalize();

  268.         // range rate
  269.         final DerivativeStructure rangeRate = FieldVector3D.dotProduct(relativeVelocity, lineOfSight);

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

  271.         // compute partial derivatives of (rr) with respect to spacecraft state Cartesian coordinates
  272.         final double[] derivatives = rangeRate.getAllDerivatives();
  273.         estimated.setStateDerivatives(0, Arrays.copyOfRange(derivatives, 1, 7));

  274.         // set partial derivatives with respect to parameters
  275.         // (beware element at index 0 is the value, not a derivative)
  276.         for (final ParameterDriver driver : getParametersDrivers()) {
  277.             final Integer index = indices.get(driver.getName());
  278.             if (index != null) {
  279.                 estimated.setParameterDerivatives(driver, derivatives[index + 1]);
  280.             }
  281.         }

  282.         return estimated;

  283.     }

  284. }