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