1   /* Copyright 2002-2018 CS Systèmes d'Information
2    * Licensed to CS Systèmes d'Information (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.gnss.attitude;
18  
19  import org.hipparchus.Field;
20  import org.hipparchus.RealFieldElement;
21  import org.hipparchus.util.FastMath;
22  import org.orekit.frames.Frame;
23  import org.orekit.time.AbsoluteDate;
24  import org.orekit.utils.ExtendedPVCoordinatesProvider;
25  import org.orekit.utils.TimeStampedAngularCoordinates;
26  import org.orekit.utils.TimeStampedFieldAngularCoordinates;
27  
28  /**
29   * Attitude providers for GPS block IIF navigation satellites.
30   * <p>
31   * This class is based on the May 2017 version of J. Kouba eclips.f
32   * subroutine available at <a href="http://acc.igs.org/orbits">IGS Analysis
33   * Center Coordinator site</a>. The eclips.f code itself is not used ; its
34   * hard-coded data are used and its low level models are used, but the
35   * structure of the code and the API have been completely rewritten.
36   * </p>
37   * <p>
38   * WARNING: as of release 9.2, this feature is still considered experimental
39   * </p>
40   * @author J. Kouba original fortran routine
41   * @author Luc Maisonobe Java translation
42   * @since 9.2
43   */
44  public class GPSBlockIIF extends AbstractGNSSAttitudeProvider {
45  
46      /** Serializable UID. */
47      private static final long serialVersionUID = 20171114L;
48  
49      /** Satellite-Sun angle limit for a midnight turn maneuver. */
50      private static final double NIGHT_TURN_LIMIT = FastMath.toRadians(180.0 - 13.25);
51  
52      /** Bias. */
53      private static final double YAW_BIAS = FastMath.toRadians(-0.7);
54  
55      /** Yaw rates for all spacecrafts. */
56      private static final double YAW_RATE = FastMath.toRadians(0.11);
57  
58      /** Margin on turn end. */
59      private final double END_MARGIN = 1800.0;
60  
61      /** Simple constructor.
62       * @param validityStart start of validity for this provider
63       * @param validityEnd end of validity for this provider
64       * @param sun provider for Sun position
65       * @param inertialFrame inertial frame where velocity are computed
66       */
67      public GPSBlockIIF(final AbsoluteDate validityStart, final AbsoluteDate validityEnd,
68                         final ExtendedPVCoordinatesProvider sun, final Frame inertialFrame) {
69          super(validityStart, validityEnd, sun, inertialFrame);
70      }
71  
72      /** {@inheritDoc} */
73      @Override
74      protected TimeStampedAngularCoordinates correctedYaw(final GNSSAttitudeContext context) {
75  
76          // noon beta angle limit from yaw rate
77          final double aNoon  = FastMath.atan(context.getMuRate() / YAW_RATE);
78          final double aNight = NIGHT_TURN_LIMIT;
79          final double cNoon  = FastMath.cos(aNoon);
80          final double cNight = FastMath.cos(aNight);
81  
82          if (context.setUpTurnRegion(cNight, cNoon)) {
83  
84              final double absBeta = FastMath.abs(context.getBeta());
85              context.setHalfSpan(context.inSunSide() ?
86                                  absBeta * FastMath.sqrt(aNoon / absBeta - 1.0) :
87                                  context.inOrbitPlaneAbsoluteAngle(aNight - FastMath.PI));
88              if (context.inTurnTimeRange(context.getDate(), END_MARGIN)) {
89  
90                  // we need to ensure beta sign does not change during the turn
91                  final double beta     = context.getSecuredBeta();
92                  final double phiStart = context.getYawStart(beta);
93                  final double dtStart  = context.timeSinceTurnStart(context.getDate());
94                  final double phiDot;
95                  final double linearPhi;
96                  if (context.inSunSide()) {
97                      // noon turn
98                      if (beta > YAW_BIAS && beta < 0) {
99                          // noon turn problem for small negative beta in block IIF
100                         // rotation is in the wrong direction for these spacecrafts
101                         phiDot    = FastMath.copySign(YAW_RATE, beta);
102                         linearPhi = phiStart + phiDot * dtStart;
103                     } else {
104                         // regular noon turn
105                         phiDot    = -FastMath.copySign(YAW_RATE, beta);
106                         linearPhi = phiStart + phiDot * dtStart;
107                     }
108                 } else {
109                     // midnight turn
110                     phiDot    = context.yawRate(beta);
111                     linearPhi = phiStart + phiDot * dtStart;
112                 }
113 
114                 return context.turnCorrectedAttitude(linearPhi, phiDot);
115 
116             }
117 
118         }
119 
120         // in nominal yaw mode
121         return context.getNominalYaw();
122 
123     }
124 
125     /** {@inheritDoc} */
126     @Override
127     protected <T extends RealFieldElement<T>> TimeStampedFieldAngularCoordinates<T> correctedYaw(final GNSSFieldAttitudeContext<T> context) {
128 
129         final Field<T> field = context.getDate().getField();
130 
131         // noon beta angle limit from yaw rate
132         final T      aNoon  = FastMath.atan(context.getMuRate().divide(YAW_RATE));
133         final T      aNight = field.getZero().add(NIGHT_TURN_LIMIT);
134         final double cNoon  = FastMath.cos(aNoon.getReal());
135         final double cNight = FastMath.cos(aNight.getReal());
136 
137         if (context.setUpTurnRegion(cNight, cNoon)) {
138 
139             final T absBeta = FastMath.abs(context.getBeta());
140             context.setHalfSpan(context.inSunSide() ?
141                                 absBeta.multiply(FastMath.sqrt(aNoon.divide(absBeta).subtract(1.0))) :
142                                 context.inOrbitPlaneAbsoluteAngle(aNight.subtract(FastMath.PI)));
143             if (context.inTurnTimeRange(context.getDate(), END_MARGIN)) {
144 
145                 // we need to ensure beta sign does not change during the turn
146                 final T beta     = context.getSecuredBeta();
147                 final T phiStart = context.getYawStart(beta);
148                 final T dtStart  = context.timeSinceTurnStart(context.getDate());
149                 final T phiDot;
150                 final T linearPhi;
151                 if (context.inSunSide()) {
152                     // noon turn
153                     if (beta.getReal() > YAW_BIAS && beta.getReal() < 0) {
154                         // noon turn problem for small negative beta in block IIF
155                         // rotation is in the wrong direction for these spacecrafts
156                         phiDot    = field.getZero().add(FastMath.copySign(YAW_RATE, beta.getReal()));
157                         linearPhi = phiStart.add(phiDot.multiply(dtStart));
158                     } else {
159                         // regular noon turn
160                         phiDot    = field.getZero().add(-FastMath.copySign(YAW_RATE, beta.getReal()));
161                         linearPhi = phiStart.add(phiDot.multiply(dtStart));
162                     }
163                 } else {
164                     // midnight turn
165                     phiDot    = context.yawRate(beta);
166                     linearPhi = phiStart.add(phiDot.multiply(dtStart));
167                 }
168 
169                 return context.turnCorrectedAttitude(linearPhi, phiDot);
170 
171             }
172 
173         }
174 
175         // in nominal yaw mode
176         return context.getNominalYaw();
177 
178     }
179 
180 }