AbstractGNSSAttitudeProvider.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.RealFieldElement;
  19. import org.orekit.attitudes.Attitude;
  20. import org.orekit.attitudes.FieldAttitude;
  21. import org.orekit.errors.OrekitException;
  22. import org.orekit.frames.Frame;
  23. import org.orekit.time.AbsoluteDate;
  24. import org.orekit.time.FieldAbsoluteDate;
  25. import org.orekit.utils.ExtendedPVCoordinatesProvider;
  26. import org.orekit.utils.FieldPVCoordinatesProvider;
  27. import org.orekit.utils.PVCoordinatesProvider;
  28. import org.orekit.utils.TimeStampedAngularCoordinates;
  29. import org.orekit.utils.TimeStampedFieldAngularCoordinates;
  30. import org.orekit.utils.TimeStampedFieldPVCoordinates;
  31. import org.orekit.utils.TimeStampedPVCoordinates;

  32. /**
  33.  * Base class for attitude providers for navigation satellites.
  34.  *
  35.  * @author Luc Maisonobe
  36.  * @since 9.2
  37.  */
  38. public abstract class AbstractGNSSAttitudeProvider implements GNSSAttitudeProvider {

  39.     /** Serializable UID. */
  40.     private static final long serialVersionUID = 20171114L;

  41.     /** Start of validity for this provider. */
  42.     private final AbsoluteDate validityStart;

  43.     /** End of validity for this provider. */
  44.     private final AbsoluteDate validityEnd;

  45.     /** Provider for Sun position. */
  46.     private final ExtendedPVCoordinatesProvider sun;

  47.     /** Inertial frame where velocity are computed. */
  48.     private final Frame inertialFrame;

  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.     protected AbstractGNSSAttitudeProvider(final AbsoluteDate validityStart,
  56.                                            final AbsoluteDate validityEnd,
  57.                                            final ExtendedPVCoordinatesProvider sun,
  58.                                            final Frame inertialFrame) {
  59.         this.validityStart = validityStart;
  60.         this.validityEnd   = validityEnd;
  61.         this.sun           = sun;
  62.         this.inertialFrame = inertialFrame;
  63.     }

  64.     /** {@inheritDoc} */
  65.     @Override
  66.     public AbsoluteDate validityStart() {
  67.         return validityStart;
  68.     }

  69.     /** {@inheritDoc} */
  70.     @Override
  71.     public AbsoluteDate validityEnd() {
  72.         return validityEnd;
  73.     }

  74.     /** {@inheritDoc} */
  75.     @Override
  76.     public Attitude getAttitude(final PVCoordinatesProvider pvProv,
  77.                                 final AbsoluteDate date,
  78.                                 final Frame frame)
  79.         throws OrekitException {

  80.         // Sun/spacecraft geometry
  81.         // computed in inertial frame so orbital plane (which depends on spacecraft velocity) is correct
  82.         final TimeStampedPVCoordinates sunPV = sun.getPVCoordinates(date, inertialFrame);
  83.         final TimeStampedPVCoordinates svPV  = pvProv.getPVCoordinates(date, inertialFrame);

  84.         // compute yaw correction
  85.         final TimeStampedAngularCoordinates corrected = correctedYaw(new GNSSAttitudeContext(sunPV, svPV));

  86.         return new Attitude(inertialFrame, corrected).withReferenceFrame(frame);

  87.     }

  88.     /** {@inheritDoc} */
  89.     @Override
  90.     public <T extends RealFieldElement<T>> FieldAttitude<T> getAttitude(final FieldPVCoordinatesProvider<T> pvProv,
  91.                                                                         final FieldAbsoluteDate<T> date,
  92.                                                                         final Frame frame)
  93.         throws OrekitException {

  94.         // Sun/spacecraft geometry
  95.         // computed in inertial frame so orbital plane (which depends on spacecraft velocity) is correct
  96.         final TimeStampedFieldPVCoordinates<T> sunPV = sun.getPVCoordinates(date, inertialFrame);
  97.         final TimeStampedFieldPVCoordinates<T> svPV  = pvProv.getPVCoordinates(date, inertialFrame);

  98.         // compute yaw correction
  99.         final TimeStampedFieldAngularCoordinates<T> corrected = correctedYaw(new GNSSFieldAttitudeContext<>(sunPV, svPV));

  100.         return new FieldAttitude<>(inertialFrame, corrected).withReferenceFrame(frame);

  101.     }

  102.     /** Compute GNSS attitude with midnight/noon yaw turn correction.
  103.      * @param context context data for attitude computation
  104.      * @return corrected yaw, using inertial frame as the reference
  105.      * @exception OrekitException if yaw corrected attitude cannot be computed
  106.      */
  107.     protected abstract TimeStampedAngularCoordinates correctedYaw(GNSSAttitudeContext context)
  108.         throws OrekitException;

  109.     /** Compute GNSS attitude with midnight/noon yaw turn correction.
  110.      * @param context context data for attitude computation
  111.      * @param <T> type of the field elements
  112.      * @return corrected yaw, using inertial frame as the reference
  113.      * @exception OrekitException if yaw corrected attitude cannot be computed
  114.      */
  115.     protected abstract <T extends RealFieldElement<T>> TimeStampedFieldAngularCoordinates<T>
  116.         correctedYaw(GNSSFieldAttitudeContext<T> context)
  117.         throws OrekitException;

  118. }