RangeRate.java

  1. /* Copyright 2002-2018 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.errors.OrekitException;
  26. import org.orekit.frames.FieldTransform;
  27. import org.orekit.propagation.SpacecraftState;
  28. import org.orekit.time.AbsoluteDate;
  29. import org.orekit.time.FieldAbsoluteDate;
  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.      * <p>
  54.      * This constructor uses 0 as the index of the propagator related
  55.      * to this measurement, thus being well suited for mono-satellite
  56.      * orbit determination.
  57.      * </p>
  58.      * @param station ground station from which measurement is performed
  59.      * @param date date of the measurement
  60.      * @param rangeRate observed value, m/s
  61.      * @param sigma theoretical standard deviation
  62.      * @param baseWeight base weight
  63.      * @param twoway if true, this is a two-way measurement
  64.      * @exception OrekitException if a {@link org.orekit.utils.ParameterDriver}
  65.      * name conflict occurs
  66.      */
  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.         throws OrekitException {
  73.         this(station, date, rangeRate, sigma, baseWeight, twoway, 0);
  74.     }

  75.     /** Simple constructor.
  76.      * @param station ground station from which measurement is performed
  77.      * @param date date of the measurement
  78.      * @param rangeRate observed value, m/s
  79.      * @param sigma theoretical standard deviation
  80.      * @param baseWeight base weight
  81.      * @param twoway if true, this is a two-way measurement
  82.      * @param propagatorIndex index of the propagator related to this measurement
  83.      * @exception OrekitException if a {@link org.orekit.utils.ParameterDriver}
  84.      * name conflict occurs
  85.      * @since 9.0
  86.      */
  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.         throws OrekitException {
  94.         super(date, rangeRate, sigma, baseWeight, Arrays.asList(propagatorIndex),
  95.               station.getEastOffsetDriver(),
  96.               station.getNorthOffsetDriver(),
  97.               station.getZenithOffsetDriver(),
  98.               station.getPrimeMeridianOffsetDriver(),
  99.               station.getPrimeMeridianDriftDriver(),
  100.               station.getPolarOffsetXDriver(),
  101.               station.getPolarDriftXDriver(),
  102.               station.getPolarOffsetYDriver(),
  103.               station.getPolarDriftYDriver());
  104.         this.station = station;
  105.         this.twoway  = twoway;
  106.     }

  107.     /** Check if the instance represents a two-way measurement.
  108.      * @return true if the instance represents a two-way measurement
  109.      */
  110.     public boolean isTwoWay() {
  111.         return twoway;
  112.     }

  113.     /** Get the ground station from which measurement is performed.
  114.      * @return ground station from which measurement is performed
  115.      */
  116.     public GroundStation getStation() {
  117.         return station;
  118.     }

  119.     /** {@inheritDoc} */
  120.     @Override
  121.     protected EstimatedMeasurement<RangeRate> theoreticalEvaluation(final int iteration, final int evaluation,
  122.                                                                     final SpacecraftState[] states)
  123.         throws OrekitException {

  124.         final SpacecraftState state = states[getPropagatorsIndices().get(0)];

  125.         // Range-rate derivatives are computed with respect to spacecraft state in inertial frame
  126.         // and station position in station's offset frame
  127.         // -------
  128.         //
  129.         // Parameters:
  130.         //  - 0..2 - Position of the spacecraft in inertial frame
  131.         //  - 3..5 - Velocity of the spacecraft in inertial frame
  132.         //  - 6..n - station parameters (station offsets, pole, prime meridian...)
  133.         int nbParams = 6;
  134.         final Map<String, Integer> indices = new HashMap<>();
  135.         for (ParameterDriver driver : getParametersDrivers()) {
  136.             if (driver.isSelected()) {
  137.                 indices.put(driver.getName(), nbParams++);
  138.             }
  139.         }
  140.         final DSFactory factory = new DSFactory(nbParams, 1);
  141.         final Field<DerivativeStructure> field = factory.getDerivativeField();
  142.         final FieldVector3D<DerivativeStructure> zero = FieldVector3D.getZero(field);

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

  145.         // transform between station and inertial frame, expressed as a derivative structure
  146.         // The components of station's position in offset frame are the 3 last derivative parameters
  147.         final AbsoluteDate downlinkDate = getDate();
  148.         final FieldAbsoluteDate<DerivativeStructure> downlinkDateDS =
  149.                         new FieldAbsoluteDate<>(field, downlinkDate);
  150.         final FieldTransform<DerivativeStructure> offsetToInertialDownlink =
  151.                         station.getOffsetToInertial(state.getFrame(), downlinkDateDS, factory, indices);

  152.         // Station position in inertial frame at end of the downlink leg
  153.         final TimeStampedFieldPVCoordinates<DerivativeStructure> stationDownlink =
  154.                         offsetToInertialDownlink.transformPVCoordinates(new TimeStampedFieldPVCoordinates<>(downlinkDateDS,
  155.                                                                                                             zero, zero, zero));

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

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

  161.         // Transit state
  162.         final double                delta        = downlinkDate.durationFrom(state.getDate());
  163.         final DerivativeStructure   deltaMTauD   = tauD.negate().add(delta);
  164.         final SpacecraftState       transitState = state.shiftedBy(deltaMTauD.getValue());

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

  167.         // one-way (downlink) range-rate
  168.         final EstimatedMeasurement<RangeRate> evalOneWay1 =
  169.                         oneWayTheoreticalEvaluation(iteration, evaluation, true,
  170.                                                     stationDownlink, transitPV, transitState, indices);
  171.         final EstimatedMeasurement<RangeRate> estimated;
  172.         if (twoway) {
  173.             // one-way (uplink) light time correction
  174.             final AbsoluteDate approxUplinkDate = downlinkDate.shiftedBy(-2 * tauD.getValue());
  175.             final FieldAbsoluteDate<DerivativeStructure> approxUplinkDateDS = new FieldAbsoluteDate<>(field, approxUplinkDate);
  176.             final FieldTransform<DerivativeStructure> offsetToInertialApproxUplink =
  177.                             station.getOffsetToInertial(state.getFrame(), approxUplinkDateDS, factory, indices);

  178.             final TimeStampedFieldPVCoordinates<DerivativeStructure> stationApproxUplink =
  179.                             offsetToInertialApproxUplink.transformPVCoordinates(new TimeStampedFieldPVCoordinates<>(approxUplinkDateDS,
  180.                                                                                                                     zero, zero, zero));

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

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

  184.             final EstimatedMeasurement<RangeRate> evalOneWay2 =
  185.                             oneWayTheoreticalEvaluation(iteration, evaluation, false,
  186.                                                         stationUplink, transitPV, transitState, indices);

  187.             // combine uplink and downlink values
  188.             estimated = new EstimatedMeasurement<>(this, iteration, evaluation,
  189.                                                    evalOneWay1.getStates(),
  190.                                                    new TimeStampedPVCoordinates[] {
  191.                                                        evalOneWay2.getParticipants()[0],
  192.                                                        evalOneWay1.getParticipants()[0],
  193.                                                        evalOneWay1.getParticipants()[1]
  194.                                                    });
  195.             estimated.setEstimatedValue(0.5 * (evalOneWay1.getEstimatedValue()[0] + evalOneWay2.getEstimatedValue()[0]));

  196.             // combine uplink and downlink partial derivatives with respect to state
  197.             final double[][] sd1 = evalOneWay1.getStateDerivatives(0);
  198.             final double[][] sd2 = evalOneWay2.getStateDerivatives(0);
  199.             final double[][] sd = new double[sd1.length][sd1[0].length];
  200.             for (int i = 0; i < sd.length; ++i) {
  201.                 for (int j = 0; j < sd[0].length; ++j) {
  202.                     sd[i][j] = 0.5 * (sd1[i][j] + sd2[i][j]);
  203.                 }
  204.             }
  205.             estimated.setStateDerivatives(0, sd);

  206.             // combine uplink and downlink partial derivatives with respect to parameters
  207.             evalOneWay1.getDerivativesDrivers().forEach(driver -> {
  208.                 final double[] pd1 = evalOneWay1.getParameterDerivatives(driver);
  209.                 final double[] pd2 = evalOneWay2.getParameterDerivatives(driver);
  210.                 final double[] pd = new double[pd1.length];
  211.                 for (int i = 0; i < pd.length; ++i) {
  212.                     pd[i] = 0.5 * (pd1[i] + pd2[i]);
  213.                 }
  214.                 estimated.setParameterDerivatives(driver, pd);
  215.             });

  216.         } else {
  217.             estimated = evalOneWay1;
  218.         }

  219.         return estimated;

  220.     }

  221.     /** Evaluate measurement in one-way.
  222.      * @param iteration iteration number
  223.      * @param evaluation evaluations counter
  224.      * @param downlink indicator for downlink leg
  225.      * @param stationPV station coordinates when signal is at station
  226.      * @param transitPV spacecraft coordinates at onboard signal transit
  227.      * @param transitState orbital state at onboard signal transit
  228.      * @param indices indices of the estimated parameters in derivatives computations
  229.      * @return theoretical value
  230.      * @exception OrekitException if value cannot be computed
  231.      * @see #evaluate(SpacecraftStatet)
  232.      */
  233.     private EstimatedMeasurement<RangeRate> oneWayTheoreticalEvaluation(final int iteration, final int evaluation, final boolean downlink,
  234.                                                                         final TimeStampedFieldPVCoordinates<DerivativeStructure> stationPV,
  235.                                                                         final TimeStampedFieldPVCoordinates<DerivativeStructure> transitPV,
  236.                                                                         final SpacecraftState transitState,
  237.                                                                         final Map<String, Integer> indices)
  238.         throws OrekitException {

  239.         // prepare the evaluation
  240.         final EstimatedMeasurement<RangeRate> estimated =
  241.                         new EstimatedMeasurement<RangeRate>(this, iteration, evaluation,
  242.                                                             new SpacecraftState[] {
  243.                                                                 transitState
  244.                                                             }, new TimeStampedPVCoordinates[] {
  245.                                                                 (downlink ? transitPV : stationPV).toTimeStampedPVCoordinates(),
  246.                                                                 (downlink ? stationPV : transitPV).toTimeStampedPVCoordinates()
  247.                                                             });

  248.         // range rate value
  249.         final FieldVector3D<DerivativeStructure> stationPosition  = stationPV.getPosition();
  250.         final FieldVector3D<DerivativeStructure> relativePosition = stationPosition.subtract(transitPV.getPosition());

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

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

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

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

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

  261.         // set partial derivatives with respect to parameters
  262.         // (beware element at index 0 is the value, not a derivative)
  263.         for (final ParameterDriver driver : getParametersDrivers()) {
  264.             final Integer index = indices.get(driver.getName());
  265.             if (index != null) {
  266.                 estimated.setParameterDerivatives(driver, derivatives[index + 1]);
  267.             }
  268.         }

  269.         return estimated;

  270.     }

  271. }