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.gnss;
18  
19  import java.util.Collections;
20  import java.util.List;
21  
22  import org.hipparchus.geometry.euclidean.threed.Rotation;
23  import org.hipparchus.geometry.euclidean.threed.Vector3D;
24  import org.hipparchus.util.FastMath;
25  import org.hipparchus.util.MathUtils;
26  import org.orekit.estimation.measurements.EstimatedMeasurementBase;
27  import org.orekit.estimation.measurements.EstimationModifier;
28  import org.orekit.estimation.measurements.ObservedMeasurement;
29  import org.orekit.utils.ParameterDriver;
30  import org.orekit.utils.TimeStampedPVCoordinates;
31  
32  /** Base class for wind-up effect computation.
33   * @see <a href="https://gssc.esa.int/navipedia/index.php/Carrier_Phase_Wind-up_Effect">Carrier Phase Wind-up Effect</a>
34   * @param <T> the type of the measurement
35   * @author Luc Maisonobe
36   * @since 12.0
37   */
38  public abstract class AbstractWindUp<T extends ObservedMeasurement<T>> implements EstimationModifier<T> {
39  
40      /** Emitter dipole. */
41      private final Dipole emitter;
42  
43      /** Receiver dipole. */
44      private final Dipole receiver;
45  
46      /** Cached angular value of wind-up. */
47      private double angularWindUp;
48  
49      /** Simple constructor.
50       * @param emitter emitter dipole
51       * @param receiver receiver dipole
52       */
53      protected AbstractWindUp(final Dipole emitter, final Dipole receiver) {
54          this.emitter  = emitter;
55          this.receiver = receiver;
56          angularWindUp = 0.0;
57      }
58  
59      /** {@inheritDoc} */
60      @Override
61      public String getEffectName() {
62          return "wind-up";
63      }
64  
65      /** {@inheritDoc}
66       * <p>
67       * Wind-up effect has no parameters, the returned list is always empty.
68       * </p>
69       */
70      @Override
71      public List<ParameterDriver> getParametersDrivers() {
72          return Collections.emptyList();
73      }
74  
75      /** Compute rotation from emitter to inertial frame.
76       * @param estimated estimated measurement to modify
77       * @return rotation from emitter to inertial frame
78       */
79      protected abstract Rotation emitterToInert(EstimatedMeasurementBase<T> estimated);
80  
81      /** Compute rotation from receiver to inertial frame.
82       * @param estimated estimated measurement to modify
83       * @return rotation from receiver to inertial frame
84       */
85      protected abstract Rotation receiverToInert(EstimatedMeasurementBase<T> estimated);
86  
87      /** Cache angular wind-up.
88       * @param participants particpants to the carrier-phase measurement
89       * @param receiverToInert rotation for receiver to inertial frame
90       * @param emitterToInert rotation from emitter to inertial frame
91       * @since 13.0
92       */
93      public void cacheAngularWindUp(final TimeStampedPVCoordinates[] participants,
94                                     final Rotation receiverToInert, final Rotation emitterToInert) {
95  
96          // signal line of sight
97          final Vector3D los = participants[1].getPosition().subtract(participants[0].getPosition()).normalize();
98  
99          // get receiver dipole
100         final Vector3D iReceiver       = receiverToInert.applyTo(receiver.getPrimary());
101         final Vector3D jReceiver       = receiverToInert.applyTo(receiver.getSecondary());
102         final Vector3D dReceiver       = new Vector3D(1.0, iReceiver, -Vector3D.dotProduct(iReceiver, los), los).
103                                          add(Vector3D.crossProduct(los, jReceiver));
104 
105         // get emitter dipole
106         final Vector3D iEmitter       = emitterToInert.applyTo(emitter.getPrimary());
107         final Vector3D jEmitter       = emitterToInert.applyTo(emitter.getSecondary());
108         final Vector3D dEmitter       = new Vector3D(1.0, iEmitter, -Vector3D.dotProduct(iEmitter, los), los).
109                                         subtract(Vector3D.crossProduct(los, jEmitter));
110 
111         // raw correction
112         final double correction = FastMath.copySign(Vector3D.angle(dEmitter, dReceiver),
113                                                     Vector3D.dotProduct(los, Vector3D.crossProduct(dEmitter, dReceiver)));
114 
115         // ensure continuity across measurements
116         // we assume the various measurements are close enough in time
117         // (less the one satellite half-turn) so the angles remain close
118         angularWindUp = MathUtils.normalizeAngle(correction, angularWindUp);
119 
120     }
121 
122     /** Get cached value of angular wind-up.
123      * @return cached value of angular wind-up
124      * @since 13.0
125      */
126     public double getAngularWindUp() {
127         return angularWindUp;
128     }
129 
130     /** {@inheritDoc} */
131     @Override
132     public void modifyWithoutDerivatives(final EstimatedMeasurementBase<T> estimated) {
133 
134         // cache new angular wind-up
135         final TimeStampedPVCoordinates[] participants = estimated.getParticipants();
136         final Rotation receiverToInert = receiverToInert(estimated);
137         final Rotation emitterToInert = emitterToInert(estimated);
138         cacheAngularWindUp(participants, receiverToInert, emitterToInert);
139 
140         // update estimate
141         estimated.modifyEstimatedValue(this, estimated.getEstimatedValue()[0] + angularWindUp / MathUtils.TWO_PI);
142 
143     }
144 
145 }