InterSatellitesRange.java

  1. /* Copyright 2002-2024 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.orekit.propagation.SpacecraftState;
  23. import org.orekit.time.AbsoluteDate;
  24. import org.orekit.time.FieldAbsoluteDate;
  25. import org.orekit.utils.Constants;
  26. import org.orekit.utils.ParameterDriver;
  27. import org.orekit.utils.TimeStampedFieldPVCoordinates;
  28. import org.orekit.utils.TimeStampedPVCoordinates;
  29. import org.orekit.utils.TimeSpanMap.Span;

  30. /** One-way or two-way range measurements between two satellites.
  31.  * <p>
  32.  * For one-way measurements, a signal is emitted by a remote satellite and received
  33.  * by local satellite. The measurement value is the elapsed time between emission
  34.  * and reception multiplied by c where c is the speed of light.
  35.  * </p>
  36.  * <p>
  37.  * For two-way measurements, a signal is emitted by local satellite, reflected on
  38.  * remote satellite, and received back by local satellite. The measurement value
  39.  * is the elapsed time between emission and reception multiplied by c/2 where c
  40.  * is the speed of light.
  41.  * </p>
  42.  * <p>
  43.  * Since 9.3, this class also uses the clock offsets of both satellites,
  44.  * which manage the value that must be added to each satellite reading of time to
  45.  * compute the real physical date. In this measurement, these offsets have two effects:
  46.  * </p>
  47.  * <ul>
  48.  *   <li>as measurement date is evaluated at reception time, the real physical date
  49.  *   of the measurement is the observed date to which the local satellite clock
  50.  *   offset is subtracted</li>
  51.  *   <li>as range is evaluated using the total signal time of flight, for one-way
  52.  *   measurements the observed range is the real physical signal time of flight to
  53.  *   which (Δtl - Δtr) ⨉ c is added, where Δtl (resp. Δtr) is the clock offset for the
  54.  *   local satellite (resp. remote satellite). A similar effect exists in
  55.  *   two-way measurements but it is computed as (Δtl - Δtl) ⨉ c / 2 as the local satellite
  56.  *   clock is used for both initial emission and final reception and therefore it evaluates
  57.  *   to zero.</li>
  58.  * </ul>
  59.  * <p>
  60.  * The motion of both satellites during the signal flight time is
  61.  * taken into account. The date of the measurement corresponds to
  62.  * the reception of the signal by satellite 1.
  63.  * </p>
  64.  * @author Luc Maisonobe
  65.  * @since 9.0
  66.  */
  67. public class InterSatellitesRange extends AbstractMeasurement<InterSatellitesRange> {

  68.     /** Type of the measurement. */
  69.     public static final String MEASUREMENT_TYPE = "InterSatellitesRange";

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

  72.     /** Simple constructor.
  73.      * @param local satellite which receives the signal and performs the measurement
  74.      * @param remote satellite which simply emits the signal in the one-way case,
  75.      * or reflects the signal in the two-way case
  76.      * @param twoWay flag indicating whether it is a two-way measurement
  77.      * @param date date of the measurement
  78.      * @param range observed value
  79.      * @param sigma theoretical standard deviation
  80.      * @param baseWeight base weight
  81.      * @since 9.3
  82.      */
  83.     public InterSatellitesRange(final ObservableSatellite local,
  84.                                 final ObservableSatellite remote,
  85.                                 final boolean twoWay,
  86.                                 final AbsoluteDate date, final double range,
  87.                                 final double sigma, final double baseWeight) {
  88.         super(date, range, sigma, baseWeight, Arrays.asList(local, remote));
  89.         // for one way and two ways measurements, the local satellite clock offsets affects the measurement
  90.         addParameterDriver(local.getClockOffsetDriver());
  91.         if (!twoWay) {
  92.             // for one way measurements, the remote satellite clock offsets also affects the measurement
  93.             addParameterDriver(remote.getClockOffsetDriver());
  94.         }
  95.         this.twoway = twoWay;
  96.     }

  97.     /** Check if the instance represents a two-way measurement.
  98.      * @return true if the instance represents a two-way measurement
  99.      */
  100.     public boolean isTwoWay() {
  101.         return twoway;
  102.     }

  103.     /** {@inheritDoc} */
  104.     @Override
  105.     protected EstimatedMeasurementBase<InterSatellitesRange> theoreticalEvaluationWithoutDerivatives(final int iteration,
  106.                                                                                                      final int evaluation,
  107.                                                                                                      final SpacecraftState[] states) {

  108.         // coordinates of both satellites
  109.         final SpacecraftState local = states[0];
  110.         final TimeStampedPVCoordinates pvaL = local.getPVCoordinates();
  111.         final SpacecraftState remote = states[1];
  112.         final TimeStampedPVCoordinates pvaR = remote.getPVCoordinates();

  113.         // compute propagation times
  114.         // (if state has already been set up to pre-compensate propagation delay,
  115.         //  we will have delta == tauD and transitState will be the same as state)

  116.         // downlink delay
  117.         final double dtl = getSatellites().get(0).getClockOffsetDriver().getValue(local.getDate());
  118.         final AbsoluteDate arrivalDate = getDate().shiftedBy(-dtl);

  119.         final TimeStampedPVCoordinates s1Downlink =
  120.                         pvaL.shiftedBy(arrivalDate.durationFrom(pvaL.getDate()));
  121.         final double tauD = signalTimeOfFlight(pvaR, s1Downlink.getPosition(), arrivalDate);

  122.         // Transit state
  123.         final double delta      = getDate().durationFrom(remote.getDate());
  124.         final double deltaMTauD = delta - tauD;

  125.         // prepare the evaluation
  126.         final EstimatedMeasurementBase<InterSatellitesRange> estimated;

  127.         final double range;
  128.         if (twoway) {
  129.             // Transit state (re)computed with derivative structures
  130.             final TimeStampedPVCoordinates transitState = pvaR.shiftedBy(deltaMTauD);

  131.             // uplink delay
  132.             final double tauU = signalTimeOfFlight(pvaL,
  133.                                                    transitState.getPosition(),
  134.                                                    transitState.getDate());
  135.             estimated = new EstimatedMeasurementBase<>(this, iteration, evaluation,
  136.                                                        new SpacecraftState[] {
  137.                                                            local.shiftedBy(deltaMTauD),
  138.                                                            remote.shiftedBy(deltaMTauD)
  139.                                                        }, new TimeStampedPVCoordinates[] {
  140.                                                            local.shiftedBy(delta - tauD - tauU).getPVCoordinates(),
  141.                                                            remote.shiftedBy(delta - tauD).getPVCoordinates(),
  142.                                                            local.shiftedBy(delta).getPVCoordinates()
  143.                                                        });

  144.             // Range value
  145.             range  = (tauD + tauU) * (0.5 * Constants.SPEED_OF_LIGHT);

  146.         } else {

  147.             estimated = new EstimatedMeasurementBase<>(this, iteration, evaluation,
  148.                                                        new SpacecraftState[] {
  149.                                                            local.shiftedBy(deltaMTauD),
  150.                                                            remote.shiftedBy(deltaMTauD)
  151.                                                        }, new TimeStampedPVCoordinates[] {
  152.                                                            remote.shiftedBy(delta - tauD).getPVCoordinates(),
  153.                                                            local.shiftedBy(delta).getPVCoordinates()
  154.                                                        });

  155.             // Clock offsets
  156.             final double dtr = getSatellites().get(1).getClockOffsetDriver().getValue(remote.getDate());

  157.             // Range value
  158.             range  = (tauD + dtl - dtr) * Constants.SPEED_OF_LIGHT;

  159.         }
  160.         estimated.setEstimatedValue(range);

  161.         return estimated;

  162.     }

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

  168.         // Range derivatives are computed with respect to spacecrafts states in inertial frame
  169.         // ----------------------
  170.         //
  171.         // Parameters:
  172.         //  - 0..2  - Position of the receiver satellite in inertial frame
  173.         //  - 3..5  - Velocity of the receiver satellite in inertial frame
  174.         //  - 6..8  - Position of the remote satellite in inertial frame
  175.         //  - 9..11 - Velocity of the remote satellite in inertial frame
  176.         //  - 12..  - Measurement parameters: local clock offset, remote clock offset...
  177.         int nbParams = 12;
  178.         final Map<String, Integer> indices = new HashMap<>();
  179.         for (ParameterDriver driver : getParametersDrivers()) {
  180.             if (driver.isSelected()) {
  181.                 for (Span<String> span = driver.getNamesSpanMap().getFirstSpan(); span != null; span = span.next()) {

  182.                     if (!indices.containsKey(span.getData())) {
  183.                         indices.put(span.getData(), nbParams++);
  184.                     }
  185.                 }
  186.             }
  187.         }

  188.         // coordinates of both satellites
  189.         final SpacecraftState local = states[0];
  190.         final TimeStampedFieldPVCoordinates<Gradient> pvaL = getCoordinates(local, 0, nbParams);
  191.         final SpacecraftState remote = states[1];
  192.         final TimeStampedFieldPVCoordinates<Gradient> pvaR = getCoordinates(remote, 6, nbParams);

  193.         // compute propagation times
  194.         // (if state has already been set up to pre-compensate propagation delay,
  195.         //  we will have delta == tauD and transitState will be the same as state)

  196.         // downlink delay
  197.         final Gradient dtl = getSatellites().get(0).getClockOffsetDriver().getValue(nbParams, indices, local.getDate());
  198.         final FieldAbsoluteDate<Gradient> arrivalDate =
  199.                         new FieldAbsoluteDate<>(getDate(), dtl.negate());

  200.         final TimeStampedFieldPVCoordinates<Gradient> s1Downlink =
  201.                         pvaL.shiftedBy(arrivalDate.durationFrom(pvaL.getDate()));
  202.         final Gradient tauD = signalTimeOfFlight(pvaR, s1Downlink.getPosition(), arrivalDate);

  203.         // Transit state
  204.         final double              delta      = getDate().durationFrom(remote.getDate());
  205.         final Gradient deltaMTauD = tauD.negate().add(delta);

  206.         // prepare the evaluation
  207.         final EstimatedMeasurement<InterSatellitesRange> estimated;

  208.         final Gradient range;
  209.         if (twoway) {
  210.             // Transit state (re)computed with derivative structures
  211.             final TimeStampedFieldPVCoordinates<Gradient> transitStateDS = pvaR.shiftedBy(deltaMTauD);

  212.             // uplink delay
  213.             final Gradient tauU = signalTimeOfFlight(pvaL,
  214.                                                      transitStateDS.getPosition(),
  215.                                                      transitStateDS.getDate());
  216.             estimated = new EstimatedMeasurement<>(this, iteration, evaluation,
  217.                                                    new SpacecraftState[] {
  218.                                                        local.shiftedBy(deltaMTauD.getValue()),
  219.                                                        remote.shiftedBy(deltaMTauD.getValue())
  220.                                                    }, new TimeStampedPVCoordinates[] {
  221.                                                        local.shiftedBy(delta - tauD.getValue() - tauU.getValue()).getPVCoordinates(),
  222.                                                        remote.shiftedBy(delta - tauD.getValue()).getPVCoordinates(),
  223.                                                        local.shiftedBy(delta).getPVCoordinates()
  224.                                                    });

  225.             // Range value
  226.             range  = tauD.add(tauU).multiply(0.5 * Constants.SPEED_OF_LIGHT);

  227.         } else {

  228.             estimated = new EstimatedMeasurement<>(this, iteration, evaluation,
  229.                                                    new SpacecraftState[] {
  230.                                                        local.shiftedBy(deltaMTauD.getValue()),
  231.                                                        remote.shiftedBy(deltaMTauD.getValue())
  232.                                                    }, new TimeStampedPVCoordinates[] {
  233.                                                        remote.shiftedBy(delta - tauD.getValue()).getPVCoordinates(),
  234.                                                        local.shiftedBy(delta).getPVCoordinates()
  235.                                                    });

  236.             // Clock offsets
  237.             final Gradient dtr = getSatellites().get(1).getClockOffsetDriver().getValue(nbParams, indices, remote.getDate());

  238.             // Range value
  239.             range  = tauD.add(dtl).subtract(dtr).multiply(Constants.SPEED_OF_LIGHT);

  240.         }
  241.         estimated.setEstimatedValue(range.getValue());

  242.         // Range partial derivatives with respect to states
  243.         final double[] derivatives = range.getGradient();
  244.         estimated.setStateDerivatives(0, Arrays.copyOfRange(derivatives, 0,  6));
  245.         estimated.setStateDerivatives(1, Arrays.copyOfRange(derivatives, 6, 12));

  246.         // Set partial derivatives with respect to parameters
  247.         for (final ParameterDriver driver : getParametersDrivers()) {
  248.             for (Span<String> span = driver.getNamesSpanMap().getFirstSpan(); span != null; span = span.next()) {
  249.                 final Integer index = indices.get(span.getData());
  250.                 if (index != null) {
  251.                     estimated.setParameterDerivatives(driver, span.getStart(), derivatives[index]);
  252.                 }
  253.             }
  254.         }

  255.         return estimated;

  256.     }

  257. }