Range.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.Constants;
  30. import org.orekit.utils.ParameterDriver;
  31. import org.orekit.utils.TimeStampedFieldPVCoordinates;
  32. import org.orekit.utils.TimeStampedPVCoordinates;

  33. /** Class modeling a range measurement from a ground station.
  34.  * <p>
  35.  * For one-way measurements, a signal is emitted by the satellite
  36.  * and received by the ground station. The measurement value is the
  37.  * elapsed time between emission and reception multiplied by c where
  38.  * c is the speed of light.
  39.  * </p>
  40.  * <p>
  41.  * For two-way measurements, the measurement is considered to be a signal
  42.  * emitted from a ground station, reflected on spacecraft, and received
  43.  * on the same ground station. Its value is the elapsed time between
  44.  * emission and reception multiplied by c/2 where c is the speed of light.
  45.  * </p>
  46.  * <p>
  47.  * The motion of both the station and the spacecraft during the signal
  48.  * flight time are taken into account. The date of the measurement
  49.  * corresponds to the reception on ground of the emitted or reflected signal.
  50.  * </p>
  51.  * <p>
  52.  * The clock offsets of both the ground station and the satellite are taken
  53.  * into account. These offsets correspond to the values that must be subtracted
  54.  * from station (resp. satellite) reading of time to compute the real physical
  55.  * date. These offsets have two effects:
  56.  * </p>
  57.  * <ul>
  58.  *   <li>as measurement date is evaluated at reception time, the real physical date
  59.  *   of the measurement is the observed date to which the receiving ground station
  60.  *   clock offset is subtracted</li>
  61.  *   <li>as range is evaluated using the total signal time of flight, for one-way
  62.  *   measurements the observed range is the real physical signal time of flight to
  63.  *   which (Δtg - Δts) ⨉ c is added, where Δtg (resp. Δts) is the clock offset for the
  64.  *   receiving ground station (resp. emitting satellite). A similar effect exists in
  65.  *   two-way measurements but it is computed as (Δtg - Δtg) ⨉ c / 2 as the same ground
  66.  *   station clock is used for initial emission and final reception and therefore it evaluates
  67.  *   to zero.</li>
  68.  * </ul>
  69.  * <p>
  70.  * @author Thierry Ceolin
  71.  * @author Luc Maisonobe
  72.  * @author Maxime Journot
  73.  * @since 8.0
  74.  */
  75. public class Range extends AbstractMeasurement<Range> {

  76.     /** Ground station from which measurement is performed. */
  77.     private final GroundStation station;

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

  80.     /** Simple constructor.
  81.      * <p>
  82.      * This constructor uses 0 as the index of the propagator related
  83.      * to this measurement, thus being well suited for mono-satellite
  84.      * orbit determination.
  85.      * </p>
  86.      * @param station ground station from which measurement is performed
  87.      * @param date date of the measurement
  88.      * @param range observed value
  89.      * @param sigma theoretical standard deviation
  90.      * @param baseWeight base weight
  91.      * @deprecated as of 9.3, replaced by {@link #Range(GroundStation, boolean, AbsoluteDate,
  92.      * double, double, double, ObservableSatellite)}
  93.      */
  94.     @Deprecated
  95.     public Range(final GroundStation station, final AbsoluteDate date,
  96.                  final double range, final double sigma, final double baseWeight) {
  97.         this(station, true, date, range, sigma, baseWeight, new ObservableSatellite(0));
  98.     }

  99.     /** Simple constructor.
  100.      * <p>
  101.      * This constructor uses 0 as the index of the propagator related
  102.      * to this measurement, thus being well suited for mono-satellite
  103.      * orbit determination.
  104.      * </p>
  105.      * @param station ground station from which measurement is performed
  106.      * @param date date of the measurement
  107.      * @param range observed value
  108.      * @param sigma theoretical standard deviation
  109.      * @param baseWeight base weight
  110.      * @param twoWay flag indicating whether it is a two-way measurement
  111.      * @deprecated as of 9.3, replaced by {@link #Range(GroundStation, boolean, AbsoluteDate,
  112.      * double, double, double, ObservableSatellite)}
  113.      */
  114.     @Deprecated
  115.     public Range(final GroundStation station, final AbsoluteDate date, final double range,
  116.                  final double sigma, final double baseWeight, final boolean twoWay) {
  117.         this(station, twoWay, date, range, sigma, baseWeight, new ObservableSatellite(0));
  118.     }

  119.     /** Simple constructor.
  120.      * @param station ground station from which measurement is performed
  121.      * @param date date of the measurement
  122.      * @param range observed value
  123.      * @param sigma theoretical standard deviation
  124.      * @param baseWeight base weight
  125.      * @param propagatorIndex index of the propagator related to this measurement
  126.      * @deprecated as of 9.3, replaced by {@link #Range(GroundStation, boolean, AbsoluteDate,
  127.      * double, double, double, ObservableSatellite)}
  128.      */
  129.     @Deprecated
  130.     public Range(final GroundStation station, final AbsoluteDate date,
  131.                  final double range, final double sigma, final double baseWeight,
  132.                  final int propagatorIndex) {
  133.         this(station, true, date, range, sigma, baseWeight, new ObservableSatellite(0));
  134.     }

  135.     /** Simple constructor.
  136.      * @param station ground station from which measurement is performed
  137.      * @param twoWay flag indicating whether it is a two-way measurement
  138.      * @param date date of the measurement
  139.      * @param range observed value
  140.      * @param sigma theoretical standard deviation
  141.      * @param baseWeight base weight
  142.      * @param propagatorIndex index of the propagator related to this measurement
  143.      * @since 9.0
  144.      * @deprecated as of 9.3, replaced by {@link #Range(GroundStation, boolean, AbsoluteDate,
  145.      * double, double, double, ObservableSatellite)}
  146.      */
  147.     @Deprecated
  148.     public Range(final GroundStation station, final boolean twoWay, final AbsoluteDate date,
  149.                  final double range, final double sigma, final double baseWeight,
  150.                  final int propagatorIndex) {
  151.         this(station, twoWay, date, range, sigma, baseWeight, new ObservableSatellite(propagatorIndex));
  152.     }

  153.     /** Simple constructor.
  154.      * @param station ground station from which measurement is performed
  155.      * @param twoWay flag indicating whether it is a two-way measurement
  156.      * @param date date of the measurement
  157.      * @param range observed value
  158.      * @param sigma theoretical standard deviation
  159.      * @param baseWeight base weight
  160.      * @param satellite satellite related to this measurement
  161.      * @since 9.3
  162.      */
  163.     public Range(final GroundStation station, final boolean twoWay, final AbsoluteDate date,
  164.                  final double range, final double sigma, final double baseWeight,
  165.                  final ObservableSatellite satellite) {
  166.         super(date, range, sigma, baseWeight, Arrays.asList(satellite));
  167.         addParameterDriver(station.getClockOffsetDriver());
  168.         addParameterDriver(station.getEastOffsetDriver());
  169.         addParameterDriver(station.getNorthOffsetDriver());
  170.         addParameterDriver(station.getZenithOffsetDriver());
  171.         addParameterDriver(station.getPrimeMeridianOffsetDriver());
  172.         addParameterDriver(station.getPrimeMeridianDriftDriver());
  173.         addParameterDriver(station.getPolarOffsetXDriver());
  174.         addParameterDriver(station.getPolarDriftXDriver());
  175.         addParameterDriver(station.getPolarOffsetYDriver());
  176.         addParameterDriver(station.getPolarDriftYDriver());
  177.         if (!twoWay) {
  178.             // for one way measurements, the satellite clock offset affects the measurement
  179.             addParameterDriver(satellite.getClockOffsetDriver());
  180.         }
  181.         this.station = station;
  182.         this.twoway = twoWay;
  183.     }

  184.     /** Get the ground station from which measurement is performed.
  185.      * @return ground station from which measurement is performed
  186.      */
  187.     public GroundStation getStation() {
  188.         return station;
  189.     }

  190.     /** Check if the instance represents a two-way measurement.
  191.      * @return true if the instance represents a two-way measurement
  192.      */
  193.     public boolean isTwoWay() {
  194.         return twoway;
  195.     }

  196.     /** {@inheritDoc} */
  197.     @Override
  198.     protected EstimatedMeasurement<Range> theoreticalEvaluation(final int iteration,
  199.                                                                 final int evaluation,
  200.                                                                 final SpacecraftState[] states) {

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

  203.         // Range derivatives are computed with respect to spacecraft state in inertial frame
  204.         // and station parameters
  205.         // ----------------------
  206.         //
  207.         // Parameters:
  208.         //  - 0..2 - Position of the spacecraft in inertial frame
  209.         //  - 3..5 - Velocity of the spacecraft in inertial frame
  210.         //  - 6..n - measurements parameters (clock offset, station offsets, pole, prime meridian, sat clock offset...)
  211.         int nbParams = 6;
  212.         final Map<String, Integer> indices = new HashMap<>();
  213.         for (ParameterDriver driver : getParametersDrivers()) {
  214.             if (driver.isSelected()) {
  215.                 indices.put(driver.getName(), nbParams++);
  216.             }
  217.         }
  218.         final DSFactory                          factory = new DSFactory(nbParams, 1);
  219.         final Field<DerivativeStructure>         field   = factory.getDerivativeField();
  220.         final FieldVector3D<DerivativeStructure> zero    = FieldVector3D.getZero(field);

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

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

  228.         // Station position in inertial frame at end of the downlink leg
  229.         final TimeStampedFieldPVCoordinates<DerivativeStructure> stationDownlink =
  230.                         offsetToInertialDownlink.transformPVCoordinates(new TimeStampedFieldPVCoordinates<>(downlinkDateDS,
  231.                                                                                                             zero, zero, zero));

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

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

  237.         // Transit state & Transit state (re)computed with derivative structures
  238.         final DerivativeStructure   delta        = downlinkDateDS.durationFrom(state.getDate());
  239.         final DerivativeStructure   deltaMTauD   = tauD.negate().add(delta);
  240.         final SpacecraftState       transitState = state.shiftedBy(deltaMTauD.getValue());
  241.         final TimeStampedFieldPVCoordinates<DerivativeStructure> transitStateDS = pvaDS.shiftedBy(deltaMTauD);

  242.         // prepare the evaluation
  243.         final EstimatedMeasurement<Range> estimated;
  244.         final DerivativeStructure range;

  245.         if (twoway) {

  246.             // Station at transit state date (derivatives of tauD taken into account)
  247.             final TimeStampedFieldPVCoordinates<DerivativeStructure> stationAtTransitDate =
  248.                             stationDownlink.shiftedBy(tauD.negate());
  249.             // Uplink delay
  250.             final DerivativeStructure tauU =
  251.                             signalTimeOfFlight(stationAtTransitDate, transitStateDS.getPosition(), transitStateDS.getDate());
  252.             final TimeStampedFieldPVCoordinates<DerivativeStructure> stationUplink =
  253.                             stationDownlink.shiftedBy(-tauD.getValue() - tauU.getValue());

  254.             // Prepare the evaluation
  255.             estimated = new EstimatedMeasurement<Range>(this, iteration, evaluation,
  256.                                                             new SpacecraftState[] {
  257.                                                                 transitState
  258.                                                             }, new TimeStampedPVCoordinates[] {
  259.                                                                 stationUplink.toTimeStampedPVCoordinates(),
  260.                                                                 transitStateDS.toTimeStampedPVCoordinates(),
  261.                                                                 stationDownlink.toTimeStampedPVCoordinates()
  262.                                                             });

  263.             // Range value
  264.             final double              cOver2 = 0.5 * Constants.SPEED_OF_LIGHT;
  265.             final DerivativeStructure tau    = tauD.add(tauU);
  266.             range                            = tau.multiply(cOver2);

  267.         } else {

  268.             estimated = new EstimatedMeasurement<Range>(this, iteration, evaluation,
  269.                             new SpacecraftState[] {
  270.                                 transitState
  271.                             }, new TimeStampedPVCoordinates[] {
  272.                                 transitStateDS.toTimeStampedPVCoordinates(),
  273.                                 stationDownlink.toTimeStampedPVCoordinates()
  274.                             });

  275.             // Clock offsets
  276.             final DerivativeStructure dtg = station.getClockOffsetDriver().getValue(factory, indices);
  277.             final DerivativeStructure dts = satellite.getClockOffsetDriver().getValue(factory, indices);

  278.             // Range value
  279.             range = tauD.add(dtg).subtract(dts).multiply(Constants.SPEED_OF_LIGHT);

  280.         }

  281.         estimated.setEstimatedValue(range.getValue());

  282.         // Range partial derivatives with respect to state
  283.         final double[] derivatives = range.getAllDerivatives();
  284.         estimated.setStateDerivatives(0, Arrays.copyOfRange(derivatives, 1, 7));

  285.         // set partial derivatives with respect to parameters
  286.         // (beware element at index 0 is the value, not a derivative)
  287.         for (final ParameterDriver driver : getParametersDrivers()) {
  288.             final Integer index = indices.get(driver.getName());
  289.             if (index != null) {
  290.                 estimated.setParameterDerivatives(driver, derivatives[index + 1]);
  291.             }
  292.         }

  293.         return estimated;

  294.     }

  295. }