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

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

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

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

  50.     /** Initial yaw end at iterative search start. */
  51.     private static final double YAW_END_ZERO = FastMath.toRadians(75.0);

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

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

  66.         // noon beta angle limit from yaw rate
  67.         final double realBeta = context.getBeta();
  68.         final double muRate   = context.getMuRate();
  69.         final double aNight   = NIGHT_TURN_LIMIT;
  70.         double       aNoon    = FastMath.atan(muRate / YAW_RATE);
  71.         if (FastMath.abs(realBeta) < aNoon) {
  72.             double       yawEnd = YAW_END_ZERO;
  73.             for (int i = 0; i < 3; ++i) {
  74.                 final double delta = muRate * yawEnd / YAW_RATE;
  75.                 yawEnd = 0.5 * FastMath.abs(context.computePhi(realBeta,  delta) -
  76.                                             context.computePhi(realBeta, -delta));
  77.             }
  78.             aNoon = muRate * yawEnd / YAW_RATE;
  79.         }

  80.         final double cNoon  = FastMath.cos(aNoon);
  81.         final double cNight = FastMath.cos(aNight);

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

  83.             context.setHalfSpan(context.inSunSide() ?
  84.                                 aNoon :
  85.                                 context.inOrbitPlaneAbsoluteAngle(aNight - FastMath.PI));
  86.             if (context.inTurnTimeRange(context.getDate(), 0)) {

  87.                 // we need to ensure beta sign does not change during the turn
  88.                 final double beta     = context.getSecuredBeta();
  89.                 final double phiStart = context.getYawStart(beta);
  90.                 final double dtStart  = context.timeSinceTurnStart(context.getDate());

  91.                 final double phiDot;
  92.                 final double linearPhi;
  93.                 final double phiEnd    = context.getYawEnd(beta);
  94.                 if (context.inSunSide()) {
  95.                     // noon turn
  96.                     phiDot    = -FastMath.copySign(YAW_RATE, beta);
  97.                     linearPhi = phiStart + phiDot * dtStart;
  98.                 } else {
  99.                     // midnight turn
  100.                     phiDot    = FastMath.copySign(YAW_RATE, beta);
  101.                     linearPhi = phiStart + phiDot * dtStart;
  102.                 }
  103.                 if (phiEnd / linearPhi < 0 || phiEnd / linearPhi > 1) {
  104.                     return context.turnCorrectedAttitude(phiEnd, 0.0);
  105.                 } else {
  106.                     return context.turnCorrectedAttitude(linearPhi, phiDot);
  107.                 }

  108.             }

  109.         }

  110.         // in nominal yaw mode
  111.         return context.getNominalYaw();

  112.     }

  113.     /** {@inheritDoc} */
  114.     @Override
  115.     protected <T extends RealFieldElement<T>> TimeStampedFieldAngularCoordinates<T> correctedYaw(final GNSSFieldAttitudeContext<T> context)
  116.         throws OrekitException {

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

  118.         // noon beta angle limit from yaw rate
  119.         final T realBeta = context.getBeta();
  120.         final T muRate   = context.getMuRate();
  121.         final T aNight   = field.getZero().add(NIGHT_TURN_LIMIT);
  122.         T       aNoon    = FastMath.atan(muRate.divide(YAW_RATE));
  123.         if (FastMath.abs(realBeta).getReal() < aNoon.getReal()) {
  124.             T       yawEnd = field.getZero().add(YAW_END_ZERO);
  125.             for (int i = 0; i < 3; ++i) {
  126.                 final T delta = muRate.multiply(yawEnd).divide(YAW_RATE);
  127.                 yawEnd = FastMath.abs(context.computePhi(realBeta, delta).
  128.                                       subtract(context.computePhi(realBeta, delta.negate()))).
  129.                          multiply(0.5);
  130.             }
  131.             aNoon = muRate.multiply(yawEnd).divide(YAW_RATE);
  132.         }

  133.         final double cNoon  = FastMath.cos(aNoon.getReal());
  134.         final double cNight = FastMath.cos(aNight.getReal());

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

  136.             context.setHalfSpan(context.inSunSide() ?
  137.                                 aNoon :
  138.                                 context.inOrbitPlaneAbsoluteAngle(aNight.subtract(FastMath.PI)));
  139.             if (context.inTurnTimeRange(context.getDate(), 0)) {

  140.                 // we need to ensure beta sign does not change during the turn
  141.                 final T beta     = context.getSecuredBeta();
  142.                 final T phiStart = context.getYawStart(beta);
  143.                 final T dtStart  = context.timeSinceTurnStart(context.getDate());

  144.                 final T phiDot;
  145.                 final T linearPhi;
  146.                 final T phiEnd    = context.getYawEnd(beta);
  147.                 if (context.inSunSide()) {
  148.                     // noon turn
  149.                     phiDot    = field.getZero().add(-FastMath.copySign(YAW_RATE, beta.getReal()));
  150.                     linearPhi = phiStart.add(phiDot.multiply(dtStart));
  151.                 } else {
  152.                     // midnight turn
  153.                     phiDot    = field.getZero().add(FastMath.copySign(YAW_RATE, beta.getReal()));
  154.                     linearPhi = phiStart.add(phiDot.multiply(dtStart));
  155.                 }
  156.                 if (phiEnd.getReal() / linearPhi.getReal() < 0 || phiEnd.getReal() / linearPhi.getReal() > 1) {
  157.                     return context.turnCorrectedAttitude(phiEnd, field.getZero());
  158.                 } else {
  159.                     return context.turnCorrectedAttitude(linearPhi, phiDot);
  160.                 }

  161.             }

  162.         }

  163.         // in nominal yaw mode
  164.         return context.getNominalYaw();

  165.     }

  166. }