OneWayGNSSPhase.java

  1. /* Copyright 2002-2023 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.Collections;
  20. import java.util.HashMap;
  21. import java.util.Map;

  22. import org.hipparchus.analysis.differentiation.Gradient;
  23. import org.orekit.estimation.measurements.AbstractMeasurement;
  24. import org.orekit.estimation.measurements.EstimatedMeasurement;
  25. import org.orekit.estimation.measurements.EstimatedMeasurementBase;
  26. import org.orekit.estimation.measurements.ObservableSatellite;
  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.PVCoordinatesProvider;
  32. import org.orekit.utils.ParameterDriver;
  33. import org.orekit.utils.TimeSpanMap.Span;
  34. import org.orekit.utils.TimeStampedFieldPVCoordinates;
  35. import org.orekit.utils.TimeStampedPVCoordinates;

  36. /** One-way GNSS phase measurement.
  37.  * <p>
  38.  * This class can be used in precise orbit determination applications
  39.  * for modeling a phase measurement between a GNSS satellite (emitter)
  40.  * and a LEO satellite (receiver).
  41.  * <p>
  42.  * The one-way GNSS phase measurement assumes knowledge of the orbit and
  43.  * the clock offset of the emitting GNSS satellite. For instance, it is
  44.  * possible to use a SP3 file or a GNSS navigation message to recover
  45.  * the satellite's orbit and clock.
  46.  * <p>
  47.  * This class is very similar to {@link InterSatellitesPhase} measurement
  48.  * class. However, using the one-way GNSS phase measurement, the orbit and clock
  49.  * of the emitting GNSS satellite are <b>NOT</b> estimated simultaneously with
  50.  * LEO satellite coordinates.
  51.  *
  52.  * @author Bryan Cazabonne
  53.  * @since 10.3
  54.  */
  55. public class OneWayGNSSPhase extends AbstractMeasurement<OneWayGNSSPhase> {

  56.     /** Type of the measurement. */
  57.     public static final String MEASUREMENT_TYPE = "OneWayGNSSPhase";

  58.     /** Name for ambiguity driver. */
  59.     public static final String AMBIGUITY_NAME = "ambiguity";

  60.     /** Driver for ambiguity. */
  61.     private final ParameterDriver ambiguityDriver;

  62.     /** Emitting satellite. */
  63.     private final PVCoordinatesProvider remote;

  64.     /** Clock offset of the emitting satellite. */
  65.     private final double dtRemote;

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

  68.     /** Simple constructor.
  69.      * @param remote provider for GNSS satellite which simply emits the signal
  70.      * @param dtRemote clock offset of the GNSS satellite, in seconds
  71.      * @param date date of the measurement
  72.      * @param phase observed value, in cycles
  73.      * @param wavelength phase observed value wavelength, in meters
  74.      * @param sigma theoretical standard deviation
  75.      * @param baseWeight base weight
  76.      * @param local satellite which receives the signal and perform the measurement
  77.      */
  78.     public OneWayGNSSPhase(final PVCoordinatesProvider remote,
  79.                            final double dtRemote,
  80.                            final AbsoluteDate date,
  81.                            final double phase, final double wavelength, final double sigma,
  82.                            final double baseWeight, final ObservableSatellite local) {
  83.         // Call super constructor
  84.         super(date, phase, sigma, baseWeight, Collections.singletonList(local));

  85.         // Initialize phase ambiguity driver
  86.         ambiguityDriver = new ParameterDriver(AMBIGUITY_NAME, 0.0, 1.0,
  87.                                               Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY);

  88.         // The local satellite clock offset affects the measurement
  89.         addParameterDriver(ambiguityDriver);
  90.         addParameterDriver(local.getClockOffsetDriver());

  91.         // Initialise fields
  92.         this.dtRemote   = dtRemote;
  93.         this.remote     = remote;
  94.         this.wavelength = wavelength;
  95.     }

  96.     /** Get the wavelength.
  97.      * @return wavelength (m)
  98.      */
  99.     public double getWavelength() {
  100.         return wavelength;
  101.     }

  102.     /** Get the driver for phase ambiguity.
  103.      * @return the driver for phase ambiguity
  104.      */
  105.     public ParameterDriver getAmbiguityDriver() {
  106.         return ambiguityDriver;
  107.     }

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

  113.         // Coordinates of both satellites
  114.         final SpacecraftState          localState = states[0];
  115.         final TimeStampedPVCoordinates pvaLocal   = localState.getPVCoordinates();
  116.         final TimeStampedPVCoordinates pvaRemote  = remote.getPVCoordinates(getDate(), localState.getFrame());

  117.         // Downlink delay
  118.         final double dtLocal = getSatellites().get(0).getClockOffsetDriver().getValue(localState.getDate());
  119.         final AbsoluteDate arrivalDate = getDate().shiftedBy(-dtLocal);

  120.         final TimeStampedPVCoordinates s1Downlink =
  121.                         pvaLocal.shiftedBy(arrivalDate.durationFrom(pvaLocal.getDate()));
  122.         final double tauD = signalTimeOfFlight(pvaRemote, s1Downlink.getPosition(), arrivalDate);

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

  126.         // prepare the evaluation
  127.         final EstimatedMeasurementBase<OneWayGNSSPhase> estimatedPhase =
  128.                         new EstimatedMeasurementBase<>(this, iteration, evaluation,
  129.                                                        new SpacecraftState[] {
  130.                                                            localState.shiftedBy(deltaMTauD)
  131.                                                        }, new TimeStampedPVCoordinates[] {
  132.                                                            pvaRemote.shiftedBy(delta - tauD),
  133.                                                            localState.shiftedBy(delta).getPVCoordinates()
  134.                                                        });

  135.         // Phase value
  136.         final double   cOverLambda      = Constants.SPEED_OF_LIGHT / wavelength;
  137.         final double   ambiguity        = ambiguityDriver.getValue(localState.getDate());
  138.         final double   phase            = (tauD + dtLocal - dtRemote) * cOverLambda + ambiguity;

  139.         // Set value of the estimated measurement
  140.         estimatedPhase.setEstimatedValue(phase);

  141.         // Return the estimated measurement
  142.         return estimatedPhase;

  143.     }

  144.     /** {@inheritDoc} */
  145.     @Override
  146.     protected EstimatedMeasurement<OneWayGNSSPhase> theoreticalEvaluation(final int iteration,
  147.                                                                           final int evaluation,
  148.                                                                           final SpacecraftState[] states) {

  149.         // Phase derivatives are computed with respect to spacecrafts states in inertial frame
  150.         // Parameters:
  151.         //  - 0..2  - Position of the receiver satellite in inertial frame
  152.         //  - 3..5  - Velocity of the receiver satellite in inertial frame
  153.         //  - 6..n  - Measurement parameters: ambiguity and clock offset
  154.         int nbEstimatedParamsPhase = 6;
  155.         final Map<String, Integer> parameterIndicesPhase = new HashMap<>();
  156.         for (ParameterDriver phaseMeasurementDriver : getParametersDrivers()) {
  157.             if (phaseMeasurementDriver.isSelected()) {
  158.                 for (Span<String> span = phaseMeasurementDriver.getNamesSpanMap().getFirstSpan(); span != null; span = span.next()) {
  159.                     parameterIndicesPhase.put(span.getData(), nbEstimatedParamsPhase++);
  160.                 }
  161.             }
  162.         }

  163.         // Coordinates of both satellites
  164.         final SpacecraftState localState  = states[0];
  165.         final TimeStampedFieldPVCoordinates<Gradient> pvaLocal  = getCoordinates(localState, 0, nbEstimatedParamsPhase);
  166.         final TimeStampedPVCoordinates                pvaRemote = remote.getPVCoordinates(getDate(), localState.getFrame());

  167.         // Downlink delay
  168.         final Gradient dtLocal = getSatellites().get(0).getClockOffsetDriver().getValue(nbEstimatedParamsPhase, parameterIndicesPhase, localState.getDate());
  169.         final FieldAbsoluteDate<Gradient> arrivalDate = new FieldAbsoluteDate<>(getDate(), dtLocal.negate());

  170.         final TimeStampedFieldPVCoordinates<Gradient> s1Downlink =
  171.                         pvaLocal.shiftedBy(arrivalDate.durationFrom(pvaLocal.getDate()));
  172.         final Gradient tauD = signalTimeOfFlight(new TimeStampedFieldPVCoordinates<>(pvaRemote.getDate(), dtLocal.getField().getOne(), pvaRemote),
  173.                                                  s1Downlink.getPosition(), arrivalDate);

  174.         // Transit state
  175.         final double   delta      = getDate().durationFrom(pvaRemote.getDate());
  176.         final Gradient deltaMTauD = tauD.negate().add(delta);

  177.         // prepare the evaluation
  178.         final EstimatedMeasurement<OneWayGNSSPhase> estimatedPhase =
  179.                         new EstimatedMeasurement<>(this, iteration, evaluation,
  180.                                                    new SpacecraftState[] {
  181.                                                        localState.shiftedBy(deltaMTauD.getValue())
  182.                                                    }, new TimeStampedPVCoordinates[] {
  183.                                                        pvaRemote.shiftedBy(delta - tauD.getValue()),
  184.                                                        localState.shiftedBy(delta).getPVCoordinates()
  185.                                                    });

  186.         // Phase value
  187.         final double   cOverLambda      = Constants.SPEED_OF_LIGHT / wavelength;
  188.         final Gradient ambiguity        = ambiguityDriver.getValue(nbEstimatedParamsPhase, parameterIndicesPhase, localState.getDate());
  189.         final Gradient phase            = tauD.add(dtLocal).subtract(dtRemote).multiply(cOverLambda).add(ambiguity);
  190.         final double[] phaseDerivatives = phase.getGradient();

  191.         // Set value and state derivatives of the estimated measurement
  192.         estimatedPhase.setEstimatedValue(phase.getValue());
  193.         estimatedPhase.setStateDerivatives(0, Arrays.copyOfRange(phaseDerivatives, 0,  6));

  194.         // Set partial derivatives with respect to parameters
  195.         for (final ParameterDriver phaseMeasurementDriver : getParametersDrivers()) {
  196.             for (Span<String> span = phaseMeasurementDriver.getNamesSpanMap().getFirstSpan(); span != null; span = span.next()) {

  197.                 final Integer index = parameterIndicesPhase.get(span.getData());
  198.                 if (index != null) {
  199.                     estimatedPhase.setParameterDerivatives(phaseMeasurementDriver, span.getStart(), phaseDerivatives[index]);
  200.                 }
  201.             }
  202.         }

  203.         // Return the estimated measurement
  204.         return estimatedPhase;

  205.     }

  206. }