Galileo.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.CalculusFieldElement;
  19. import org.hipparchus.Field;
  20. import org.hipparchus.analysis.differentiation.FieldUnivariateDerivative2;
  21. import org.hipparchus.analysis.differentiation.UnivariateDerivative2;
  22. import org.hipparchus.util.FastMath;
  23. import org.hipparchus.util.FieldSinCos;
  24. import org.orekit.frames.Frame;
  25. import org.orekit.time.AbsoluteDate;
  26. import org.orekit.utils.ExtendedPositionProvider;
  27. import org.orekit.utils.TimeStampedAngularCoordinates;
  28. import org.orekit.utils.TimeStampedFieldAngularCoordinates;

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

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

  45.     /** Constants for Galileo turns. */
  46.     private static final double BETA_X = FastMath.toRadians(15.0);

  47.     /** Limit for the noon turn. */
  48.     private static final double COS_NOON = FastMath.cos(BETA_X);

  49.     /** Limit for the night turn. */
  50.     private static final double COS_NIGHT = -COS_NOON;

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

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

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

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

  71.         // noon beta angle limit from yaw rate
  72.         final double beta0 = FastMath.atan(context.getMuRate() / yawRate);

  73.         if (FastMath.abs(context.betaD2().getValue()) < beta0 &&
  74.             context.setUpTurnRegion(COS_NIGHT, COS_NOON)) {

  75.             context.setHalfSpan(context.inSunSide() ?
  76.                                 BETA_X :
  77.                                 context.inOrbitPlaneAbsoluteAngle(BETA_X),
  78.                                 END_MARGIN);
  79.             if (context.inTurnTimeRange()) {

  80.                 // handling both noon and midnight turns at once
  81.                 final UnivariateDerivative2              beta     = context.betaD2();
  82.                 final FieldSinCos<UnivariateDerivative2> scBeta   = FastMath.sinCos(beta);
  83.                 final UnivariateDerivative2              cosBeta  = scBeta.cos();
  84.                 final UnivariateDerivative2              sinBeta  = scBeta.sin();
  85.                 final double                             sinY     = FastMath.copySign(FastMath.sin(beta0), context.getSecuredBeta());
  86.                 final UnivariateDerivative2              sd       = FastMath.sin(context.getDeltaDS()).
  87.                                                                     multiply(FastMath.copySign(1.0, -context.getSVBcos() * context.getDeltaDS().getPartialDerivative(1)));
  88.                 final UnivariateDerivative2              c        = sd.multiply(cosBeta);
  89.                 final UnivariateDerivative2              shy      = sinBeta.negate().subtract(sinY).
  90.                                                                     add(sinBeta.subtract(sinY).multiply(c.abs().multiply(c.getPi().divide(FastMath.sin(BETA_X))).cos())).
  91.                                                                     multiply(0.5);
  92.                 final UnivariateDerivative2              phi      = FastMath.atan2(shy, c);

  93.                 return context.turnCorrectedAttitude(phi);

  94.             }

  95.         }

  96.         // in nominal yaw mode
  97.         return context.nominalYaw(context.getDate());

  98.     }

  99.     /** {@inheritDoc} */
  100.     @Override
  101.     protected <T extends CalculusFieldElement<T>> TimeStampedFieldAngularCoordinates<T> correctedYaw(final GNSSFieldAttitudeContext<T> context) {

  102.         // noon beta angle limit from yaw rate
  103.         final double beta0 = FastMath.atan(context.getMuRate().getReal() / yawRate);

  104.         if (FastMath.abs(context.beta(context.getDate())).getReal() < beta0 &&
  105.             context.setUpTurnRegion(COS_NIGHT, COS_NOON)) {

  106.             final Field<T> field = context.getDate().getField();
  107.             final T        betaX = field.getZero().newInstance(BETA_X);
  108.             context.setHalfSpan(context.inSunSide() ?
  109.                                 betaX :
  110.                                 context.inOrbitPlaneAbsoluteAngle(betaX),
  111.                                 END_MARGIN);
  112.             if (context.inTurnTimeRange()) {

  113.                 // handling both noon and midnight turns at once
  114.                 final FieldUnivariateDerivative2<T>              beta    = context.betaD2();
  115.                 final FieldSinCos<FieldUnivariateDerivative2<T>> scBeta  = FastMath.sinCos(beta);
  116.                 final FieldUnivariateDerivative2<T>              cosBeta = scBeta.cos();
  117.                 final FieldUnivariateDerivative2<T>              sinBeta = scBeta.sin();
  118.                 final T                                          sinY    = FastMath.sin(field.getZero().add(beta0)).copySign(context.getSecuredBeta());
  119.                 final FieldUnivariateDerivative2<T>              sd      = FastMath.sin(context.getDeltaDS()).
  120.                                                                            multiply(FastMath.copySign(1.0, -context.getSVBcos().getReal() * context.getDeltaDS().getPartialDerivative(1).getReal()));
  121.                 final FieldUnivariateDerivative2<T>              c       = sd.multiply(cosBeta);
  122.                 final FieldUnivariateDerivative2<T>              shy     = sinBeta.negate().subtract(sinY).
  123.                                                                            add(sinBeta.subtract(sinY).multiply(c.abs().multiply(c.getPi().divide(FastMath.sin(BETA_X))).cos())).
  124.                                                                            multiply(0.5);
  125.                 final FieldUnivariateDerivative2<T>              phi     = FastMath.atan2(shy, c);

  126.                 return context.turnCorrectedAttitude(phi);

  127.             }

  128.         }

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

  131.     }

  132. }