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

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

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

  79.     /** Simple constructor.
  80.      * @param station ground station from which measurement is performed
  81.      * @param twoWay flag indicating whether it is a two-way measurement
  82.      * @param date date of the measurement
  83.      * @param range observed value
  84.      * @param sigma theoretical standard deviation
  85.      * @param baseWeight base weight
  86.      * @param satellite satellite related to this measurement
  87.      * @since 9.3
  88.      */
  89.     public Range(final GroundStation station, final boolean twoWay, final AbsoluteDate date,
  90.                  final double range, final double sigma, final double baseWeight,
  91.                  final ObservableSatellite satellite) {
  92.         super(date, range, sigma, baseWeight, Arrays.asList(satellite));
  93.         addParameterDriver(station.getClockOffsetDriver());
  94.         addParameterDriver(station.getEastOffsetDriver());
  95.         addParameterDriver(station.getNorthOffsetDriver());
  96.         addParameterDriver(station.getZenithOffsetDriver());
  97.         addParameterDriver(station.getPrimeMeridianOffsetDriver());
  98.         addParameterDriver(station.getPrimeMeridianDriftDriver());
  99.         addParameterDriver(station.getPolarOffsetXDriver());
  100.         addParameterDriver(station.getPolarDriftXDriver());
  101.         addParameterDriver(station.getPolarOffsetYDriver());
  102.         addParameterDriver(station.getPolarDriftYDriver());
  103.         if (!twoWay) {
  104.             // for one way measurements, the satellite clock offset affects the measurement
  105.             addParameterDriver(satellite.getClockOffsetDriver());
  106.         }
  107.         this.station = station;
  108.         this.twoway = twoWay;
  109.     }

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

  116.     /** Check if the instance represents a two-way measurement.
  117.      * @return true if the instance represents a two-way measurement
  118.      */
  119.     public boolean isTwoWay() {
  120.         return twoway;
  121.     }

  122.     /** {@inheritDoc} */
  123.     @Override
  124.     protected EstimatedMeasurement<Range> theoreticalEvaluation(final int iteration,
  125.                                                                 final int evaluation,
  126.                                                                 final SpacecraftState[] states) {

  127.         final SpacecraftState state = states[0];

  128.         // Range derivatives are computed with respect to spacecraft state in inertial frame
  129.         // and station parameters
  130.         // ----------------------
  131.         //
  132.         // Parameters:
  133.         //  - 0..2 - Position of the spacecraft in inertial frame
  134.         //  - 3..5 - Velocity of the spacecraft in inertial frame
  135.         //  - 6..n - measurements parameters (clock offset, station offsets, pole, prime meridian, sat clock offset...)
  136.         int nbParams = 6;
  137.         final Map<String, Integer> indices = new HashMap<>();
  138.         for (ParameterDriver driver : getParametersDrivers()) {
  139.             if (driver.isSelected()) {
  140.                 indices.put(driver.getName(), nbParams++);
  141.             }
  142.         }
  143.         final FieldVector3D<Gradient> zero = FieldVector3D.getZero(GradientField.getField(nbParams));

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

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

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

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

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

  160.         // Transit state & Transit state (re)computed with gradients
  161.         final Gradient        delta        = downlinkDateDS.durationFrom(state.getDate());
  162.         final Gradient        deltaMTauD   = tauD.negate().add(delta);
  163.         final SpacecraftState transitState = state.shiftedBy(deltaMTauD.getValue());
  164.         final TimeStampedFieldPVCoordinates<Gradient> transitStateDS = pvaDS.shiftedBy(deltaMTauD);

  165.         // prepare the evaluation
  166.         final EstimatedMeasurement<Range> estimated;
  167.         final Gradient range;

  168.         if (twoway) {

  169.             // Station at transit state date (derivatives of tauD taken into account)
  170.             final TimeStampedFieldPVCoordinates<Gradient> stationAtTransitDate =
  171.                             stationDownlink.shiftedBy(tauD.negate());
  172.             // Uplink delay
  173.             final Gradient tauU =
  174.                             signalTimeOfFlight(stationAtTransitDate, transitStateDS.getPosition(), transitStateDS.getDate());
  175.             final TimeStampedFieldPVCoordinates<Gradient> stationUplink =
  176.                             stationDownlink.shiftedBy(-tauD.getValue() - tauU.getValue());

  177.             // Prepare the evaluation
  178.             estimated = new EstimatedMeasurement<Range>(this, iteration, evaluation,
  179.                                                             new SpacecraftState[] {
  180.                                                                 transitState
  181.                                                             }, new TimeStampedPVCoordinates[] {
  182.                                                                 stationUplink.toTimeStampedPVCoordinates(),
  183.                                                                 transitStateDS.toTimeStampedPVCoordinates(),
  184.                                                                 stationDownlink.toTimeStampedPVCoordinates()
  185.                                                             });

  186.             // Range value
  187.             final double   cOver2 = 0.5 * Constants.SPEED_OF_LIGHT;
  188.             final Gradient tau    = tauD.add(tauU);
  189.             range                 = tau.multiply(cOver2);

  190.         } else {

  191.             estimated = new EstimatedMeasurement<Range>(this, iteration, evaluation,
  192.                             new SpacecraftState[] {
  193.                                 transitState
  194.                             }, new TimeStampedPVCoordinates[] {
  195.                                 transitStateDS.toTimeStampedPVCoordinates(),
  196.                                 stationDownlink.toTimeStampedPVCoordinates()
  197.                             });

  198.             // Clock offsets
  199.             final ObservableSatellite satellite = getSatellites().get(0);
  200.             final Gradient            dts       = satellite.getClockOffsetDriver().getValue(nbParams, indices);
  201.             final Gradient            dtg       = station.getClockOffsetDriver().getValue(nbParams, indices);

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

  204.         }

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

  206.         // Range partial derivatives with respect to state
  207.         final double[] derivatives = range.getGradient();
  208.         estimated.setStateDerivatives(0, Arrays.copyOfRange(derivatives, 0, 6));

  209.         // set partial derivatives with respect to parameters
  210.         // (beware element at index 0 is the value, not a derivative)
  211.         for (final ParameterDriver driver : getParametersDrivers()) {
  212.             final Integer index = indices.get(driver.getName());
  213.             if (index != null) {
  214.                 estimated.setParameterDerivatives(driver, derivatives[index]);
  215.             }
  216.         }

  217.         return estimated;

  218.     }

  219. }