InterSatellitesPhase.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.gnss;

  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.estimation.measurements.AbstractMeasurement;
  23. import org.orekit.estimation.measurements.EstimatedMeasurement;
  24. import org.orekit.estimation.measurements.EstimatedMeasurementBase;
  25. import org.orekit.estimation.measurements.ObservableSatellite;
  26. import org.orekit.propagation.SpacecraftState;
  27. import org.orekit.time.AbsoluteDate;
  28. import org.orekit.time.FieldAbsoluteDate;
  29. import org.orekit.utils.Constants;
  30. import org.orekit.utils.ParameterDriver;
  31. import org.orekit.utils.TimeSpanMap.Span;
  32. import org.orekit.utils.TimeStampedFieldPVCoordinates;
  33. import org.orekit.utils.TimeStampedPVCoordinates;

  34. /** Phase measurement between two satellites.
  35.  * <p>
  36.  * The measurement is considered to be a signal emitted from
  37.  * a remote satellite and received by a local satellite.
  38.  * Its value is the number of cycles between emission and reception.
  39.  * The motion of both spacecrafts during the signal flight time
  40.  * are taken into account. The date of the measurement corresponds to the
  41.  * reception on ground of the emitted signal.
  42.  * </p>
  43.  * @author Bryan Cazabonne
  44.  * @since 10.3
  45.  */
  46. public class InterSatellitesPhase extends AbstractMeasurement<InterSatellitesPhase> {

  47.     /** Type of the measurement. */
  48.     public static final String MEASUREMENT_TYPE = "InterSatellitesPhase";

  49.     /** Name for ambiguity driver. */
  50.     public static final String AMBIGUITY_NAME = "ambiguity";

  51.     /** Driver for ambiguity. */
  52.     private final ParameterDriver ambiguityDriver;

  53.     /** Wavelength of the phase observed value [m]. */
  54.     private final double wavelength;

  55.     /** Constructor.
  56.      * @param local satellite which receives the signal and performs the measurement
  57.      * @param remote remote satellite which simply emits the signal
  58.      * @param date date of the measurement
  59.      * @param phase observed value (cycles)
  60.      * @param wavelength phase observed value wavelength (m)
  61.      * @param sigma theoretical standard deviation
  62.      * @param baseWeight base weight
  63.      */
  64.     public InterSatellitesPhase(final ObservableSatellite local,
  65.                                 final ObservableSatellite remote,
  66.                                 final AbsoluteDate date, final double phase,
  67.                                 final double wavelength, final double sigma,
  68.                                 final double baseWeight) {
  69.         // Call to super constructor
  70.         super(date, phase, sigma, baseWeight, Arrays.asList(local, remote));

  71.         // Initialize phase ambiguity driver
  72.         ambiguityDriver = new ParameterDriver(AMBIGUITY_NAME, 0.0, 1.0,
  73.                                               Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY);

  74.         // Add parameter drivers
  75.         addParameterDriver(ambiguityDriver);
  76.         addParameterDriver(local.getClockOffsetDriver());
  77.         addParameterDriver(remote.getClockOffsetDriver());

  78.         // Initialize fields
  79.         this.wavelength = wavelength;
  80.     }

  81.     /** Get the wavelength.
  82.      * @return wavelength (m)
  83.      */
  84.     public double getWavelength() {
  85.         return wavelength;
  86.     }

  87.     /** Get the driver for phase ambiguity.
  88.      * @return the driver for phase ambiguity
  89.      */
  90.     public ParameterDriver getAmbiguityDriver() {
  91.         return ambiguityDriver;
  92.     }

  93.     /** {@inheritDoc} */
  94.     @Override
  95.     protected EstimatedMeasurementBase<InterSatellitesPhase> theoreticalEvaluationWithoutDerivatives(final int iteration,
  96.                                                                                                      final int evaluation,
  97.                                                                                                      final SpacecraftState[] states) {

  98.         // Coordinates of both satellites
  99.         final SpacecraftState local = states[0];
  100.         final TimeStampedPVCoordinates pvaL = local.getPVCoordinates();
  101.         final SpacecraftState remote = states[1];
  102.         final TimeStampedPVCoordinates pvaR = remote.getPVCoordinates();

  103.         // Compute propagation times
  104.         // Downlink delay
  105.         final double dtl = getSatellites().get(0).getClockOffsetDriver().getValue(AbsoluteDate.ARBITRARY_EPOCH);
  106.         final AbsoluteDate arrivalDate = getDate().shiftedBy(-dtl);

  107.         final TimeStampedPVCoordinates s1Downlink = pvaL.shiftedBy(arrivalDate.durationFrom(pvaL.getDate()));
  108.         final double tauD = signalTimeOfFlight(pvaR, s1Downlink.getPosition(), arrivalDate);

  109.         // Transit state
  110.         final double delta      = getDate().durationFrom(remote.getDate());
  111.         final double deltaMTauD = delta - tauD;

  112.         // prepare the evaluation
  113.         final EstimatedMeasurementBase<InterSatellitesPhase> estimatedPhase =
  114.                         new EstimatedMeasurementBase<>(this, iteration, evaluation,
  115.                                                        new SpacecraftState[] {
  116.                                                            local.shiftedBy(deltaMTauD),
  117.                                                            remote.shiftedBy(deltaMTauD)
  118.                                                        }, new TimeStampedPVCoordinates[] {
  119.                                                            remote.shiftedBy(delta - tauD).getPVCoordinates(),
  120.                                                            local.shiftedBy(delta).getPVCoordinates()
  121.                                                        });

  122.         // Clock offsets
  123.         final double dtr = getSatellites().get(1).getClockOffsetDriver().getValue(AbsoluteDate.ARBITRARY_EPOCH);

  124.         // Phase value
  125.         final double cOverLambda = Constants.SPEED_OF_LIGHT / wavelength;
  126.         final double ambiguity   = ambiguityDriver.getValue(AbsoluteDate.ARBITRARY_EPOCH);
  127.         final double phase       = (tauD + dtl - dtr) * cOverLambda + ambiguity;

  128.         estimatedPhase.setEstimatedValue(phase);

  129.         // Return the estimated measurement
  130.         return estimatedPhase;

  131.     }

  132.     /** {@inheritDoc} */
  133.     @Override
  134.     protected EstimatedMeasurement<InterSatellitesPhase> theoreticalEvaluation(final int iteration,
  135.                                                                                final int evaluation,
  136.                                                                                final SpacecraftState[] states) {

  137.         // Phase derivatives are computed with respect to spacecrafts states in inertial frame
  138.         // ----------------------
  139.         //
  140.         // Parameters:
  141.         //  - 0..2  - Position of the receiver satellite in inertial frame
  142.         //  - 3..5  - Velocity of the receiver satellite in inertial frame
  143.         //  - 6..8  - Position of the remote satellite in inertial frame
  144.         //  - 9..11 - Velocity of the remote satellite in inertial frame
  145.         //  - 12..  - Measurement parameters: ambiguity, local clock offset, remote clock offset...
  146.         int nbParams = 12;
  147.         final Map<String, Integer> indices = new HashMap<>();
  148.         for (ParameterDriver phaseMeasurementDriver : getParametersDrivers()) {
  149.             if (phaseMeasurementDriver.isSelected()) {
  150.                 for (Span<String> span = phaseMeasurementDriver.getNamesSpanMap().getFirstSpan(); span != null; span = span.next()) {

  151.                     indices.put(span.getData(), nbParams++);
  152.                 }
  153.             }
  154.         }

  155.         // Coordinates of both satellites
  156.         final SpacecraftState local = states[0];
  157.         final TimeStampedFieldPVCoordinates<Gradient> pvaL = getCoordinates(local, 0, nbParams);
  158.         final SpacecraftState remote = states[1];
  159.         final TimeStampedFieldPVCoordinates<Gradient> pvaR = getCoordinates(remote, 6, nbParams);

  160.         // Compute propagation times
  161.         // Downlink delay
  162.         final Gradient dtl = getSatellites().get(0).getClockOffsetDriver().getValue(nbParams, indices, AbsoluteDate.ARBITRARY_EPOCH);
  163.         final FieldAbsoluteDate<Gradient> arrivalDate = new FieldAbsoluteDate<>(getDate(), dtl.negate());

  164.         final TimeStampedFieldPVCoordinates<Gradient> s1Downlink =
  165.                         pvaL.shiftedBy(arrivalDate.durationFrom(pvaL.getDate()));
  166.         final Gradient tauD = signalTimeOfFlight(pvaR, s1Downlink.getPosition(), arrivalDate);

  167.         // Transit state
  168.         final double   delta      = getDate().durationFrom(remote.getDate());
  169.         final Gradient deltaMTauD = tauD.negate().add(delta);

  170.         // prepare the evaluation
  171.         final EstimatedMeasurement<InterSatellitesPhase> estimatedPhase =
  172.                         new EstimatedMeasurement<>(this, iteration, evaluation,
  173.                                                    new SpacecraftState[] {
  174.                                                        local.shiftedBy(deltaMTauD.getValue()),
  175.                                                        remote.shiftedBy(deltaMTauD.getValue())
  176.                                                    }, new TimeStampedPVCoordinates[] {
  177.                                                        remote.shiftedBy(delta - tauD.getValue()).getPVCoordinates(),
  178.                                                        local.shiftedBy(delta).getPVCoordinates()
  179.                                                    });

  180.         // Clock offsets
  181.         final Gradient dtr = getSatellites().get(1).getClockOffsetDriver().getValue(nbParams, indices, AbsoluteDate.ARBITRARY_EPOCH);

  182.         // Phase value
  183.         final double   cOverLambda = Constants.SPEED_OF_LIGHT / wavelength;
  184.         final Gradient ambiguity   = ambiguityDriver.getValue(nbParams, indices, AbsoluteDate.ARBITRARY_EPOCH);
  185.         final Gradient phase       = tauD.add(dtl).subtract(dtr).multiply(cOverLambda).add(ambiguity);

  186.         estimatedPhase.setEstimatedValue(phase.getValue());

  187.         // Range partial derivatives with respect to states
  188.         final double[] derivatives = phase.getGradient();
  189.         estimatedPhase.setStateDerivatives(0, Arrays.copyOfRange(derivatives, 0,  6));
  190.         estimatedPhase.setStateDerivatives(1, Arrays.copyOfRange(derivatives, 6, 12));

  191.         // Set partial derivatives with respect to parameters
  192.         for (final ParameterDriver driver : getParametersDrivers()) {
  193.             for (Span<String> span = driver.getNamesSpanMap().getFirstSpan(); span != null; span = span.next()) {

  194.                 final Integer index = indices.get(span.getData());
  195.                 if (index != null) {
  196.                     estimatedPhase.setParameterDerivatives(driver, span.getStart(), derivatives[index]);
  197.                 }
  198.             }
  199.         }

  200.         // Return the estimated measurement
  201.         return estimatedPhase;

  202.     }

  203. }