AttitudeState.java

  1. /* Copyright 2022-2025 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 org.hipparchus.geometry.euclidean.threed.RotationOrder;
  20. import org.orekit.time.AbsoluteDate;
  21. import org.orekit.time.TimeStamped;
  22. import org.orekit.utils.AngularDerivativesFilter;
  23. import org.orekit.utils.TimeStampedAngularCoordinates;
  24. import org.orekit.utils.units.Unit;

  25. /** Attitude state entry.
  26.  * @author Luc Maisonobe
  27.  * @since 12.0
  28.  */
  29. public class AttitudeState implements TimeStamped {

  30.     /** Type of the elements. */
  31.     private final AttitudeElementsType attitudeType;

  32.     /** Type of the elements rates. */
  33.     private final RateElementsType rateType;

  34.     /** Entry date. */
  35.     private final AbsoluteDate date;

  36.     /** Attitude elements. */
  37.     private final double[] elements;

  38.     /** Simple constructor.
  39.      * @param attitudeType type of the elements
  40.      * @param rateType type of the elements rates
  41.      * (internally changed to {@link RateElementsType#NONE} if null)
  42.      * @param date entry date
  43.      * @param fields trajectory elements
  44.      * @param first index of first field to consider
  45.      */
  46.     public AttitudeState(final AttitudeElementsType attitudeType, final RateElementsType rateType,
  47.                          final AbsoluteDate date, final String[] fields, final int first) {

  48.         this.attitudeType = attitudeType;
  49.         this.rateType     = rateType == null ? RateElementsType.NONE : rateType;

  50.         final List<Unit> attUnits  = this.attitudeType.getUnits();
  51.         final List<Unit> rateUnits = this.rateType.getUnits();

  52.         this.date         = date;
  53.         this.elements     = new double[attUnits.size() + rateUnits.size()];
  54.         for (int i = 0; i < attUnits.size(); ++i) {
  55.             elements[i] = attUnits.get(i).toSI(Double.parseDouble(fields[first + i]));
  56.         }
  57.         for (int i = 0; i < rateUnits.size(); ++i) {
  58.             elements[attUnits.size() + i] = rateUnits.get(i).toSI(Double.parseDouble(fields[attUnits.size() + first + i]));
  59.         }
  60.     }

  61.     /** {@inheritDoc} */
  62.     @Override
  63.     public AbsoluteDate getDate() {
  64.         return date;
  65.     }

  66.     /** Get attitude elements.
  67.      * @return attitude elements
  68.      */
  69.     public double[] getElements() {
  70.         return elements.clone();
  71.     }

  72.     /** Get the type of the elements.
  73.      * @return type of the elements
  74.      */
  75.     public AttitudeElementsType getAttitudeType() {
  76.         return attitudeType;
  77.     }

  78.     /** Get the type of the elements rates.
  79.      * @return type of the elements rates
  80.      */
  81.     public RateElementsType getRateElementsType() {
  82.         return rateType;
  83.     }

  84.     /** Get which derivatives of position are available in this state.
  85.      * @return a value indicating if the file contains rotation rate and/or acceleration
  86.       */
  87.     public AngularDerivativesFilter getAvailableDerivatives() {
  88.         return rateType == RateElementsType.NONE ?
  89.                AngularDerivativesFilter.USE_R :
  90.                AngularDerivativesFilter.USE_RR;
  91.     }

  92.     /** Convert to angular coordinates.
  93.      * @param order rotation order for Euler angles
  94.      * @return angular coordinates
  95.      */
  96.     public TimeStampedAngularCoordinates toAngular(final RotationOrder order) {
  97.         return rateType.toAngular(getDate(), order,
  98.                                   attitudeType.toRotation(order, elements),
  99.                                   attitudeType.getUnits().size(), elements);
  100.     }

  101. }