GPSBlockIIA.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 IIR 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 GPSBlockIIA 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.5);

  49.     /** Yaw rates for all spacecrafts. */
  50.     private static final double[] YAW_RATES = new double[] {
  51.         0.1211, 0.1339, 0.1230, 0.1233, 0.1180, 0.1266, 0.1269, 0.1033,
  52.         0.1278, 0.0978, 0.2000, 0.1990, 0.2000, 0.0815, 0.1303, 0.0838,
  53.         0.1401, 0.1069, 0.0980, 0.1030, 0.1366, 0.1025, 0.1140, 0.1089,
  54.         0.1001, 0.1227, 0.1194, 0.1260, 0.1228, 0.1165, 0.0969, 0.1140
  55.     };

  56.     /** Margin on turn end. */
  57.     private final double END_MARGIN = 1800.0;

  58.     /** Yaw rate for current spacecraft. */
  59.     private final double yawRate;

  60.     /** Simple constructor.
  61.      * @param validityStart start of validity for this provider
  62.      * @param validityEnd end of validity for this provider
  63.      * @param sun provider for Sun position
  64.      * @param inertialFrame inertial frame where velocity are computed
  65.      * @param prnNumber number within the GPS constellation (between 1 and 32)
  66.      */
  67.     public GPSBlockIIA(final AbsoluteDate validityStart, final AbsoluteDate validityEnd,
  68.                        final ExtendedPVCoordinatesProvider sun, final Frame inertialFrame, final int prnNumber) {
  69.         super(validityStart, validityEnd, sun, inertialFrame);
  70.         yawRate = FastMath.toRadians(YAW_RATES[prnNumber - 1]);
  71.     }

  72.     /** {@inheritDoc} */
  73.     @Override
  74.     protected TimeStampedAngularCoordinates correctedYaw(final GNSSAttitudeContext context) {

  75.         // noon beta angle limit from yaw rate
  76.         final double aNoon  = FastMath.atan(context.getMuRate() / yawRate);
  77.         final double aNight = NIGHT_TURN_LIMIT;
  78.         final double cNoon  = FastMath.cos(aNoon);
  79.         final double cNight = FastMath.cos(aNight);

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

  81.             final double absBeta = FastMath.abs(context.getBeta());
  82.             context.setHalfSpan(context.inSunSide() ?
  83.                                 absBeta * FastMath.sqrt(aNoon / absBeta - 1.0) :
  84.                                 context.inOrbitPlaneAbsoluteAngle(aNight - FastMath.PI));
  85.             if (context.inTurnTimeRange(context.getDate(), END_MARGIN)) {

  86.                 // we need to ensure beta sign does not change during the turn
  87.                 final double beta     = context.getSecuredBeta();
  88.                 final double phiStart = context.getYawStart(beta);
  89.                 final double dtStart  = context.timeSinceTurnStart(context.getDate());
  90.                 final double linearPhi;
  91.                 final double phiDot;
  92.                 if (context.inSunSide()) {
  93.                     // noon turn
  94.                     if (beta > 0 && beta < YAW_BIAS) {
  95.                         // noon turn problem for small positive beta in block IIA
  96.                         // rotation is in the wrong direction for these spacecrafts
  97.                         phiDot    = FastMath.copySign(yawRate, beta);
  98.                         linearPhi = phiStart + phiDot * dtStart;
  99.                     } else {
  100.                         // regular noon turn
  101.                         phiDot    = -FastMath.copySign(yawRate, beta);
  102.                         linearPhi = phiStart + phiDot * dtStart;
  103.                     }
  104.                 } else {
  105.                     // midnight turn
  106.                     final double dtEnd = dtStart - context.getTurnDuration();
  107.                     if (dtEnd < 0) {
  108.                         // we are within the turn itself
  109.                         phiDot    = yawRate;
  110.                         linearPhi = phiStart + phiDot * dtStart;
  111.                     } else {
  112.                         // we are in the recovery phase after turn
  113.                         phiDot = yawRate;
  114.                         final double phiEnd   = phiStart + phiDot * context.getTurnDuration();
  115.                         final double deltaPhi = context.yawAngle() - phiEnd;
  116.                         if (FastMath.abs(deltaPhi / phiDot) <= dtEnd) {
  117.                             // time since turn end was sufficient for recovery
  118.                             // we are already back in nominal yaw mode
  119.                             return context.getNominalYaw();
  120.                         } else {
  121.                             // recovery is not finished yet
  122.                             linearPhi = phiEnd + FastMath.copySign(yawRate * dtEnd, deltaPhi);
  123.                         }
  124.                     }
  125.                 }

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

  127.             }

  128.         }

  129.         // in nominal yaw mode
  130.         return context.getNominalYaw();

  131.     }

  132.     /** {@inheritDoc} */
  133.     @Override
  134.     protected <T extends RealFieldElement<T>> TimeStampedFieldAngularCoordinates<T> correctedYaw(final GNSSFieldAttitudeContext<T> context) {

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

  136.         // noon beta angle limit from yaw rate
  137.         final T      aNoon  = FastMath.atan(context.getMuRate().divide(yawRate));
  138.         final T      aNight = field.getZero().add(NIGHT_TURN_LIMIT);
  139.         final double cNoon  = FastMath.cos(aNoon.getReal());
  140.         final double cNight = FastMath.cos(aNight.getReal());

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

  142.             final T absBeta = FastMath.abs(context.getBeta());
  143.             context.setHalfSpan(context.inSunSide() ?
  144.                                 absBeta.multiply(FastMath.sqrt(aNoon.divide(absBeta).subtract(1.0))) :
  145.                                 context.inOrbitPlaneAbsoluteAngle(aNight.subtract(FastMath.PI)));
  146.             if (context.inTurnTimeRange(context.getDate(), END_MARGIN)) {

  147.                 // we need to ensure beta sign does not change during the turn
  148.                 final T beta     = context.getSecuredBeta();
  149.                 final T phiStart = context.getYawStart(beta);
  150.                 final T dtStart  = context.timeSinceTurnStart(context.getDate());
  151.                 final T linearPhi;
  152.                 final T phiDot;
  153.                 if (context.inSunSide()) {
  154.                     // noon turn
  155.                     if (beta.getReal() > 0 && beta.getReal() < YAW_BIAS) {
  156.                         // noon turn problem for small positive beta in block IIA
  157.                         // rotation is in the wrong direction for these spacecrafts
  158.                         phiDot    = field.getZero().add(FastMath.copySign(yawRate, beta.getReal()));
  159.                         linearPhi = phiStart.add(phiDot.multiply(dtStart));
  160.                     } else {
  161.                         // regular noon turn
  162.                         phiDot    = field.getZero().add(-FastMath.copySign(yawRate, beta.getReal()));
  163.                         linearPhi = phiStart.add(phiDot.multiply(dtStart));
  164.                     }
  165.                 } else {
  166.                     // midnight turn
  167.                     final T dtEnd = dtStart.subtract(context.getTurnDuration());
  168.                     if (dtEnd.getReal() < 0) {
  169.                         // we are within the turn itself
  170.                         phiDot    = field.getZero().add(yawRate);
  171.                         linearPhi = phiStart.add(phiDot.multiply(dtStart));
  172.                     } else {
  173.                         // we are in the recovery phase after turn
  174.                         phiDot = field.getZero().add(yawRate);
  175.                         final T phiEnd   = phiStart.add(phiDot.multiply(context.getTurnDuration()));
  176.                         final T deltaPhi = context.yawAngle().subtract(phiEnd);
  177.                         if (FastMath.abs(deltaPhi.divide(phiDot).getReal()) <= dtEnd.getReal()) {
  178.                             // time since turn end was sufficient for recovery
  179.                             // we are already back in nominal yaw mode
  180.                             return context.getNominalYaw();
  181.                         } else {
  182.                             // recovery is not finished yet
  183.                             linearPhi = phiEnd.add(dtEnd.multiply(yawRate).copySign(deltaPhi));
  184.                         }
  185.                     }
  186.                 }

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

  188.             }

  189.         }

  190.         // in nominal yaw mode
  191.         return context.getNominalYaw();

  192.     }

  193. }