OneWayGNSSRange.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.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.InterSatellitesRange;
  27. import org.orekit.estimation.measurements.ObservableSatellite;
  28. import org.orekit.propagation.SpacecraftState;
  29. import org.orekit.time.AbsoluteDate;
  30. import org.orekit.time.FieldAbsoluteDate;
  31. import org.orekit.utils.Constants;
  32. import org.orekit.utils.PVCoordinatesProvider;
  33. import org.orekit.utils.ParameterDriver;
  34. import org.orekit.utils.TimeSpanMap.Span;
  35. import org.orekit.utils.TimeStampedFieldPVCoordinates;
  36. import org.orekit.utils.TimeStampedPVCoordinates;

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

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

  59.     /** Emitting satellite. */
  60.     private final PVCoordinatesProvider remote;

  61.     /** Clock offset of the emitting satellite. */
  62.     private final double dtRemote;

  63.     /** Simple constructor.
  64.      * @param remote provider for GNSS satellite which simply emits the signal
  65.      * @param dtRemote clock offset of the GNSS satellite, in seconds
  66.      * @param date date of the measurement
  67.      * @param range observed value
  68.      * @param sigma theoretical standard deviation
  69.      * @param baseWeight base weight
  70.      * @param local satellite which receives the signal and perform the measurement
  71.      */
  72.     public OneWayGNSSRange(final PVCoordinatesProvider remote,
  73.                            final double dtRemote,
  74.                            final AbsoluteDate date,
  75.                            final double range, final double sigma,
  76.                            final double baseWeight, final ObservableSatellite local) {
  77.         // Call super constructor
  78.         super(date, range, sigma, baseWeight, Collections.singletonList(local));
  79.         // The local satellite clock offset affects the measurement
  80.         addParameterDriver(local.getClockOffsetDriver());
  81.         // Initialise fields
  82.         this.dtRemote = dtRemote;
  83.         this.remote   = remote;
  84.     }

  85.     /** {@inheritDoc} */
  86.     @Override
  87.     protected EstimatedMeasurementBase<OneWayGNSSRange> theoreticalEvaluationWithoutDerivatives(final int iteration,
  88.                                                                                                 final int evaluation,
  89.                                                                                                 final SpacecraftState[] states) {

  90.         // Coordinates of both satellites in local satellite frame
  91.         final SpacecraftState          localState = states[0];
  92.         final TimeStampedPVCoordinates pvaLocal   = localState.getPVCoordinates();
  93.         final TimeStampedPVCoordinates pvaRemote  = remote.getPVCoordinates(getDate(), localState.getFrame());

  94.         // Downlink delay
  95.         final double dtLocal = getSatellites().get(0).getClockOffsetDriver().getValue(localState.getDate());
  96.         final AbsoluteDate arrivalDate = getDate().shiftedBy(-dtLocal);

  97.         final TimeStampedPVCoordinates s1Downlink = pvaLocal.shiftedBy(arrivalDate.durationFrom(pvaLocal.getDate()));
  98.         final double tauD = signalTimeOfFlight(pvaRemote, s1Downlink.getPosition(), arrivalDate);

  99.         // Transit state
  100.         final double delta      = getDate().durationFrom(pvaRemote.getDate());
  101.         final double deltaMTauD = delta - tauD;

  102.         // Estimated measurement
  103.         final EstimatedMeasurementBase<OneWayGNSSRange> estimatedRange =
  104.                         new EstimatedMeasurementBase<>(this, iteration, evaluation,
  105.                                                        new SpacecraftState[] {
  106.                                                            localState.shiftedBy(deltaMTauD)
  107.                                                        }, new TimeStampedPVCoordinates[] {
  108.                                                            pvaRemote.shiftedBy(delta - tauD),
  109.                                                            localState.shiftedBy(delta).getPVCoordinates()
  110.                                                        });

  111.         // Range value
  112.         final double range = (tauD + dtLocal - dtRemote) * Constants.SPEED_OF_LIGHT;

  113.         // Set value of the estimated measurement
  114.         estimatedRange.setEstimatedValue(range);

  115.         // Return the estimated measurement
  116.         return estimatedRange;

  117.     }

  118.     /** {@inheritDoc} */
  119.     @Override
  120.     protected EstimatedMeasurement<OneWayGNSSRange> theoreticalEvaluation(final int iteration,
  121.                                                                           final int evaluation,
  122.                                                                           final SpacecraftState[] states) {

  123.         // Range derivatives are computed with respect to spacecraft state in inertial frame
  124.         // Parameters:
  125.         //  - 0..2 - Position of the spacecraft in inertial frame
  126.         //  - 3..5 - Velocity of the spacecraft in inertial frame
  127.         //  - 6..n - measurements parameters (clock offset, etc)
  128.         int nbEstimatedParams = 6;
  129.         final Map<String, Integer> parameterIndices = new HashMap<>();
  130.         for (ParameterDriver measurementDriver : getParametersDrivers()) {
  131.             if (measurementDriver.isSelected()) {
  132.                 for (Span<String> span = measurementDriver.getNamesSpanMap().getFirstSpan(); span != null; span = span.next()) {
  133.                     parameterIndices.put(span.getData(), nbEstimatedParams++);
  134.                 }
  135.             }
  136.         }

  137.         // Coordinates of both satellites in local satellite frame
  138.         final SpacecraftState localState  = states[0];
  139.         final TimeStampedFieldPVCoordinates<Gradient> pvaLocal  = getCoordinates(localState, 0, nbEstimatedParams);
  140.         final TimeStampedPVCoordinates                pvaRemote = remote.getPVCoordinates(getDate(), localState.getFrame());

  141.         // Downlink delay
  142.         final Gradient dtLocal = getSatellites().get(0).getClockOffsetDriver().getValue(nbEstimatedParams, parameterIndices, localState.getDate());
  143.         final FieldAbsoluteDate<Gradient> arrivalDate = new FieldAbsoluteDate<>(getDate(), dtLocal.negate());

  144.         final TimeStampedFieldPVCoordinates<Gradient> s1Downlink = pvaLocal.shiftedBy(arrivalDate.durationFrom(pvaLocal.getDate()));
  145.         final Gradient tauD = signalTimeOfFlight(new TimeStampedFieldPVCoordinates<>(pvaRemote.getDate(), dtLocal.getField().getOne(), pvaRemote),
  146.                                                  s1Downlink.getPosition(), arrivalDate);

  147.         // Transit state
  148.         final double   delta      = getDate().durationFrom(pvaRemote.getDate());
  149.         final Gradient deltaMTauD = tauD.negate().add(delta);

  150.         // Estimated measurement
  151.         final EstimatedMeasurement<OneWayGNSSRange> estimatedRange =
  152.                         new EstimatedMeasurement<>(this, iteration, evaluation,
  153.                                                    new SpacecraftState[] {
  154.                                                        localState.shiftedBy(deltaMTauD.getValue())
  155.                                                    }, new TimeStampedPVCoordinates[] {
  156.                                                        pvaRemote.shiftedBy(delta - tauD.getValue()),
  157.                                                        localState.shiftedBy(delta).getPVCoordinates()
  158.                                                    });

  159.         // Range value
  160.         final Gradient range            = tauD.add(dtLocal).subtract(dtRemote).multiply(Constants.SPEED_OF_LIGHT);
  161.         final double[] rangeDerivatives = range.getGradient();

  162.         // Set value and state derivatives of the estimated measurement
  163.         estimatedRange.setEstimatedValue(range.getValue());
  164.         estimatedRange.setStateDerivatives(0, Arrays.copyOfRange(rangeDerivatives, 0,  6));

  165.         // Set partial derivatives with respect to parameters
  166.         for (final ParameterDriver measurementDriver : getParametersDrivers()) {
  167.             for (Span<String> span = measurementDriver.getNamesSpanMap().getFirstSpan(); span != null; span = span.next()) {

  168.                 final Integer index = parameterIndices.get(span.getData());
  169.                 if (index != null) {
  170.                     estimatedRange.setParameterDerivatives(measurementDriver, span.getStart(), rangeDerivatives[index]);
  171.                 }
  172.             }
  173.         }

  174.         // Return the estimated measurement
  175.         return estimatedRange;

  176.     }

  177. }