InterSatellitesRange.java

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

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

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

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

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

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

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

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

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

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

  125.         final TimeStampedPVCoordinates s1Downlink =
  126.                         pvaL.shiftedBy(arrivalDate.durationFrom(pvaL.getDate()));
  127.         final double tauD = signalTimeOfFlightAdjustableEmitter(pvaR, s1Downlink.getPosition(), arrivalDate, frame);

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

  131.         // prepare the evaluation
  132.         final EstimatedMeasurementBase<InterSatellitesRange> estimated;

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

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

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

  153.         } else {

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

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

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

  166.         }
  167.         estimated.setEstimatedValue(range);

  168.         return estimated;

  169.     }

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

  175.         final Frame frame = states[0].getFrame();

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

  190.                     if (!indices.containsKey(span.getData())) {
  191.                         indices.put(span.getData(), nbParams++);
  192.                     }
  193.                 }
  194.             }
  195.         }

  196.         // coordinates of both satellites
  197.         final SpacecraftState local = states[0];
  198.         final TimeStampedFieldPVCoordinates<Gradient> pvaL = getCoordinates(local, 0, nbParams);
  199.         final SpacecraftState remote = states[1];
  200.         final TimeStampedFieldPVCoordinates<Gradient> pvaR = states[1].
  201.                                                              getFrame().
  202.                                                              getTransformTo(frame, states[1].getDate()).
  203.                                                              transformPVCoordinates(getCoordinates(remote, 6, nbParams));

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

  207.         // downlink delay
  208.         final Gradient dtl = getSatellites().get(0).getClockOffsetDriver().getValue(nbParams, indices, local.getDate());
  209.         final FieldAbsoluteDate<Gradient> arrivalDate =
  210.                         new FieldAbsoluteDate<>(getDate(), dtl.negate());

  211.         final TimeStampedFieldPVCoordinates<Gradient> s1Downlink =
  212.                         pvaL.shiftedBy(arrivalDate.durationFrom(pvaL.getDate()));
  213.         final Gradient tauD = signalTimeOfFlightAdjustableEmitter(pvaR, s1Downlink.getPosition(),
  214.                                                                   arrivalDate, frame);

  215.         // Transit state
  216.         final double              delta      = getDate().durationFrom(remote.getDate());
  217.         final Gradient deltaMTauD = tauD.negate().add(delta);

  218.         // prepare the evaluation
  219.         final EstimatedMeasurement<InterSatellitesRange> estimated;

  220.         final Gradient range;
  221.         if (twoway) {
  222.             // Transit state (re)computed with derivative structures
  223.             final TimeStampedFieldPVCoordinates<Gradient> transitStateDS = pvaR.shiftedBy(deltaMTauD);

  224.             // uplink delay
  225.             final Gradient tauU = signalTimeOfFlightAdjustableEmitter(pvaL,
  226.                                                                       transitStateDS.getPosition(),
  227.                                                                       transitStateDS.getDate(),
  228.                                                                       frame);
  229.             estimated = new EstimatedMeasurement<>(this, iteration, evaluation,
  230.                                                    new SpacecraftState[] {
  231.                                                        local.shiftedBy(deltaMTauD.getValue()),
  232.                                                        remote.shiftedBy(deltaMTauD.getValue())
  233.                                                    }, new TimeStampedPVCoordinates[] {
  234.                                                        local.shiftedBy(delta - tauD.getValue() - tauU.getValue()).getPVCoordinates(frame),
  235.                                                        remote.shiftedBy(delta - tauD.getValue()).getPVCoordinates(frame),
  236.                                                        local.shiftedBy(delta).getPVCoordinates(frame)
  237.                                                    });

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

  240.         } else {

  241.             estimated = new EstimatedMeasurement<>(this, iteration, evaluation,
  242.                                                    new SpacecraftState[] {
  243.                                                        local.shiftedBy(deltaMTauD.getValue()),
  244.                                                        remote.shiftedBy(deltaMTauD.getValue())
  245.                                                    }, new TimeStampedPVCoordinates[] {
  246.                                                        remote.shiftedBy(delta - tauD.getValue()).getPVCoordinates(frame),
  247.                                                        local.shiftedBy(delta).getPVCoordinates()
  248.                                                    });

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

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

  253.         }
  254.         estimated.setEstimatedValue(range.getValue());

  255.         // Range first order derivatives with respect to states
  256.         final double[] derivatives = range.getGradient();
  257.         estimated.setStateDerivatives(0, Arrays.copyOfRange(derivatives, 0,  6));
  258.         estimated.setStateDerivatives(1, Arrays.copyOfRange(derivatives, 6, 12));

  259.         // Set first order derivatives with respect to parameters
  260.         for (final ParameterDriver driver : getParametersDrivers()) {
  261.             for (Span<String> span = driver.getNamesSpanMap().getFirstSpan(); span != null; span = span.next()) {
  262.                 final Integer index = indices.get(span.getData());
  263.                 if (index != null) {
  264.                     estimated.setParameterDerivatives(driver, span.getStart(), derivatives[index]);
  265.                 }
  266.             }
  267.         }

  268.         return estimated;

  269.     }

  270. }