LofOffset.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.attitudes;

  18. import org.hipparchus.RealFieldElement;
  19. import org.hipparchus.geometry.euclidean.threed.FieldRotation;
  20. import org.hipparchus.geometry.euclidean.threed.Rotation;
  21. import org.hipparchus.geometry.euclidean.threed.RotationConvention;
  22. import org.hipparchus.geometry.euclidean.threed.RotationOrder;
  23. import org.orekit.errors.OrekitException;
  24. import org.orekit.errors.OrekitMessages;
  25. import org.orekit.frames.FieldTransform;
  26. import org.orekit.frames.Frame;
  27. import org.orekit.frames.LOFType;
  28. import org.orekit.frames.Transform;
  29. import org.orekit.time.AbsoluteDate;
  30. import org.orekit.time.FieldAbsoluteDate;
  31. import org.orekit.utils.FieldPVCoordinates;
  32. import org.orekit.utils.FieldPVCoordinatesProvider;
  33. import org.orekit.utils.PVCoordinates;
  34. import org.orekit.utils.PVCoordinatesProvider;


  35. /**
  36.  * Attitude law defined by fixed Roll, Pitch and Yaw angles (in any order)
  37.  * with respect to a local orbital frame.

  38.  * <p>
  39.  * The attitude provider is defined as a rotation offset from some local orbital frame.
  40.  * @author V&eacute;ronique Pommier-Maurussane
  41.  */
  42. public class LofOffset implements AttitudeProvider {

  43.     /** Serializable UID. */
  44.     private static final long serialVersionUID = -713570668596014285L;

  45.     /** Type of Local Orbital Frame. */
  46.     private LOFType type;

  47.     /** Rotation from local orbital frame.  */
  48.     private final Rotation offset;

  49.     /** Inertial frame with respect to which orbit should be computed. */
  50.     private final Frame inertialFrame;

  51.     /** Create a LOF-aligned attitude.
  52.      * <p>
  53.      * Calling this constructor is equivalent to call
  54.      * {@code LofOffset(inertialFrame, LOFType, RotationOrder.XYZ, 0, 0, 0)}
  55.      * </p>
  56.      * @param inertialFrame inertial frame with respect to which orbit should be computed
  57.      * @param type type of Local Orbital Frame
  58.      * @exception OrekitException if inertialFrame is not a pseudo-inertial frame
  59.      */
  60.     public LofOffset(final Frame inertialFrame, final LOFType type) throws OrekitException {
  61.         this(inertialFrame, type, RotationOrder.XYZ, 0, 0, 0);
  62.     }

  63.     /** Creates new instance.
  64.      * <p>
  65.      * An important thing to note is that the rotation order and angles signs used here
  66.      * are compliant with an <em>attitude</em> definition, i.e. they correspond to
  67.      * a frame that rotate in a field of fixed vectors. So to retrieve the angles
  68.      * provided here from the Hipparchus underlying rotation, one has to either use the
  69.      * {@link RotationConvention#VECTOR_OPERATOR} and <em>revert</em> the rotation, or
  70.      * to use {@link RotationConvention#FRAME_TRANSFORM} as in the following code snippet:
  71.      * </p>
  72.      * <pre>
  73.      *   LofOffset law          = new LofOffset(inertial, lofType, order, alpha1, alpha2, alpha3);
  74.      *   Rotation  offsetAtt    = law.getAttitude(orbit).getRotation();
  75.      *   Rotation  alignedAtt   = new LofOffset(inertial, lofType).getAttitude(orbit).getRotation();
  76.      *   Rotation  offsetProper = offsetAtt.compose(alignedAtt.revert(), RotationConvention.VECTOR_OPERATOR);
  77.      *
  78.      *   // note the call to revert and the conventions in the following statement
  79.      *   double[] anglesV = offsetProper.revert().getAngles(order, RotationConvention.VECTOR_OPERATOR);
  80.      *   System.out.println(alpha1 + " == " + anglesV[0]);
  81.      *   System.out.println(alpha2 + " == " + anglesV[1]);
  82.      *   System.out.println(alpha3 + " == " + anglesV[2]);
  83.      *
  84.      *   // note the conventions in the following statement
  85.      *   double[] anglesF = offsetProper.getAngles(order, RotationConvention.FRAME_TRANSFORM);
  86.      *   System.out.println(alpha1 + " == " + anglesF[0]);
  87.      *   System.out.println(alpha2 + " == " + anglesF[1]);
  88.      *   System.out.println(alpha3 + " == " + anglesF[2]);
  89.      * </pre>
  90.      * @param inertialFrame inertial frame with respect to which orbit should be computed
  91.      * @param type type of Local Orbital Frame
  92.      * @param order order of rotations to use for (alpha1, alpha2, alpha3) composition
  93.      * @param alpha1 angle of the first elementary rotation
  94.      * @param alpha2 angle of the second elementary rotation
  95.      * @param alpha3 angle of the third elementary rotation
  96.      * @exception OrekitException if inertialFrame is not a pseudo-inertial frame
  97.      */
  98.     public LofOffset(final Frame inertialFrame, final LOFType type,
  99.                      final RotationOrder order, final double alpha1,
  100.                      final double alpha2, final double alpha3) throws OrekitException {
  101.         this.type = type;
  102.         this.offset = new Rotation(order, RotationConvention.VECTOR_OPERATOR, alpha1, alpha2, alpha3).revert();
  103.         if (!inertialFrame.isPseudoInertial()) {
  104.             throw new OrekitException(OrekitMessages.NON_PSEUDO_INERTIAL_FRAME,
  105.                                       inertialFrame.getName());
  106.         }
  107.         this.inertialFrame = inertialFrame;
  108.     }


  109.     /** {@inheritDoc} */
  110.     public Attitude getAttitude(final PVCoordinatesProvider pvProv,
  111.                                 final AbsoluteDate date, final Frame frame)
  112.         throws OrekitException {

  113.         // construction of the local orbital frame, using PV from inertial frame
  114.         final PVCoordinates pv = pvProv.getPVCoordinates(date, inertialFrame);
  115.         final Transform inertialToLof = type.transformFromInertial(date, pv);

  116.         // take into account the specified start frame (which may not be an inertial one)
  117.         final Transform frameToInertial = frame.getTransformTo(inertialFrame, date);
  118.         final Transform frameToLof = new Transform(date, frameToInertial, inertialToLof);

  119.         // compose with offset rotation
  120.         return new Attitude(date, frame,
  121.                             offset.compose(frameToLof.getRotation(), RotationConvention.VECTOR_OPERATOR),
  122.                             offset.applyTo(frameToLof.getRotationRate()),
  123.                             offset.applyTo(frameToLof.getRotationAcceleration()));

  124.     }

  125.     /** {@inheritDoc} */
  126.     public <T extends RealFieldElement<T>> FieldAttitude<T> getAttitude(final FieldPVCoordinatesProvider<T> pvProv,
  127.                                                                         final FieldAbsoluteDate<T> date,
  128.                                                                         final Frame frame)
  129.         throws OrekitException {

  130.         // construction of the local orbital frame, using PV from inertial frame
  131.         final FieldPVCoordinates<T> pv = pvProv.getPVCoordinates(date, inertialFrame);
  132.         final FieldTransform<T> inertialToLof = type.transformFromInertial(date, pv);

  133.         // take into account the specified start frame (which may not be an inertial one)
  134.         final FieldTransform<T> frameToInertial = frame.getTransformTo(inertialFrame, date);
  135.         final FieldTransform<T> frameToLof = new FieldTransform<>(date, frameToInertial, inertialToLof);

  136.         // compose with offset rotation
  137.         return new FieldAttitude<>(date, frame,
  138.                                    frameToLof.getRotation().compose(offset, RotationConvention.FRAME_TRANSFORM),
  139.                                    FieldRotation.applyTo(offset, frameToLof.getRotationRate()),
  140.                                    FieldRotation.applyTo(offset, frameToLof.getRotationAcceleration()));

  141.     }
  142. }