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.InterSatellitesOneWayRangeRate;
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.InterSatellitesOneWayRangeRate} measurements.
31   * @author Luc Maisonobe
32   * @since 12.1
33   */
34  public class InterSatellitesOneWayRangeRateBuilder
35      extends AbstractMeasurementBuilder<InterSatellitesOneWayRangeRate> {
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 InterSatellitesOneWayRangeRateBuilder(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 InterSatellitesOneWayRangeRate 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 InterSatellitesOneWayRangeRate dummy = new InterSatellitesOneWayRangeRate(local, remote, relevant[0].getDate(),
72                                                                                          Double.NaN, sigma, baseWeight);
73          for (final EstimationModifier<InterSatellitesOneWayRangeRate> modifier : getModifiers()) {
74              dummy.addModifier(modifier);
75          }
76  
77          // set a reference date for parameters missing one
78          for (final ParameterDriver driver : dummy.getParametersDrivers()) {
79              if (driver.getReferenceDate() == null) {
80                  final AbsoluteDate start = getStart();
81                  final AbsoluteDate end   = getEnd();
82                  driver.setReferenceDate(start.durationFrom(end) <= 0 ? start : end);
83              }
84          }
85  
86          // estimate the perfect value of the measurement
87          double rangeRate = dummy.estimateWithoutDerivatives(relevant).getEstimatedValue()[0];
88  
89          // add the noise
90          final double[] noise = getNoise();
91          if (noise != null) {
92              rangeRate += noise[0];
93          }
94  
95          // generate measurement
96          final InterSatellitesOneWayRangeRate measurement = new InterSatellitesOneWayRangeRate(local, remote, relevant[0].getDate(),
97                                                                                                rangeRate, sigma, baseWeight);
98          for (final EstimationModifier<InterSatellitesOneWayRangeRate> modifier : getModifiers()) {
99              measurement.addModifier(modifier);
100         }
101         return measurement;
102 
103     }
104 
105 }