1   /* Copyright 2002-2024 Thales Alenia Space
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.generation;
18  
19  import org.hipparchus.random.CorrelatedRandomVectorGenerator;
20  import org.orekit.estimation.measurements.EstimationModifier;
21  import org.orekit.estimation.measurements.ObservableSatellite;
22  import org.orekit.estimation.measurements.gnss.OneWayGNSSRangeRate;
23  import org.orekit.propagation.SpacecraftState;
24  import org.orekit.propagation.sampling.OrekitStepInterpolator;
25  import org.orekit.time.AbsoluteDate;
26  import org.orekit.utils.ParameterDriver;
27  
28  import java.util.Map;
29  
30  /** Builder for {@link org.orekit.estimation.measurements.gnss.OneWayGNSSRangeRate} measurements.
31   * @author Luc Maisonobe
32   * @since 12.1
33   */
34  public class OneWayGNSSRangeRateBuilder
35      extends AbstractMeasurementBuilder<OneWayGNSSRangeRate> {
36  
37      /** Satellite which receives the signal and performs the measurement. */
38      private final ObservableSatellite local;
39  
40      /** Satellite which simply emits the signal. */
41      private final ObservableSatellite remote;
42  
43      /** Simple constructor.
44       * @param noiseSource noise source, may be null for generating perfect measurements
45       * @param local satellite which receives the signal and performs the measurement
46       * @param remote satellite which simply emits the signal
47       * @param sigma theoretical standard deviation
48       * @param baseWeight base weight
49       */
50      public OneWayGNSSRangeRateBuilder(final CorrelatedRandomVectorGenerator noiseSource,
51                                        final ObservableSatellite local, final ObservableSatellite remote,
52                                        final double sigma, final double baseWeight) {
53          super(noiseSource, sigma, baseWeight, local, remote);
54          this.local  = local;
55          this.remote = remote;
56      }
57  
58      /** {@inheritDoc} */
59      @Override
60      public OneWayGNSSRangeRate build(final AbsoluteDate date,
61                                       final Map<ObservableSatellite, OrekitStepInterpolator> interpolators) {
62  
63          final double            sigma      = getTheoreticalStandardDeviation()[0];
64          final double            baseWeight = getBaseWeight()[0];
65          final SpacecraftState[] relevant   = new SpacecraftState[] {
66              interpolators.get(local).getInterpolatedState(date),
67              interpolators.get(remote).getInterpolatedState(date)
68          };
69  
70          // create a dummy measurement
71          final OneWayGNSSRangeRate dummy = new OneWayGNSSRangeRate(interpolators.get(remote),
72                                                                    remote.getQuadraticClockModel(), relevant[0].getDate(),
73                                                                    Double.NaN, sigma, baseWeight, local);
74          for (final EstimationModifier<OneWayGNSSRangeRate> modifier : getModifiers()) {
75              dummy.addModifier(modifier);
76          }
77  
78          // set a reference date for parameters missing one
79          for (final ParameterDriver driver : dummy.getParametersDrivers()) {
80              if (driver.getReferenceDate() == null) {
81                  final AbsoluteDate start = getStart();
82                  final AbsoluteDate end   = getEnd();
83                  driver.setReferenceDate(start.durationFrom(end) <= 0 ? start : end);
84              }
85          }
86  
87          // estimate the perfect value of the measurement
88          double rangeRate = dummy.estimateWithoutDerivatives(relevant).getEstimatedValue()[0];
89  
90          // add the noise
91          final double[] noise = getNoise();
92          if (noise != null) {
93              rangeRate += noise[0];
94          }
95  
96          // generate measurement
97          final OneWayGNSSRangeRate measurement = new OneWayGNSSRangeRate(interpolators.get(remote),
98                                                                          remote.getQuadraticClockModel(), relevant[0].getDate(),
99                                                                          rangeRate, sigma, baseWeight, local);
100         for (final EstimationModifier<OneWayGNSSRangeRate> modifier : getModifiers()) {
101             measurement.addModifier(modifier);
102         }
103         return measurement;
104 
105     }
106 
107 }