BistaticRange.java

  1. /* Copyright 2002-2023 Mark Rutten
  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.  * Mark Rutten 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.hipparchus.analysis.differentiation.GradientField;
  23. import org.hipparchus.geometry.euclidean.threed.FieldVector3D;
  24. import org.hipparchus.geometry.euclidean.threed.Vector3D;
  25. import org.orekit.frames.FieldTransform;
  26. import org.orekit.frames.Transform;
  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.ParameterDriver;
  32. import org.orekit.utils.TimeSpanMap.Span;
  33. import org.orekit.utils.TimeStampedFieldPVCoordinates;
  34. import org.orekit.utils.TimeStampedPVCoordinates;

  35. /**
  36.  * Class modeling a bistatic range measurement using
  37.  * an emitter ground station and a receiver ground station.
  38.  * <p>
  39.  * The measurement is considered to be a signal:
  40.  * <ul>
  41.  * <li>Emitted from the emitter ground station</li>
  42.  * <li>Reflected on the spacecraft</li>
  43.  * <li>Received on the receiver ground station</li>
  44.  * </ul>
  45.  * The date of the measurement corresponds to the reception on ground of the reflected signal.
  46.  * <p>
  47.  * The motion of the stations and the spacecraft during the signal flight time are taken into account.
  48.  * </p>
  49.  *
  50.  * @author Mark Rutten
  51.  * @since 11.2
  52.  */
  53. public class BistaticRange extends GroundReceiverMeasurement<BistaticRange> {

  54.     /** Type of the measurement. */
  55.     public static final String MEASUREMENT_TYPE = "BistaticRange";

  56.     /**
  57.      * Ground station from which transmission is made.
  58.      */
  59.     private final GroundStation emitter;

  60.     /**
  61.      * Simple constructor.
  62.      *
  63.      * @param emitter     ground station from which transmission is performed
  64.      * @param receiver    ground station from which measurement is performed
  65.      * @param date        date of the measurement
  66.      * @param range       observed value
  67.      * @param sigma       theoretical standard deviation
  68.      * @param baseWeight  base weight
  69.      * @param satellite   satellite related to this measurement
  70.      * @since 11.2
  71.      */
  72.     public BistaticRange(final GroundStation emitter, final GroundStation receiver, final AbsoluteDate date,
  73.                          final double range, final double sigma, final double baseWeight,
  74.                          final ObservableSatellite satellite) {
  75.         super(receiver, true, date, range, sigma, baseWeight, satellite);

  76.         addParameterDriver(emitter.getClockOffsetDriver());
  77.         addParameterDriver(emitter.getEastOffsetDriver());
  78.         addParameterDriver(emitter.getNorthOffsetDriver());
  79.         addParameterDriver(emitter.getZenithOffsetDriver());
  80.         addParameterDriver(emitter.getPrimeMeridianOffsetDriver());
  81.         addParameterDriver(emitter.getPrimeMeridianDriftDriver());
  82.         addParameterDriver(emitter.getPolarOffsetXDriver());
  83.         addParameterDriver(emitter.getPolarDriftXDriver());
  84.         addParameterDriver(emitter.getPolarOffsetYDriver());
  85.         addParameterDriver(emitter.getPolarDriftYDriver());

  86.         this.emitter = emitter;

  87.     }

  88.     /** Get the emitter ground station.
  89.      * @return emitter ground station
  90.      */
  91.     public GroundStation getEmitterStation() {
  92.         return emitter;
  93.     }

  94.     /** Get the receiver ground station.
  95.      * @return receiver ground station
  96.      */
  97.     public GroundStation getReceiverStation() {
  98.         return getStation();
  99.     }

  100.     /**
  101.      * {@inheritDoc}
  102.      */
  103.     @Override
  104.     protected EstimatedMeasurementBase<BistaticRange> theoreticalEvaluationWithoutDerivatives(final int iteration,
  105.                                                                                               final int evaluation,
  106.                                                                                               final SpacecraftState[] states) {

  107.         final SpacecraftState state = states[0];

  108.         // Coordinates of the spacecraft
  109.         final TimeStampedPVCoordinates pva = state.getPVCoordinates();

  110.         // transform between station and inertial frame, expressed as a gradient
  111.         // The components of station's position in offset frame are the 3 last derivative parameters
  112.         final Transform offsetToInertialRx = getReceiverStation().getOffsetToInertial(state.getFrame(), getDate(), false);
  113.         final AbsoluteDate downlinkDate    = offsetToInertialRx.getDate();

  114.         // Station position in inertial frame at end of the downlink leg
  115.         final TimeStampedPVCoordinates stationReceiver =
  116.                 offsetToInertialRx.transformPVCoordinates(new TimeStampedPVCoordinates(downlinkDate,
  117.                                                                                        Vector3D.ZERO, Vector3D.ZERO, Vector3D.ZERO));

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

  121.         // Downlink delay
  122.         final double tauD = signalTimeOfFlight(pva, stationReceiver.getPosition(), downlinkDate);

  123.         // Transit state & Transit state (re)computed with gradients
  124.         final double delta = downlinkDate.durationFrom(state.getDate());
  125.         final double deltaMTauD = delta - tauD;
  126.         final SpacecraftState transitState = state.shiftedBy(deltaMTauD);
  127.         final TimeStampedPVCoordinates transitStateDS = pva.shiftedBy(deltaMTauD);

  128.         // transform between secondary station topocentric frame (east-north-zenith) and inertial frame expressed as gradients
  129.         // The components of secondary station's position in offset frame are the 3 last derivative parameters
  130.         final AbsoluteDate transitDate = downlinkDate.shiftedBy(-tauD);
  131.         final Transform offsetToInertialTxApprox = getEmitterStation().getOffsetToInertial(state.getFrame(), transitDate, true);

  132.         // Secondary station PV in inertial frame at transit time
  133.         final TimeStampedPVCoordinates transmitApprox =
  134.                 offsetToInertialTxApprox.transformPVCoordinates(new TimeStampedPVCoordinates(transitDate,
  135.                                                                                              Vector3D.ZERO, Vector3D.ZERO, Vector3D.ZERO));

  136.         // Uplink time of flight from secondary station to transit state of leg2
  137.         final double tauU = signalTimeOfFlight(transmitApprox, transitStateDS.getPosition(), transitStateDS.getDate());

  138.         // Total time of flight
  139.         final double tauTotal = tauU - deltaMTauD;

  140.         // Absolute date of transmission
  141.         final AbsoluteDate transmitDate = downlinkDate.shiftedBy(tauTotal);
  142.         final Transform transmitToInert = emitter.getOffsetToInertial(state.getFrame(), transmitDate, true);

  143.         // Secondary station PV in inertial frame at rebound date on secondary station
  144.         final TimeStampedPVCoordinates stationTransmitter =
  145.                 transmitToInert.transformPVCoordinates(new TimeStampedPVCoordinates(transmitDate,
  146.                                                                                     Vector3D.ZERO, Vector3D.ZERO, Vector3D.ZERO));

  147.         // Prepare the evaluation
  148.         final EstimatedMeasurementBase<BistaticRange> estimated =
  149.                         new EstimatedMeasurementBase<>(this,
  150.                                                        iteration, evaluation,
  151.                                                        new SpacecraftState[] {
  152.                                                            transitState
  153.                                                        },
  154.                                                        new TimeStampedPVCoordinates[] {
  155.                                                            stationReceiver,
  156.                                                            transitStateDS,
  157.                                                            stationTransmitter
  158.                                                        });

  159.         // Range value
  160.         final double tau = tauD + tauU;
  161.         final double range = tau * Constants.SPEED_OF_LIGHT;

  162.         estimated.setEstimatedValue(range);

  163.         return estimated;
  164.     }

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

  172.         final SpacecraftState state = states[0];

  173.         // Range derivatives are computed with respect to spacecraft state in inertial frame
  174.         // and station parameters
  175.         // ----------------------
  176.         //
  177.         // Parameters:
  178.         //  - 0..2 - Position of the spacecraft in inertial frame
  179.         //  - 3..5 - Velocity of the spacecraft in inertial frame
  180.         //  - 6..n - measurements parameters (clock offset, station offsets, pole, prime meridian, sat clock offset...)
  181.         int nbParams = 6;
  182.         final Map<String, Integer> indices = new HashMap<>();
  183.         for (ParameterDriver driver : getParametersDrivers()) {
  184.             if (driver.isSelected()) {
  185.                 for (Span<String> span = driver.getNamesSpanMap().getFirstSpan(); span != null; span = span.next()) {
  186.                     if (!indices.containsKey(span.getData())) {
  187.                         indices.put(span.getData(), nbParams++);
  188.                     }
  189.                 }
  190.             }
  191.         }
  192.         final FieldVector3D<Gradient> zero = FieldVector3D.getZero(GradientField.getField(nbParams));

  193.         // Coordinates of the spacecraft expressed as a gradient
  194.         final TimeStampedFieldPVCoordinates<Gradient> pvaDS = getCoordinates(state, 0, nbParams);

  195.         // transform between station and inertial frame, expressed as a gradient
  196.         // The components of station's position in offset frame are the 3 last derivative parameters
  197.         final FieldTransform<Gradient> offsetToInertialRx =
  198.                 getReceiverStation().getOffsetToInertial(state.getFrame(), getDate(), nbParams, indices);
  199.         final FieldAbsoluteDate<Gradient> downlinkDateDS = offsetToInertialRx.getFieldDate();

  200.         // Station position in inertial frame at end of the downlink leg
  201.         final TimeStampedFieldPVCoordinates<Gradient> stationReceiver =
  202.                 offsetToInertialRx.transformPVCoordinates(new TimeStampedFieldPVCoordinates<>(downlinkDateDS,
  203.                         zero, zero, zero));

  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 tauD = signalTimeOfFlight(pvaDS, stationReceiver.getPosition(), downlinkDateDS);

  209.         // Transit state & Transit state (re)computed with gradients
  210.         final Gradient delta = downlinkDateDS.durationFrom(state.getDate());
  211.         final Gradient deltaMTauD = tauD.negate().add(delta);
  212.         final SpacecraftState transitState = state.shiftedBy(deltaMTauD.getValue());
  213.         final TimeStampedFieldPVCoordinates<Gradient> transitStateDS = pvaDS.shiftedBy(deltaMTauD);

  214.         // transform between secondary station topocentric frame (east-north-zenith) and inertial frame expressed as gradients
  215.         // The components of secondary station's position in offset frame are the 3 last derivative parameters
  216.         final FieldAbsoluteDate<Gradient> transitDate = downlinkDateDS.shiftedBy(tauD.negate());
  217.         final FieldTransform<Gradient> offsetToInertialTxApprox =
  218.                 getEmitterStation().getOffsetToInertial(state.getFrame(), transitDate, nbParams, indices);

  219.         // Secondary station PV in inertial frame at transit time
  220.         final TimeStampedFieldPVCoordinates<Gradient> transmitApprox =
  221.                 offsetToInertialTxApprox.transformPVCoordinates(new TimeStampedFieldPVCoordinates<>(transitDate,
  222.                         zero, zero, zero));

  223.         // Uplink time of flight from secondary station to transit state of leg2
  224.         final Gradient tauU = signalTimeOfFlight(transmitApprox, transitStateDS.getPosition(), transitStateDS.getDate());

  225.         // Total time of flight
  226.         final Gradient tauTotal = deltaMTauD.negate().add(tauU);

  227.         // Absolute date of transmission
  228.         final FieldAbsoluteDate<Gradient> transmitDateDS = downlinkDateDS.shiftedBy(tauTotal);
  229.         final FieldTransform<Gradient> transmitToInert =
  230.                 emitter.getOffsetToInertial(state.getFrame(), transmitDateDS, nbParams, indices);

  231.         // Secondary station PV in inertial frame at rebound date on secondary station
  232.         final TimeStampedFieldPVCoordinates<Gradient> stationTransmitter =
  233.                 transmitToInert.transformPVCoordinates(new TimeStampedFieldPVCoordinates<>(transmitDateDS,
  234.                         zero, zero, zero));

  235.         // Prepare the evaluation
  236.         final EstimatedMeasurement<BistaticRange> estimated = new EstimatedMeasurement<>(this,
  237.                 iteration, evaluation,
  238.                 new SpacecraftState[] {
  239.                     transitState
  240.                 },
  241.                 new TimeStampedPVCoordinates[] {
  242.                     stationReceiver.toTimeStampedPVCoordinates(),
  243.                     transitStateDS.toTimeStampedPVCoordinates(),
  244.                     stationTransmitter.toTimeStampedPVCoordinates()
  245.                 });

  246.         // Range value
  247.         final Gradient tau = tauD.add(tauU);
  248.         final Gradient range = tau.multiply(Constants.SPEED_OF_LIGHT);

  249.         estimated.setEstimatedValue(range.getValue());

  250.         // Range partial derivatives with respect to state
  251.         final double[] derivatives = range.getGradient();
  252.         estimated.setStateDerivatives(0, Arrays.copyOfRange(derivatives, 0, 6));

  253.         // set partial derivatives with respect to parameters
  254.         // (beware element at index 0 is the value, not a derivative)
  255.         for (final ParameterDriver driver : getParametersDrivers()) {
  256.             for (Span<String> span = driver.getNamesSpanMap().getFirstSpan(); span != null; span = span.next()) {
  257.                 final Integer index = indices.get(span.getData());
  258.                 if (index != null) {
  259.                     estimated.setParameterDerivatives(driver, span.getStart(), derivatives[index]);
  260.                 }
  261.             }
  262.         }

  263.         return estimated;
  264.     }

  265. }