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

  34. /** Class modeling a range measurement from a ground station or
  35.  * from a satellite.
  36.  * <p>
  37.  * For two-way measurements, the measurement is considered
  38.  * to be a signal emitted from a ground station, reflected
  39.  * on spacecraft, and received on the same ground station.
  40.  * Its value is the elapsed time between emission and reception
  41.  * divided by 2c were c is the speed of light.
  42.  * </p>
  43.  * <p>
  44.  * For one-way measurements, a signal is emitted by the satellite
  45.  * and received by the ground station. The measurement value
  46.  * is the elapsed time between emission and reception divided by
  47.  * the speed of light.
  48.  * </p>
  49.  * <p>
  50.  * The motion of both the station and the
  51.  * spacecraft during the signal flight time are taken into
  52.  * account. The date of the measurement corresponds to the
  53.  * reception on ground of the emitted or reflected signal.
  54.  * </p>
  55.  * @author Thierry Ceolin
  56.  * @author Luc Maisonobe
  57.  * @author Maxime Journot
  58.  * @since 8.0
  59.  */
  60. public class Range extends AbstractMeasurement<Range> {

  61.     /** Ground station from which measurement is performed. */
  62.     private final GroundStation station;

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

  65.     /** Simple constructor.
  66.      * <p>
  67.      * This constructor uses 0 as the index of the propagator related
  68.      * to this measurement, thus being well suited for mono-satellite
  69.      * orbit determination.
  70.      * </p>
  71.      * @param station ground station from which measurement is performed
  72.      * @param date date of the measurement
  73.      * @param range observed value
  74.      * @param sigma theoretical standard deviation
  75.      * @param baseWeight base weight
  76.      * @exception OrekitException if a {@link org.orekit.utils.ParameterDriver}
  77.      * name conflict occurs
  78.      */
  79.     public Range(final GroundStation station, final AbsoluteDate date,
  80.                  final double range, final double sigma, final double baseWeight)
  81.         throws OrekitException {
  82.         this(station, true, date, range, sigma, baseWeight, 0);
  83.     }

  84.     /** Simple constructor.
  85.      * <p>
  86.      * This constructor uses 0 as the index of the propagator related
  87.      * to this measurement, thus being well suited for mono-satellite
  88.      * orbit determination.
  89.      * </p>
  90.      * @param station ground station from which measurement is performed
  91.      * @param date date of the measurement
  92.      * @param range observed value
  93.      * @param sigma theoretical standard deviation
  94.      * @param baseWeight base weight
  95.      * @param twoWay flag indicating whether it is a two-way measurement
  96.      * @exception OrekitException if a {@link org.orekit.utils.ParameterDriver}
  97.      * name conflict occurs
  98.      */
  99.     public Range(final GroundStation station, final AbsoluteDate date, final double range,
  100.                  final double sigma, final double baseWeight, final boolean twoWay)
  101.         throws OrekitException {
  102.         this(station, twoWay, date, range, sigma, baseWeight, 0);
  103.     }

  104.     /** Simple constructor.
  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 propagatorIndex index of the propagator related to this measurement
  111.      * @exception OrekitException if a {@link org.orekit.utils.ParameterDriver}
  112.      * name conflict occurs
  113.      * @since 9.0
  114.      */
  115.     public Range(final GroundStation station, final AbsoluteDate date,
  116.                  final double range, final double sigma, final double baseWeight,
  117.                  final int propagatorIndex)
  118.         throws OrekitException {
  119.         this(station, true, date, range, sigma, baseWeight, 0);
  120.     }

  121.     /** Simple constructor.
  122.      * @param station ground station from which measurement is performed
  123.      * @param twoWay flag indicating whether it is a two-way measurement
  124.      * @param date date of the measurement
  125.      * @param range observed value
  126.      * @param sigma theoretical standard deviation
  127.      * @param baseWeight base weight
  128.      * @param propagatorIndex index of the propagator related to this measurement
  129.      * @exception OrekitException if a {@link org.orekit.utils.ParameterDriver}
  130.      * name conflict occurs
  131.      * @since 9.0
  132.      */
  133.     public Range(final GroundStation station, final boolean twoWay, final AbsoluteDate date,
  134.                  final double range, final double sigma, final double baseWeight,
  135.                  final int propagatorIndex)
  136.         throws OrekitException {
  137.         super(date, range, sigma, baseWeight, Arrays.asList(propagatorIndex),
  138.               station.getEastOffsetDriver(),
  139.               station.getNorthOffsetDriver(),
  140.               station.getZenithOffsetDriver(),
  141.               station.getPrimeMeridianOffsetDriver(),
  142.               station.getPrimeMeridianDriftDriver(),
  143.               station.getPolarOffsetXDriver(),
  144.               station.getPolarDriftXDriver(),
  145.               station.getPolarOffsetYDriver(),
  146.               station.getPolarDriftYDriver());
  147.         this.station = station;
  148.         this.twoway = twoWay;
  149.     }

  150.     /** Get the ground station from which measurement is performed.
  151.      * @return ground station from which measurement is performed
  152.      */
  153.     public GroundStation getStation() {
  154.         return station;
  155.     }

  156.     /** Check if the instance represents a two-way measurement.
  157.      * @return true if the instance represents a two-way measurement
  158.      */
  159.     public boolean isTwoWay() {
  160.         return twoway;
  161.     }

  162.     /** {@inheritDoc} */
  163.     @Override
  164.     protected EstimatedMeasurement<Range> theoreticalEvaluation(final int iteration,
  165.                                                                 final int evaluation,
  166.                                                                 final SpacecraftState[] states)
  167.         throws OrekitException {

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

  169.         // Range derivatives are computed with respect to spacecraft state in inertial frame
  170.         // and station parameters
  171.         // ----------------------
  172.         //
  173.         // Parameters:
  174.         //  - 0..2 - Position of the spacecraft in inertial frame
  175.         //  - 3..5 - Velocity of the spacecraft in inertial frame
  176.         //  - 6..n - station parameters (station offsets, pole, prime meridian...)
  177.         int nbParams = 6;
  178.         final Map<String, Integer> indices = new HashMap<>();
  179.         for (ParameterDriver driver : getParametersDrivers()) {
  180.             if (driver.isSelected()) {
  181.                 indices.put(driver.getName(), nbParams++);
  182.             }
  183.         }
  184.         final DSFactory                          factory = new DSFactory(nbParams, 1);
  185.         final Field<DerivativeStructure>         field   = factory.getDerivativeField();
  186.         final FieldVector3D<DerivativeStructure> zero    = FieldVector3D.getZero(field);

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

  189.         // transform between station and inertial frame, expressed as a derivative structure
  190.         // The components of station's position in offset frame are the 3 last derivative parameters
  191.         final AbsoluteDate downlinkDate = getDate();
  192.         final FieldAbsoluteDate<DerivativeStructure> downlinkDateDS =
  193.                         new FieldAbsoluteDate<>(field, downlinkDate);
  194.         final FieldTransform<DerivativeStructure> offsetToInertialDownlink =
  195.                         station.getOffsetToInertial(state.getFrame(), downlinkDateDS, factory, indices);

  196.         // Station position in inertial frame at end of the downlink leg
  197.         final TimeStampedFieldPVCoordinates<DerivativeStructure> stationDownlink =
  198.                         offsetToInertialDownlink.transformPVCoordinates(new TimeStampedFieldPVCoordinates<>(downlinkDateDS,
  199.                                                                                                             zero, zero, zero));

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

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

  205.         // Transit state & Transit state (re)computed with derivative structures
  206.         final double                delta        = downlinkDate.durationFrom(state.getDate());
  207.         final DerivativeStructure   deltaMTauD   = tauD.negate().add(delta);
  208.         final SpacecraftState       transitState = state.shiftedBy(deltaMTauD.getValue());
  209.         final TimeStampedFieldPVCoordinates<DerivativeStructure> transitStateDS = pvaDS.shiftedBy(deltaMTauD);

  210.         // prepare the evaluation
  211.         final EstimatedMeasurement<Range> estimated;
  212.         final DerivativeStructure range;

  213.         if (twoway) {

  214.             // Station at transit state date (derivatives of tauD taken into account)
  215.             final TimeStampedFieldPVCoordinates<DerivativeStructure> stationAtTransitDate =
  216.                             stationDownlink.shiftedBy(tauD.negate());
  217.             // Uplink delay
  218.             final DerivativeStructure tauU =
  219.                             signalTimeOfFlight(stationAtTransitDate, transitStateDS.getPosition(), transitStateDS.getDate());
  220.             final TimeStampedFieldPVCoordinates<DerivativeStructure> stationUplink =
  221.                             stationDownlink.shiftedBy(-tauD.getValue() - tauU.getValue());

  222.             // Prepare the evaluation
  223.             estimated = new EstimatedMeasurement<Range>(this, iteration, evaluation,
  224.                                                             new SpacecraftState[] {
  225.                                                                 transitState
  226.                                                             }, new TimeStampedPVCoordinates[] {
  227.                                                                 stationUplink.toTimeStampedPVCoordinates(),
  228.                                                                 transitStateDS.toTimeStampedPVCoordinates(),
  229.                                                                 stationDownlink.toTimeStampedPVCoordinates()
  230.                                                             });

  231.             // Range value
  232.             final double              cOver2 = 0.5 * Constants.SPEED_OF_LIGHT;
  233.             final DerivativeStructure tau    = tauD.add(tauU);
  234.             range                            = tau.multiply(cOver2);

  235.         } else {

  236.             estimated = new EstimatedMeasurement<Range>(this, iteration, evaluation,
  237.                             new SpacecraftState[] {
  238.                                 transitState
  239.                             }, new TimeStampedPVCoordinates[] {
  240.                                 transitStateDS.toTimeStampedPVCoordinates(),
  241.                                 stationDownlink.toTimeStampedPVCoordinates()
  242.                             });

  243.             // Range value
  244.             range = tauD.multiply(Constants.SPEED_OF_LIGHT);
  245.         }

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

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

  250.         // set partial derivatives with respect to parameters
  251.         // (beware element at index 0 is the value, not a derivative)
  252.         for (final ParameterDriver driver : getParametersDrivers()) {
  253.             final Integer index = indices.get(driver.getName());
  254.             if (index != null) {
  255.                 estimated.setParameterDerivatives(driver, derivatives[index + 1]);
  256.             }
  257.         }

  258.         return estimated;

  259.     }

  260. }