Range.java

  1. /* Copyright 2002-2022 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.Collections;
  20. import java.util.HashMap;
  21. import java.util.Map;

  22. import org.hipparchus.analysis.differentiation.Gradient;
  23. import org.hipparchus.analysis.differentiation.GradientField;
  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, Collections.singletonList(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 FieldVector3D<Gradient> zero = FieldVector3D.getZero(GradientField.getField(nbParams));

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

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

  152.         // Station position in inertial frame at end of the downlink leg
  153.         final TimeStampedFieldPVCoordinates<Gradient> 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 Gradient tauD = signalTimeOfFlight(pvaDS, stationDownlink.getPosition(), downlinkDateDS);

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

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

  169.         if (twoway) {

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

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

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

  191.         } else {

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

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

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

  205.         }

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

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

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

  218.         return estimated;

  219.     }

  220. }