Range.java

  1. /* Copyright 2002-2017 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.
  35.  * <p>
  36.  * The measurement is considered to be a signal emitted from
  37.  * a ground station, reflected on spacecraft, and received
  38.  * on the same ground station. Its value is the elapsed time
  39.  * between emission and reception divided by 2c were c is the
  40.  * speed of light. The motion of both the station and the
  41.  * spacecraft during the signal flight time are taken into
  42.  * account. The date of the measurement corresponds to the
  43.  * reception on ground of the reflected signal.
  44.  * </p>
  45.  * @author Thierry Ceolin
  46.  * @author Luc Maisonobe
  47.  * @author Maxime Journot
  48.  * @since 8.0
  49.  */
  50. public class Range extends AbstractMeasurement<Range> {

  51.     /** Ground station from which measurement is performed. */
  52.     private final GroundStation station;

  53.     /** Simple constructor.
  54.      * <p>
  55.      * This constructor uses 0 as the index of the propagator related
  56.      * to this measurement, thus being well suited for mono-satellite
  57.      * orbit determination.
  58.      * </p>
  59.      * @param station ground station from which measurement is performed
  60.      * @param date date of the measurement
  61.      * @param range observed value
  62.      * @param sigma theoretical standard deviation
  63.      * @param baseWeight base weight
  64.      * @exception OrekitException if a {@link org.orekit.utils.ParameterDriver}
  65.      * name conflict occurs
  66.      */
  67.     public Range(final GroundStation station, final AbsoluteDate date,
  68.                  final double range, final double sigma, final double baseWeight)
  69.         throws OrekitException {
  70.         this(station, date, range, sigma, baseWeight, 0);
  71.     }

  72.     /** Simple constructor.
  73.      * @param station ground station from which measurement is performed
  74.      * @param date date of the measurement
  75.      * @param range observed value
  76.      * @param sigma theoretical standard deviation
  77.      * @param baseWeight base weight
  78.      * @param propagatorIndex index of the propagator related to this measurement
  79.      * @exception OrekitException if a {@link org.orekit.utils.ParameterDriver}
  80.      * name conflict occurs
  81.      * @since 9.0
  82.      */
  83.     public Range(final GroundStation station, final AbsoluteDate date,
  84.                  final double range, final double sigma, final double baseWeight,
  85.                  final int propagatorIndex)
  86.         throws OrekitException {
  87.         super(date, range, sigma, baseWeight, Arrays.asList(propagatorIndex),
  88.               station.getEastOffsetDriver(),
  89.               station.getNorthOffsetDriver(),
  90.               station.getZenithOffsetDriver(),
  91.               station.getPrimeMeridianOffsetDriver(),
  92.               station.getPrimeMeridianDriftDriver(),
  93.               station.getPolarOffsetXDriver(),
  94.               station.getPolarDriftXDriver(),
  95.               station.getPolarOffsetYDriver(),
  96.               station.getPolarDriftYDriver());
  97.         this.station = station;
  98.     }

  99.     /** Get the ground station from which measurement is performed.
  100.      * @return ground station from which measurement is performed
  101.      */
  102.     public GroundStation getStation() {
  103.         return station;
  104.     }

  105.     /** {@inheritDoc} */
  106.     @Override
  107.     protected EstimatedMeasurement<Range> theoreticalEvaluation(final int iteration,
  108.                                                                 final int evaluation,
  109.                                                                 final SpacecraftState[] states)
  110.         throws OrekitException {

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

  112.         // Range derivatives are computed with respect to spacecraft state in inertial frame
  113.         // and station parameters
  114.         // ----------------------
  115.         //
  116.         // Parameters:
  117.         //  - 0..2 - Position of the spacecraft in inertial frame
  118.         //  - 3..5 - Velocity of the spacecraft in inertial frame
  119.         //  - 6..n - station parameters (station offsets, pole, prime meridian...)
  120.         int nbParams = 6;
  121.         final Map<String, Integer> indices = new HashMap<>();
  122.         for (ParameterDriver driver : getParametersDrivers()) {
  123.             if (driver.isSelected()) {
  124.                 indices.put(driver.getName(), nbParams++);
  125.             }
  126.         }
  127.         final DSFactory                          factory = new DSFactory(nbParams, 1);
  128.         final Field<DerivativeStructure>         field   = factory.getDerivativeField();
  129.         final FieldVector3D<DerivativeStructure> zero    = FieldVector3D.getZero(field);

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

  132.         // transform between station and inertial frame, expressed as a derivative structure
  133.         // The components of station's position in offset frame are the 3 last derivative parameters
  134.         final AbsoluteDate downlinkDate = getDate();
  135.         final FieldAbsoluteDate<DerivativeStructure> downlinkDateDS =
  136.                         new FieldAbsoluteDate<>(field, downlinkDate);
  137.         final FieldTransform<DerivativeStructure> offsetToInertialDownlink =
  138.                         station.getOffsetToInertial(state.getFrame(), downlinkDateDS, factory, indices);

  139.         // Station position in inertial frame at end of the downlink leg
  140.         final TimeStampedFieldPVCoordinates<DerivativeStructure> stationDownlink =
  141.                         offsetToInertialDownlink.transformPVCoordinates(new TimeStampedFieldPVCoordinates<>(downlinkDateDS,
  142.                                                                                                             zero, zero, zero));

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

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

  148.         // Transit state
  149.         final double                delta        = downlinkDate.durationFrom(state.getDate());
  150.         final DerivativeStructure   deltaMTauD   = tauD.negate().add(delta);
  151.         final SpacecraftState       transitState = state.shiftedBy(deltaMTauD.getValue());

  152.         // Transit state (re)computed with derivative structures
  153.         final TimeStampedFieldPVCoordinates<DerivativeStructure> transitStateDS = pvaDS.shiftedBy(deltaMTauD);

  154.         // Station at transit state date (derivatives of tauD taken into account)
  155.         final TimeStampedFieldPVCoordinates<DerivativeStructure> stationAtTransitDate =
  156.                         stationDownlink.shiftedBy(tauD.negate());

  157.         // Uplink delay
  158.         final DerivativeStructure tauU =
  159.                         signalTimeOfFlight(stationAtTransitDate, transitStateDS.getPosition(), transitStateDS.getDate());
  160.         final TimeStampedFieldPVCoordinates<DerivativeStructure> stationUplink =
  161.                         stationDownlink.shiftedBy(-tauD.getValue() - tauU.getValue());

  162.         // Prepare the evaluation
  163.         final EstimatedMeasurement<Range> estimated =
  164.                         new EstimatedMeasurement<Range>(this, iteration, evaluation,
  165.                                                         new SpacecraftState[] {
  166.                                                             transitState
  167.                                                         }, new TimeStampedPVCoordinates[] {
  168.                                                             stationUplink.toTimeStampedPVCoordinates(),
  169.                                                             transitStateDS.toTimeStampedPVCoordinates(),
  170.                                                             stationDownlink.toTimeStampedPVCoordinates()
  171.                                                         });

  172.         // Range value
  173.         final double              cOver2 = 0.5 * Constants.SPEED_OF_LIGHT;
  174.         final DerivativeStructure tau    = tauD.add(tauU);
  175.         final DerivativeStructure range  = tau.multiply(cOver2);
  176.         estimated.setEstimatedValue(range.getValue());

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

  180.         // set partial derivatives with respect to parameters
  181.         // (beware element at index 0 is the value, not a derivative)
  182.         for (final ParameterDriver driver : getParametersDrivers()) {
  183.             final Integer index = indices.get(driver.getName());
  184.             if (index != null) {
  185.                 estimated.setParameterDerivatives(driver, derivatives[index + 1]);
  186.             }
  187.         }

  188.         return estimated;

  189.     }

  190. }