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

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

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

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

  128.         final SpacecraftState state = states[0];

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

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

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

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

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

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

  163.         // Transit state & Transit state (re)computed with derivative structures
  164.         final DerivativeStructure   delta        = downlinkDateDS.durationFrom(state.getDate());
  165.         final DerivativeStructure   deltaMTauD   = tauD.negate().add(delta);
  166.         final SpacecraftState       transitState = state.shiftedBy(deltaMTauD.getValue());
  167.         final TimeStampedFieldPVCoordinates<DerivativeStructure> transitStateDS = pvaDS.shiftedBy(deltaMTauD);

  168.         // prepare the evaluation
  169.         final EstimatedMeasurement<Range> estimated;
  170.         final DerivativeStructure range;

  171.         if (twoway) {

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

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

  189.             // Range value
  190.             final double              cOver2 = 0.5 * Constants.SPEED_OF_LIGHT;
  191.             final DerivativeStructure tau    = tauD.add(tauU);
  192.             range                            = tau.multiply(cOver2);

  193.         } else {

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

  201.             // Clock offsets
  202.             final ObservableSatellite satellite = getSatellites().get(0);
  203.             final DerivativeStructure dts       = satellite.getClockOffsetDriver().getValue(factory, indices);
  204.             final DerivativeStructure dtg       = station.getClockOffsetDriver().getValue(factory, indices);

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

  207.         }

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

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

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

  220.         return estimated;

  221.     }

  222. }