GPSBlockIIF.java

  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. import org.hipparchus.Field;
  19. import org.hipparchus.RealFieldElement;
  20. import org.hipparchus.util.FastMath;
  21. import org.orekit.frames.Frame;
  22. import org.orekit.time.AbsoluteDate;
  23. import org.orekit.utils.ExtendedPVCoordinatesProvider;
  24. import org.orekit.utils.TimeStampedAngularCoordinates;
  25. import org.orekit.utils.TimeStampedFieldAngularCoordinates;

  26. /**
  27.  * Attitude providers for GPS block IIF navigation satellites.
  28.  * <p>
  29.  * This class is based on the May 2017 version of J. Kouba eclips.f
  30.  * subroutine available at <a href="http://acc.igs.org/orbits">IGS Analysis
  31.  * Center Coordinator site</a>. The eclips.f code itself is not used ; its
  32.  * hard-coded data are used and its low level models are used, but the
  33.  * structure of the code and the API have been completely rewritten.
  34.  * </p>
  35.  * <p>
  36.  * WARNING: as of release 9.2, this feature is still considered experimental
  37.  * </p>
  38.  * @author J. Kouba original fortran routine
  39.  * @author Luc Maisonobe Java translation
  40.  * @since 9.2
  41.  */
  42. public class GPSBlockIIF extends AbstractGNSSAttitudeProvider {

  43.     /** Serializable UID. */
  44.     private static final long serialVersionUID = 20171114L;

  45.     /** Satellite-Sun angle limit for a midnight turn maneuver. */
  46.     private static final double NIGHT_TURN_LIMIT = FastMath.toRadians(180.0 - 13.25);

  47.     /** Bias. */
  48.     private static final double YAW_BIAS = FastMath.toRadians(-0.7);

  49.     /** Yaw rates for all spacecrafts. */
  50.     private static final double YAW_RATE = FastMath.toRadians(0.11);

  51.     /** Margin on turn end. */
  52.     private final double END_MARGIN = 1800.0;

  53.     /** Simple constructor.
  54.      * @param validityStart start of validity for this provider
  55.      * @param validityEnd end of validity for this provider
  56.      * @param sun provider for Sun position
  57.      * @param inertialFrame inertial frame where velocity are computed
  58.      */
  59.     public GPSBlockIIF(final AbsoluteDate validityStart, final AbsoluteDate validityEnd,
  60.                        final ExtendedPVCoordinatesProvider sun, final Frame inertialFrame) {
  61.         super(validityStart, validityEnd, sun, inertialFrame);
  62.     }

  63.     /** {@inheritDoc} */
  64.     @Override
  65.     protected TimeStampedAngularCoordinates correctedYaw(final GNSSAttitudeContext context) {

  66.         // noon beta angle limit from yaw rate
  67.         final double aNoon  = FastMath.atan(context.getMuRate() / YAW_RATE);
  68.         final double aNight = NIGHT_TURN_LIMIT;
  69.         final double cNoon  = FastMath.cos(aNoon);
  70.         final double cNight = FastMath.cos(aNight);

  71.         if (context.setUpTurnRegion(cNight, cNoon)) {

  72.             final double absBeta = FastMath.abs(context.getBeta());
  73.             context.setHalfSpan(context.inSunSide() ?
  74.                                 absBeta * FastMath.sqrt(aNoon / absBeta - 1.0) :
  75.                                 context.inOrbitPlaneAbsoluteAngle(aNight - FastMath.PI));
  76.             if (context.inTurnTimeRange(context.getDate(), END_MARGIN)) {

  77.                 // we need to ensure beta sign does not change during the turn
  78.                 final double beta     = context.getSecuredBeta();
  79.                 final double phiStart = context.getYawStart(beta);
  80.                 final double dtStart  = context.timeSinceTurnStart(context.getDate());
  81.                 final double phiDot;
  82.                 final double linearPhi;
  83.                 if (context.inSunSide()) {
  84.                     // noon turn
  85.                     if (beta > YAW_BIAS && beta < 0) {
  86.                         // noon turn problem for small negative beta in block IIF
  87.                         // rotation is in the wrong direction for these spacecrafts
  88.                         phiDot    = FastMath.copySign(YAW_RATE, beta);
  89.                         linearPhi = phiStart + phiDot * dtStart;
  90.                     } else {
  91.                         // regular noon turn
  92.                         phiDot    = -FastMath.copySign(YAW_RATE, beta);
  93.                         linearPhi = phiStart + phiDot * dtStart;
  94.                     }
  95.                 } else {
  96.                     // midnight turn
  97.                     phiDot    = context.yawRate(beta);
  98.                     linearPhi = phiStart + phiDot * dtStart;
  99.                 }

  100.                 return context.turnCorrectedAttitude(linearPhi, phiDot);

  101.             }

  102.         }

  103.         // in nominal yaw mode
  104.         return context.getNominalYaw();

  105.     }

  106.     /** {@inheritDoc} */
  107.     @Override
  108.     protected <T extends RealFieldElement<T>> TimeStampedFieldAngularCoordinates<T> correctedYaw(final GNSSFieldAttitudeContext<T> context) {

  109.         final Field<T> field = context.getDate().getField();

  110.         // noon beta angle limit from yaw rate
  111.         final T      aNoon  = FastMath.atan(context.getMuRate().divide(YAW_RATE));
  112.         final T      aNight = field.getZero().add(NIGHT_TURN_LIMIT);
  113.         final double cNoon  = FastMath.cos(aNoon.getReal());
  114.         final double cNight = FastMath.cos(aNight.getReal());

  115.         if (context.setUpTurnRegion(cNight, cNoon)) {

  116.             final T absBeta = FastMath.abs(context.getBeta());
  117.             context.setHalfSpan(context.inSunSide() ?
  118.                                 absBeta.multiply(FastMath.sqrt(aNoon.divide(absBeta).subtract(1.0))) :
  119.                                 context.inOrbitPlaneAbsoluteAngle(aNight.subtract(FastMath.PI)));
  120.             if (context.inTurnTimeRange(context.getDate(), END_MARGIN)) {

  121.                 // we need to ensure beta sign does not change during the turn
  122.                 final T beta     = context.getSecuredBeta();
  123.                 final T phiStart = context.getYawStart(beta);
  124.                 final T dtStart  = context.timeSinceTurnStart(context.getDate());
  125.                 final T phiDot;
  126.                 final T linearPhi;
  127.                 if (context.inSunSide()) {
  128.                     // noon turn
  129.                     if (beta.getReal() > YAW_BIAS && beta.getReal() < 0) {
  130.                         // noon turn problem for small negative beta in block IIF
  131.                         // rotation is in the wrong direction for these spacecrafts
  132.                         phiDot    = field.getZero().add(FastMath.copySign(YAW_RATE, beta.getReal()));
  133.                         linearPhi = phiStart.add(phiDot.multiply(dtStart));
  134.                     } else {
  135.                         // regular noon turn
  136.                         phiDot    = field.getZero().add(-FastMath.copySign(YAW_RATE, beta.getReal()));
  137.                         linearPhi = phiStart.add(phiDot.multiply(dtStart));
  138.                     }
  139.                 } else {
  140.                     // midnight turn
  141.                     phiDot    = context.yawRate(beta);
  142.                     linearPhi = phiStart.add(phiDot.multiply(dtStart));
  143.                 }

  144.                 return context.turnCorrectedAttitude(linearPhi, phiDot);

  145.             }

  146.         }

  147.         // in nominal yaw mode
  148.         return context.getNominalYaw();

  149.     }

  150. }