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