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.         addParameterDriver(local.getClockDriftDriver());
  92.         addParameterDriver(local.getClockAccelerationDriver());
  93.         if (!twoWay) {
  94.             // for one way measurements, the remote satellite clock offsets also affects the measurement
  95.             addParameterDriver(remote.getClockOffsetDriver());
  96.             addParameterDriver(remote.getClockDriftDriver());
  97.             addParameterDriver(remote.getClockAccelerationDriver());
  98.         }
  99.         this.twoway = twoWay;
  100.     }

  101.     /** Check if the instance represents a two-way measurement.
  102.      * @return true if the instance represents a two-way measurement
  103.      */
  104.     public boolean isTwoWay() {
  105.         return twoway;
  106.     }

  107.     /** {@inheritDoc} */
  108.     @Override
  109.     protected EstimatedMeasurementBase<InterSatellitesRange> theoreticalEvaluationWithoutDerivatives(final int iteration,
  110.                                                                                                      final int evaluation,
  111.                                                                                                      final SpacecraftState[] states) {

  112.         // coordinates of both satellites
  113.         final SpacecraftState local = states[0];
  114.         final TimeStampedPVCoordinates pvaL = local.getPVCoordinates();
  115.         final SpacecraftState remote = states[1];
  116.         final TimeStampedPVCoordinates pvaR = remote.getPVCoordinates();

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

  120.         // downlink delay
  121.         final double dtl = getSatellites().get(0).getClockOffsetDriver().getValue(local.getDate());
  122.         final AbsoluteDate arrivalDate = getDate().shiftedBy(-dtl);

  123.         final TimeStampedPVCoordinates s1Downlink =
  124.                         pvaL.shiftedBy(arrivalDate.durationFrom(pvaL.getDate()));
  125.         final double tauD = signalTimeOfFlight(pvaR, s1Downlink.getPosition(), arrivalDate, local.getFrame());

  126.         // Transit state
  127.         final double delta      = getDate().durationFrom(remote.getDate());
  128.         final double deltaMTauD = delta - tauD;

  129.         // prepare the evaluation
  130.         final EstimatedMeasurementBase<InterSatellitesRange> estimated;

  131.         final double range;
  132.         if (twoway) {
  133.             // Transit state (re)computed with derivative structures
  134.             final TimeStampedPVCoordinates transitState = pvaR.shiftedBy(deltaMTauD);

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

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

  151.         } else {

  152.             estimated = new EstimatedMeasurementBase<>(this, iteration, evaluation,
  153.                                                        new SpacecraftState[] {
  154.                                                            local.shiftedBy(deltaMTauD),
  155.                                                            remote.shiftedBy(deltaMTauD)
  156.                                                        }, new TimeStampedPVCoordinates[] {
  157.                                                            remote.shiftedBy(delta - tauD).getPVCoordinates(),
  158.                                                            local.shiftedBy(delta).getPVCoordinates()
  159.                                                        });

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

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

  164.         }
  165.         estimated.setEstimatedValue(range);

  166.         return estimated;

  167.     }

  168.     /** {@inheritDoc} */
  169.     @Override
  170.     protected EstimatedMeasurement<InterSatellitesRange> theoreticalEvaluation(final int iteration,
  171.                                                                                final int evaluation,
  172.                                                                                final SpacecraftState[] states) {

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

  187.                     if (!indices.containsKey(span.getData())) {
  188.                         indices.put(span.getData(), nbParams++);
  189.                     }
  190.                 }
  191.             }
  192.         }

  193.         // coordinates of both satellites
  194.         final SpacecraftState local = states[0];
  195.         final TimeStampedFieldPVCoordinates<Gradient> pvaL = getCoordinates(local, 0, nbParams);
  196.         final SpacecraftState remote = states[1];
  197.         final TimeStampedFieldPVCoordinates<Gradient> pvaR = getCoordinates(remote, 6, nbParams);

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

  201.         // downlink delay
  202.         final Gradient dtl = getSatellites().get(0).getClockOffsetDriver().getValue(nbParams, indices, local.getDate());
  203.         final FieldAbsoluteDate<Gradient> arrivalDate =
  204.                         new FieldAbsoluteDate<>(getDate(), dtl.negate());

  205.         final TimeStampedFieldPVCoordinates<Gradient> s1Downlink =
  206.                         pvaL.shiftedBy(arrivalDate.durationFrom(pvaL.getDate()));
  207.         final Gradient tauD = signalTimeOfFlight(pvaR, s1Downlink.getPosition(),
  208.                                                  arrivalDate, local.getFrame());

  209.         // Transit state
  210.         final double              delta      = getDate().durationFrom(remote.getDate());
  211.         final Gradient deltaMTauD = tauD.negate().add(delta);

  212.         // prepare the evaluation
  213.         final EstimatedMeasurement<InterSatellitesRange> estimated;

  214.         final Gradient range;
  215.         if (twoway) {
  216.             // Transit state (re)computed with derivative structures
  217.             final TimeStampedFieldPVCoordinates<Gradient> transitStateDS = pvaR.shiftedBy(deltaMTauD);

  218.             // uplink delay
  219.             final Gradient tauU = signalTimeOfFlight(pvaL,
  220.                                                      transitStateDS.getPosition(),
  221.                                                      transitStateDS.getDate(),
  222.                                                      local.getFrame());
  223.             estimated = new EstimatedMeasurement<>(this, iteration, evaluation,
  224.                                                    new SpacecraftState[] {
  225.                                                        local.shiftedBy(deltaMTauD.getValue()),
  226.                                                        remote.shiftedBy(deltaMTauD.getValue())
  227.                                                    }, new TimeStampedPVCoordinates[] {
  228.                                                        local.shiftedBy(delta - tauD.getValue() - tauU.getValue()).getPVCoordinates(),
  229.                                                        remote.shiftedBy(delta - tauD.getValue()).getPVCoordinates(),
  230.                                                        local.shiftedBy(delta).getPVCoordinates()
  231.                                                    });

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

  234.         } else {

  235.             estimated = new EstimatedMeasurement<>(this, iteration, evaluation,
  236.                                                    new SpacecraftState[] {
  237.                                                        local.shiftedBy(deltaMTauD.getValue()),
  238.                                                        remote.shiftedBy(deltaMTauD.getValue())
  239.                                                    }, new TimeStampedPVCoordinates[] {
  240.                                                        remote.shiftedBy(delta - tauD.getValue()).getPVCoordinates(),
  241.                                                        local.shiftedBy(delta).getPVCoordinates()
  242.                                                    });

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

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

  247.         }
  248.         estimated.setEstimatedValue(range.getValue());

  249.         // Range first order derivatives with respect to states
  250.         final double[] derivatives = range.getGradient();
  251.         estimated.setStateDerivatives(0, Arrays.copyOfRange(derivatives, 0,  6));
  252.         estimated.setStateDerivatives(1, Arrays.copyOfRange(derivatives, 6, 12));

  253.         // Set first order derivatives with respect to parameters
  254.         for (final ParameterDriver driver : getParametersDrivers()) {
  255.             for (Span<String> span = driver.getNamesSpanMap().getFirstSpan(); span != null; span = span.next()) {
  256.                 final Integer index = indices.get(span.getData());
  257.                 if (index != null) {
  258.                     estimated.setParameterDerivatives(driver, span.getStart(), derivatives[index]);
  259.                 }
  260.             }
  261.         }

  262.         return estimated;

  263.     }

  264. }