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.modifiers;
18  
19  import java.util.Collections;
20  import java.util.List;
21  
22  import org.hipparchus.geometry.euclidean.threed.Vector3D;
23  import org.orekit.attitudes.AttitudeProvider;
24  import org.orekit.estimation.measurements.EstimatedMeasurement;
25  import org.orekit.estimation.measurements.EstimationModifier;
26  import org.orekit.estimation.measurements.gnss.OneWayGNSSRange;
27  import org.orekit.frames.Transform;
28  import org.orekit.orbits.CartesianOrbit;
29  import org.orekit.orbits.Orbit;
30  import org.orekit.propagation.SpacecraftState;
31  import org.orekit.time.AbsoluteDate;
32  import org.orekit.utils.ParameterDriver;
33  import org.orekit.utils.TimeStampedPVCoordinates;
34  
35  /** On-board antenna offset effect on one-way GNSS range measurements.
36   * @author Bryan Cazabonne
37   * @since 10.3
38   */
39  public class OnBoardAntennaOneWayGNSSRangeModifier implements EstimationModifier<OneWayGNSSRange> {
40  
41      /** Position of the Antenna Phase Center in satellite 1 frame. */
42      private final Vector3D antennaPhaseCenter1;
43  
44      /** Position of the Antenna Phase Center in satellite 2 frame. */
45      private final Vector3D antennaPhaseCenter2;
46  
47      /** Attitude provider of the emitting satellite. */
48      private final AttitudeProvider attitude;
49  
50      /** Simple constructor.
51       * @param antennaPhaseCenter1 position of the Antenna Phase Center in satellite 1 frame
52       * (i.e. the satellite which receives the signal and performs the measurement)
53       * @param antennaPhaseCenter2 position of the Antenna Phase Center in satellite 2 frame
54       * (i.e. the satellite which simply emits the signal)
55       * @param attitude attitude provider of the emitting satellite
56       */
57      public OnBoardAntennaOneWayGNSSRangeModifier(final Vector3D antennaPhaseCenter1,
58                                                   final Vector3D antennaPhaseCenter2,
59                                                   final AttitudeProvider attitude) {
60          this.antennaPhaseCenter1 = antennaPhaseCenter1;
61          this.antennaPhaseCenter2 = antennaPhaseCenter2;
62          this.attitude            = attitude;
63      }
64  
65      /** {@inheritDoc} */
66      @Override
67      public List<ParameterDriver> getParametersDrivers() {
68          return Collections.emptyList();
69      }
70  
71      /** {@inheritDoc} */
72      @Override
73      public void modify(final EstimatedMeasurement<OneWayGNSSRange> estimated) {
74  
75          // The participants are remote satellite at emission, local satellite at reception
76          final TimeStampedPVCoordinates[] participants  = estimated.getParticipants();
77          final AbsoluteDate               emissionDate  = participants[0].getDate();
78          final AbsoluteDate               receptionDate = participants[1].getDate();
79  
80          // Transforms from spacecraft to inertial frame at reception date
81          final SpacecraftState refStateLocal              = estimated.getStates()[0];
82          final SpacecraftState receptionState             = refStateLocal.shiftedBy(receptionDate.durationFrom(refStateLocal.getDate()));
83          final Transform       receptionSpacecraftToInert = receptionState.toTransform().getInverse();
84  
85          // Orbit of the remote satellite
86          final Orbit orbitRemote = new CartesianOrbit(participants[0], refStateLocal.getFrame(), receptionState.getMu());
87  
88          // Transforms from spacecraft to inertial frame at emission date
89          final SpacecraftState refStateRemote             = new SpacecraftState(orbitRemote,
90                                                                                 attitude.getAttitude(orbitRemote,
91                                                                                                      orbitRemote.getDate(),
92                                                                                                      orbitRemote.getFrame()));
93          final SpacecraftState emissionState              = refStateRemote.shiftedBy(emissionDate.durationFrom(refStateRemote.getDate()));
94          final Transform       emissionSpacecraftToInert  = emissionState.toTransform().getInverse();
95  
96          // Compute the geometrical value of the one-way GNSS range directly from participants positions.
97          // Note that this may be different from the value returned by estimated.getEstimatedValue(),
98          // because other modifiers may already have been taken into account
99          final Vector3D pSpacecraftReception = receptionSpacecraftToInert.transformPosition(Vector3D.ZERO);
100         final Vector3D pSpacecraftEmission  = emissionSpacecraftToInert.transformPosition(Vector3D.ZERO);
101         final double oneWayGNSSRangeUsingSpacecraftCenter = Vector3D.distance(pSpacecraftEmission, pSpacecraftReception);
102 
103         // Compute the geometrical value of the range replacing
104         // the spacecraft positions with antenna phase center positions
105         final Vector3D pAPCReception = receptionSpacecraftToInert.transformPosition(antennaPhaseCenter1);
106         final Vector3D pAPCEmission  = emissionSpacecraftToInert.transformPosition(antennaPhaseCenter2);
107         final double oneWayGNSSRangeUsingAntennaPhaseCenter = Vector3D.distance(pAPCEmission, pAPCReception);
108 
109         // Get the estimated value before this modifier is applied
110         final double[] value = estimated.getEstimatedValue();
111 
112         // Modify the value
113         value[0] += oneWayGNSSRangeUsingAntennaPhaseCenter - oneWayGNSSRangeUsingSpacecraftCenter;
114         estimated.setEstimatedValue(value);
115 
116     }
117 
118 }