AttitudeElementsType.java

  1. /* Copyright 2002-2024 Luc Maisonobe
  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.files.ccsds.ndm.adm.acm;

  18. import java.util.List;
  19. import java.util.stream.Collectors;
  20. import java.util.stream.Stream;

  21. import org.hipparchus.geometry.euclidean.threed.Rotation;
  22. import org.hipparchus.geometry.euclidean.threed.RotationConvention;
  23. import org.hipparchus.geometry.euclidean.threed.RotationOrder;
  24. import org.orekit.utils.units.Unit;

  25. /** Attitude element set type used in CCSDS {@link Acm Attitude Comprehensive Messages}.
  26.  * @author Luc Maisonobe
  27.  * @since 12.0
  28.  */
  29. public enum AttitudeElementsType {

  30.     // CHECKSTYLE: stop MultipleStringLiterals check

  31.     /** Quaternion. */
  32.     QUATERNION("Quaternion",
  33.                "n/a", "n/a", "n/a", "n/a") {
  34.         /** {@inheritDoc} */
  35.         @Override
  36.         public Rotation toRotation(final RotationOrder order, final double[] elements) {
  37.             return new Rotation(elements[3], elements[0], elements[1], elements[2], true);
  38.         }
  39.     },

  40.     /** Euler angles. */
  41.     EULER_ANGLES("Euler angles",
  42.                  "°", "°", "°") {
  43.         /** {@inheritDoc} */
  44.         @Override
  45.         public Rotation toRotation(final RotationOrder order, final double[] elements) {
  46.             return new Rotation(order, RotationConvention.FRAME_TRANSFORM,
  47.                                 elements[0], elements[1], elements[2]);
  48.         }
  49.     },

  50.     /** Direction cosine matrix. */
  51.     DCM("Direction cosine matrix",
  52.         "n/a", "n/a", "n/a", "n/a", "n/a", "n/a", "n/a", "n/a", "n/a") {
  53.         /** {@inheritDoc} */
  54.         @Override
  55.         public Rotation toRotation(final RotationOrder order, final double[] elements) {
  56.             return new Rotation(new double[][] {
  57.                 { elements[0], elements[3], elements[6] },
  58.                 { elements[1], elements[4], elements[7] },
  59.                 { elements[2], elements[5], elements[8] }
  60.             }, 1.0e-10);
  61.         }
  62.     };

  63.     // CHECKSTYLE: resume MultipleStringLiterals check

  64.     /** Description. */
  65.     private final String description;

  66.     /** Elements units. */
  67.     private final List<Unit> units;

  68.     /** Simple constructor.
  69.      * @param description description
  70.      * @param unitsSpecifications elements units specifications
  71.      */
  72.     AttitudeElementsType(final String description, final String... unitsSpecifications) {
  73.         this.description = description;
  74.         this.units       = Stream.of(unitsSpecifications).
  75.                            map(s -> Unit.parse(s)).
  76.                            collect(Collectors.toList());
  77.     }

  78.     /** Get the elements units.
  79.      * @return elements units
  80.      */
  81.     public List<Unit> getUnits() {
  82.         return units;
  83.     }

  84.     /** Convert to rotation.
  85.      * @param order rotation order for Euler angles
  86.      * @param elements elements values in SI units
  87.      * @return rotation
  88.      */
  89.     public abstract Rotation toRotation(RotationOrder order, double[] elements);

  90.     /** {@inheritDoc} */
  91.     @Override
  92.     public String toString() {
  93.         return description;
  94.     }

  95. }