1   /* Copyright 2002-2025 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;
18  
19  import org.hipparchus.util.FastMath;
20  import org.orekit.utils.ParameterDriver;
21  
22  /** Class modeling a satellite that can be observed.
23   *
24   * @author Luc Maisonobe
25   * @since 9.3
26   */
27  public class ObservableSatellite {
28  
29      /** Prefix for clock offset parameter driver, the propagator index will be appended to it. */
30      public static final String CLOCK_OFFSET_PREFIX = "clock-offset-";
31  
32      /** Prefix for clock drift parameter driver, the propagator index will be appended to it. */
33      public static final String CLOCK_DRIFT_PREFIX = "clock-drift-";
34  
35      /** Prefix for clock acceleration parameter driver, the propagator index will be appended to it.
36       * @since 12.1
37       */
38      public static final String CLOCK_ACCELERATION_PREFIX = "clock-acceleration-";
39  
40      /** Clock offset scaling factor.
41       * <p>
42       * We use a power of 2 to avoid numeric noise introduction
43       * in the multiplications/divisions sequences.
44       * </p>
45       */
46      private static final double CLOCK_OFFSET_SCALE = FastMath.scalb(1.0, -10);
47  
48      /** Prefix for satellite names. */
49      private static final String SAT_PREFIX = "sat-";
50  
51      /** Index of the propagator related to this satellite. */
52      private final int propagatorIndex;
53  
54      /** Parameter driver for satellite clock offset. */
55      private final ParameterDriver clockOffsetDriver;
56  
57      /** Parameter driver for satellite clock drift. */
58      private final ParameterDriver clockDriftDriver;
59  
60      /** Parameter driver for satellite clock acceleration.
61       * @since 12.1
62       */
63      private final ParameterDriver clockAccelerationDriver;
64  
65      /** Name of the satellite.
66       * @since 13.0
67       */
68      private final String name;
69  
70      /** Simple constructor.
71       * <p>
72       * This constructor builds a default name based on the propagator index.
73       * </p>
74       * @param propagatorIndex index of the propagator related to this satellite
75       */
76      public ObservableSatellite(final int propagatorIndex) {
77          this(propagatorIndex, null);
78      }
79  
80      /** Simple constructor.
81       * @param propagatorIndex index of the propagator related to this satellite
82       * @param name satellite name (if null, a default name built from index will be used)
83       * @since 13.0
84       */
85      public ObservableSatellite(final int propagatorIndex, final String name) {
86          this.propagatorIndex   = propagatorIndex;
87          this.name              = name == null ? SAT_PREFIX + propagatorIndex : name;
88          this.clockOffsetDriver = new ParameterDriver(CLOCK_OFFSET_PREFIX + this.name,
89                                                       0.0, CLOCK_OFFSET_SCALE,
90                                                       Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY);
91          this.clockDriftDriver = new ParameterDriver(CLOCK_DRIFT_PREFIX + this.name,
92                                                      0.0, CLOCK_OFFSET_SCALE,
93                                                      Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY);
94          this.clockAccelerationDriver = new ParameterDriver(CLOCK_ACCELERATION_PREFIX + this.name,
95                                                             0.0, CLOCK_OFFSET_SCALE,
96                                                             Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY);
97      }
98  
99      /** Build a name for the satellite.
100      * <p>
101      * This is mainly useful to build the arguments for {@link
102      * org.orekit.estimation.measurements.gnss.AmbiguityCache#getAmbiguity(String,
103      * String, double)}
104      * </p>
105      * @return name for the satellite
106      * @since 12.1
107      */
108     public String getName() {
109         return name;
110     }
111 
112     /** Get the index of the propagator related to this satellite.
113      * @return index of the propagator related to this satellite
114      */
115     public int getPropagatorIndex() {
116         return propagatorIndex;
117     }
118 
119     /** Get the clock offset parameter driver.
120      * <p>
121      * The offset value is defined as the value in seconds that must be <em>subtracted</em> from
122      * the satellite clock reading of time to compute the real physical date. The offset
123      * is therefore negative if the satellite clock is slow and positive if it is fast.
124      * </p>
125      * @return clock offset parameter driver
126      */
127     public ParameterDriver getClockOffsetDriver() {
128         return clockOffsetDriver;
129     }
130 
131     /** Get the clock drift parameter driver.
132      * <p>
133      * The drift is negative if the satellite clock is slowing down and positive if it is speeding up.
134      * </p>
135      * @return clock drift parameter driver
136      * @since 10.3
137      */
138     public ParameterDriver getClockDriftDriver() {
139         return clockDriftDriver;
140     }
141 
142     /** Get the clock acceleration parameter driver.
143      * @return clock acceleration parameter driver
144      * @since 12.1
145      */
146     public ParameterDriver getClockAccelerationDriver() {
147         return clockAccelerationDriver;
148     }
149 
150     /** Get a quadratic clock model valid at some date.
151      * @return quadratic clock model
152      * @since 12.1
153      */
154     public QuadraticClockModel getQuadraticClockModel() {
155         return new QuadraticClockModel(clockOffsetDriver,
156                                        clockDriftDriver,
157                                        clockAccelerationDriver);
158     }
159 
160     /** {@inheritDoc}
161      * @since 12.0
162      */
163     @Override
164     public boolean equals(final Object other) {
165         if (other instanceof ObservableSatellite) {
166             return propagatorIndex == ((ObservableSatellite) other).propagatorIndex;
167         } else {
168             return false;
169 
170         }
171     }
172 
173     /** {@inheritDoc}
174      * @since 12.0
175      */
176     @Override
177     public int hashCode() {
178         return propagatorIndex;
179     }
180 
181 }