GPSBlockIIR.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 GPSBlockIIR extends AbstractGNSSAttitudeProvider {

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

  45.     /** Yaw rates for all spacecrafts. */
  46.     private static final double YAW_RATE = FastMath.toRadians(0.2);

  47.     /** Margin on turn end. */
  48.     private final double END_MARGIN = 1800.0;

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

  59.     /** {@inheritDoc} */
  60.     @Override
  61.     protected TimeStampedAngularCoordinates correctedYaw(final GNSSAttitudeContext context) {

  62.         // noon beta angle limit from yaw rate
  63.         final double aNoon  = FastMath.atan(context.getMuRate() / YAW_RATE);
  64.         final double cNoon  = FastMath.cos(aNoon);
  65.         final double cNight = -cNoon;

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

  67.             final double absBeta = FastMath.abs(context.getBeta());
  68.             context.setHalfSpan(absBeta * FastMath.sqrt(aNoon / absBeta - 1.0));
  69.             if (context.inTurnTimeRange(context.getDate(), END_MARGIN)) {

  70.                 // we need to ensure beta sign does not change during the turn
  71.                 final double beta     = context.getSecuredBeta();
  72.                 final double phiStart = context.getYawStart(beta);
  73.                 final double dtStart  = context.timeSinceTurnStart(context.getDate());
  74.                 final double phiDot;
  75.                 final double linearPhi;

  76.                 if (context.inSunSide()) {
  77.                     // noon turn
  78.                     phiDot    = -FastMath.copySign(YAW_RATE, beta);
  79.                     linearPhi = phiStart + phiDot * dtStart;
  80.                 } else {
  81.                     // midnight turn
  82.                     phiDot    = FastMath.copySign(YAW_RATE, beta);
  83.                     linearPhi = phiStart + phiDot * dtStart;
  84.                     final double phiEnd = context.getYawEnd(beta);
  85.                     if (phiEnd / linearPhi < 0 || phiEnd / linearPhi > 1) {
  86.                         return context.getNominalYaw();
  87.                     }
  88.                 }

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

  90.             }

  91.         }

  92.         // in nominal yaw mode
  93.         return context.getNominalYaw();

  94.     }

  95.     /** {@inheritDoc} */
  96.     @Override
  97.     protected <T extends RealFieldElement<T>> TimeStampedFieldAngularCoordinates<T> correctedYaw(final GNSSFieldAttitudeContext<T> context) {

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

  99.         // noon beta angle limit from yaw rate
  100.         final T      aNoon  = FastMath.atan(context.getMuRate().divide(YAW_RATE));
  101.         final double cNoon  = FastMath.cos(aNoon.getReal());
  102.         final double cNight = -cNoon;

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

  104.             final T absBeta = FastMath.abs(context.getBeta());
  105.             context.setHalfSpan(absBeta.multiply(FastMath.sqrt(aNoon.divide(absBeta).subtract(1.0))));
  106.             if (context.inTurnTimeRange(context.getDate(), END_MARGIN)) {

  107.                 // we need to ensure beta sign does not change during the turn
  108.                 final T beta     = context.getSecuredBeta();
  109.                 final T phiStart = context.getYawStart(beta);
  110.                 final T dtStart  = context.timeSinceTurnStart(context.getDate());
  111.                 final T phiDot;
  112.                 final T linearPhi;

  113.                 if (context.inSunSide()) {
  114.                     // noon turn
  115.                     phiDot    = field.getZero().add(-FastMath.copySign(YAW_RATE, beta.getReal()));
  116.                     linearPhi = phiStart.add(phiDot.multiply(dtStart));
  117.                 } else {
  118.                     // midnight turn
  119.                     phiDot    = field.getZero().add(FastMath.copySign(YAW_RATE, beta.getReal()));
  120.                     linearPhi = phiStart.add(phiDot.multiply(dtStart));
  121.                     final T phiEnd = context.getYawEnd(beta);
  122.                     if (phiEnd.getReal() / linearPhi.getReal() < 0 || phiEnd.getReal() / linearPhi.getReal() > 1) {
  123.                         return context.getNominalYaw();
  124.                     }
  125.                 }

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

  127.             }

  128.         }

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

  131.     }

  132. }