Glonass.java

  1. /* Copyright 2002-2025 CS GROUP
  2.  * Licensed to CS GROUP (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.CalculusFieldElement;
  20. import org.hipparchus.analysis.CalculusFieldUnivariateFunction;
  21. import org.hipparchus.analysis.UnivariateFunction;
  22. import org.hipparchus.analysis.solvers.AllowedSolution;
  23. import org.hipparchus.analysis.solvers.BracketingNthOrderBrentSolver;
  24. import org.hipparchus.analysis.solvers.FieldBracketingNthOrderBrentSolver;
  25. import org.hipparchus.analysis.solvers.UnivariateSolverUtils;
  26. import org.hipparchus.util.FastMath;
  27. import org.orekit.frames.Frame;
  28. import org.orekit.time.AbsoluteDate;
  29. import org.orekit.utils.ExtendedPositionProvider;
  30. import org.orekit.utils.TimeStampedAngularCoordinates;
  31. import org.orekit.utils.TimeStampedFieldAngularCoordinates;

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

  46.     /** Default yaw rates for all spacecrafts in radians per seconds. */
  47.     public static final double DEFAULT_YAW_RATE = FastMath.toRadians(0.250);

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

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

  52.     /** No margin on turn end for Glonass. */
  53.     private static final double END_MARGIN = 0.0;

  54.     /** Yaw rate. */
  55.     private final double yawRate;

  56.     /** Simple constructor.
  57.      * @param yawRate yaw rate to use in radians per seconds (typically {@link #DEFAULT_YAW_RATE})
  58.      * @param validityStart start of validity for this provider
  59.      * @param validityEnd end of validity for this provider
  60.      * @param sun provider for Sun position
  61.      * @param inertialFrame inertial frame where velocity are computed
  62.      */
  63.     public Glonass(final double yawRate,
  64.                    final AbsoluteDate validityStart, final AbsoluteDate validityEnd,
  65.                    final ExtendedPositionProvider sun, final Frame inertialFrame) {
  66.         super(validityStart, validityEnd, sun, inertialFrame);
  67.         this.yawRate = yawRate;
  68.     }

  69.     /** {@inheritDoc} */
  70.     @Override
  71.     protected TimeStampedAngularCoordinates correctedYaw(final GNSSAttitudeContext context) {

  72.         // noon beta angle limit from yaw rate
  73.         final double realBeta = context.beta(context.getDate());
  74.         final double muRate   = context.getMuRate();
  75.         final double aNight   = NIGHT_TURN_LIMIT;
  76.         double       aNoon    = FastMath.atan(muRate / yawRate);
  77.         if (FastMath.abs(realBeta) < aNoon) {
  78.             final UnivariateFunction f = yawEnd -> {
  79.                 final double delta =  muRate * yawEnd / yawRate;
  80.                 return yawEnd - 0.5 * FastMath.abs(context.computePhi(realBeta,  delta) -
  81.                                                    context.computePhi(realBeta, -delta));
  82.             };
  83.             final double[] bracket = UnivariateSolverUtils.bracket(f, YAW_END_ZERO, 0.0, FastMath.PI);
  84.             final double yawEnd = new BracketingNthOrderBrentSolver(1.0e-14, 1.0e-8, 1.0e-15, 5).
  85.                                   solve(50, f, bracket[0], bracket[1], AllowedSolution.ANY_SIDE);
  86.             aNoon = muRate * yawEnd / yawRate;
  87.         }

  88.         final double cNoon  = FastMath.cos(aNoon);
  89.         final double cNight = FastMath.cos(aNight);

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

  91.             context.setHalfSpan(context.inSunSide() ?
  92.                                 aNoon :
  93.                                 context.inOrbitPlaneAbsoluteAngle(aNight - FastMath.PI),
  94.                                 END_MARGIN);
  95.             if (context.inTurnTimeRange()) {

  96.                 // we need to ensure beta sign does not change during the turn
  97.                 final double beta     = context.getSecuredBeta();
  98.                 final double phiStart = context.getYawStart(beta);
  99.                 final double dtStart  = context.timeSinceTurnStart();

  100.                 final double phiDot;
  101.                 final double linearPhi;
  102.                 final double phiEnd    = context.getYawEnd(beta);
  103.                 if (context.inSunSide()) {
  104.                     // noon turn
  105.                     phiDot    = -FastMath.copySign(yawRate, beta);
  106.                     linearPhi = phiStart + phiDot * dtStart;
  107.                 } else {
  108.                     // midnight turn
  109.                     phiDot    = FastMath.copySign(yawRate, beta);
  110.                     linearPhi = phiStart + phiDot * dtStart;

  111.                     if (phiEnd / linearPhi < 0 || phiEnd / linearPhi > 1) {
  112.                         // this turn limitation is only computed for midnight turns in Kouba model
  113.                         // we don't understand yet why it doesn't apply to noon turns
  114.                         return context.turnCorrectedAttitude(phiEnd, 0.0);
  115.                     }

  116.                 }

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

  118.             }

  119.         }

  120.         // in nominal yaw mode
  121.         return context.nominalYaw(context.getDate());

  122.     }

  123.     /** {@inheritDoc} */
  124.     @Override
  125.     protected <T extends CalculusFieldElement<T>> TimeStampedFieldAngularCoordinates<T> correctedYaw(final GNSSFieldAttitudeContext<T> context) {

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

  127.         // noon beta angle limit from yaw rate
  128.         final T realBeta = context.beta(context.getDate());
  129.         final T muRate   = context.getMuRate();
  130.         final T aNight   = field.getZero().newInstance(NIGHT_TURN_LIMIT);
  131.         T       aNoon    = FastMath.atan(muRate.divide(yawRate));
  132.         if (FastMath.abs(realBeta).getReal() < aNoon.getReal()) {
  133.             final CalculusFieldUnivariateFunction<T> f = yawEnd -> {
  134.                 final T delta = muRate.multiply(yawEnd).divide(yawRate);
  135.                 return yawEnd.subtract(FastMath.abs(context.computePhi(realBeta, delta).
  136.                                                     subtract(context.computePhi(realBeta, delta.negate()))).
  137.                                        multiply(0.5));
  138.             };
  139.             final T[] bracket = UnivariateSolverUtils.bracket(f, field.getZero().newInstance(YAW_END_ZERO),
  140.                                                               field.getZero(), field.getZero().getPi());
  141.             final T yawEnd = new FieldBracketingNthOrderBrentSolver<>(field.getZero().newInstance(1.0e-14),
  142.                                                                       field.getZero().newInstance(1.0e-8),
  143.                                                                       field.getZero().newInstance(1.0e-15),
  144.                                                                       5).
  145.                             solve(50, f, bracket[0], bracket[1], AllowedSolution.ANY_SIDE);
  146.             aNoon = muRate.multiply(yawEnd).divide(yawRate);
  147.         }

  148.         final double cNoon  = FastMath.cos(aNoon.getReal());
  149.         final double cNight = FastMath.cos(aNight.getReal());

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

  151.             context.setHalfSpan(context.inSunSide() ?
  152.                                 aNoon :
  153.                                 context.inOrbitPlaneAbsoluteAngle(aNight.subtract(aNight.getPi())),
  154.                                 END_MARGIN);
  155.             if (context.inTurnTimeRange()) {

  156.                 // we need to ensure beta sign does not change during the turn
  157.                 final T beta     = context.getSecuredBeta();
  158.                 final T phiStart = context.getYawStart(beta);
  159.                 final T dtStart  = context.timeSinceTurnStart();

  160.                 final T phiDot;
  161.                 final T linearPhi;
  162.                 final T phiEnd    = context.getYawEnd(beta);
  163.                 if (context.inSunSide()) {
  164.                     // noon turn
  165.                     phiDot    = field.getZero().newInstance(-FastMath.copySign(yawRate, beta.getReal()));
  166.                     linearPhi = phiStart.add(phiDot.multiply(dtStart));
  167.                 } else {
  168.                     // midnight turn
  169.                     phiDot    = field.getZero().newInstance(FastMath.copySign(yawRate, beta.getReal()));
  170.                     linearPhi = phiStart.add(phiDot.multiply(dtStart));

  171.                     // this turn limitation is only computed for midnight turns in Kouba model
  172.                     // we don't understand yet why it doesn't apply to noon turns
  173.                     if (phiEnd.getReal() / linearPhi.getReal() < 0 || phiEnd.getReal() / linearPhi.getReal() > 1) {
  174.                         return context.turnCorrectedAttitude(phiEnd, field.getZero());
  175.                     }

  176.                 }

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


  178.             }

  179.         }

  180.         // in nominal yaw mode
  181.         return context.nominalYaw(context.getDate());

  182.     }

  183. }