Galileo.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.analysis.differentiation.DerivativeStructure;
  21. import org.hipparchus.analysis.differentiation.FieldDerivativeStructure;
  22. import org.hipparchus.util.FastMath;
  23. import org.orekit.frames.Frame;
  24. import org.orekit.time.AbsoluteDate;
  25. import org.orekit.utils.ExtendedPVCoordinatesProvider;
  26. import org.orekit.utils.TimeStampedAngularCoordinates;
  27. import org.orekit.utils.TimeStampedFieldAngularCoordinates;

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

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

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

  49.     /** Constants for Galileo turns. */
  50.     private static final double BETA_Y = FastMath.toRadians(2.0);

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

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

  55.     /** No margin on turn end for Galileo. */
  56.     private final double END_MARGIN = 0.0;

  57.     /** Simple constructor.
  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 Galileo(final AbsoluteDate validityStart, final AbsoluteDate validityEnd,
  64.                    final ExtendedPVCoordinatesProvider sun, final Frame inertialFrame) {
  65.         super(validityStart, validityEnd, sun, inertialFrame);
  66.     }

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

  70.         if (FastMath.abs(context.getBeta()) < BETA_Y &&
  71.             context.setUpTurnRegion(COS_NIGHT, COS_NOON)) {

  72.             context.setHalfSpan(context.inSunSide() ?
  73.                                 BETA_X :
  74.                                 context.inOrbitPlaneAbsoluteAngle(BETA_X));
  75.             if (context.inTurnTimeRange(context.getDate(), END_MARGIN)) {

  76.                 // handling both noon and midnight turns at once
  77.                 final DerivativeStructure beta     = context.getBetaDS();
  78.                 final DerivativeStructure cosBeta  = beta.cos();
  79.                 final DerivativeStructure sinBeta  = beta.sin();
  80.                 final double              sinY     = FastMath.copySign(FastMath.sin(BETA_Y), context.getSecuredBeta());
  81.                 final DerivativeStructure sd       = FastMath.sin(context.getDeltaDS()).
  82.                                                      multiply(FastMath.copySign(1.0, -context.getSVBcos() * context.getDeltaDS().getPartialDerivative(1)));
  83.                 final DerivativeStructure c        = sd.multiply(cosBeta);
  84.                 final DerivativeStructure shy      = sinBeta.negate().subtract(sinY).
  85.                                                      add(sinBeta.subtract(sinY).multiply(c.abs().multiply(FastMath.PI / FastMath.sin(BETA_X)).cos())).
  86.                                                      multiply(0.5);
  87.                 final DerivativeStructure phi     = FastMath.atan2(shy, c);

  88.                 return context.turnCorrectedAttitude(phi);

  89.             }

  90.         }

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

  93.     }

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

  97.         if (FastMath.abs(context.getBeta()).getReal() < BETA_Y &&
  98.             context.setUpTurnRegion(COS_NIGHT, COS_NOON)) {

  99.             final Field<T> field = context.getDate().getField();
  100.             final T        betaX = field.getZero().add(BETA_X);
  101.             context.setHalfSpan(context.inSunSide() ?
  102.                                 betaX :
  103.                                 context.inOrbitPlaneAbsoluteAngle(betaX));
  104.             if (context.inTurnTimeRange(context.getDate(), END_MARGIN)) {

  105.                 // handling both noon and midnight turns at once
  106.                 final FieldDerivativeStructure<T> beta     = context.getBetaDS();
  107.                 final FieldDerivativeStructure<T> cosBeta  = beta.cos();
  108.                 final FieldDerivativeStructure<T> sinBeta  = beta.sin();
  109.                 final T                           sinY     = FastMath.sin(field.getZero().add(BETA_Y)).copySign(context.getSecuredBeta());
  110.                 final FieldDerivativeStructure<T> sd       = FastMath.sin(context.getDeltaDS()).
  111.                                                              multiply(FastMath.copySign(1.0, -context.getSVBcos().getReal() * context.getDeltaDS().getPartialDerivative(1).getReal()));
  112.                 final FieldDerivativeStructure<T> c        = sd.multiply(cosBeta);
  113.                 final FieldDerivativeStructure<T> shy      = sinBeta.negate().subtract(sinY).
  114.                                                              add(sinBeta.subtract(sinY).multiply(c.abs().multiply(FastMath.PI / FastMath.sin(BETA_X)).cos())).
  115.                                                              multiply(0.5);
  116.                 final FieldDerivativeStructure<T> phi     = FastMath.atan2(shy, c);

  117.                 return context.turnCorrectedAttitude(phi);

  118.             }

  119.         }

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

  122.     }

  123. }