AttitudeEntry.java

  1. /* Copyright 2002-2025 CS GROUP
  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.aem;

  18. import java.util.Arrays;

  19. import org.orekit.files.ccsds.ndm.adm.AttitudeType;
  20. import org.orekit.time.AbsoluteDate;
  21. import org.orekit.utils.TimeStampedAngularCoordinates;

  22. /** Container for one attitude entry.
  23.  * @author Luc Maisonobe
  24.  * @since 11.0
  25.  */
  26. class AttitudeEntry {

  27.     /** Metadata used to interpret the data fields. */
  28.     private final AemMetadata metadata;

  29.     /** Epoch. */
  30.     private AbsoluteDate epoch;

  31.     /** Attitude components. */
  32.     private double[] components;

  33.     /** Build an uninitialized entry.
  34.      * @param metadata metadata used to interpret the data fields
  35.      */
  36.     AttitudeEntry(final AemMetadata metadata) {
  37.         this.metadata   = metadata;
  38.         this.components = new double[8];
  39.         Arrays.fill(components, Double.NaN);
  40.     }

  41.     /** Get the metadata.
  42.      * @return metadata
  43.      */
  44.     public AemMetadata getMetadata() {
  45.         return metadata;
  46.     }

  47.     /** Set epoch.
  48.      * @param epoch epoch to set
  49.      */
  50.     public void setEpoch(final AbsoluteDate epoch) {
  51.         this.epoch = epoch;
  52.     }

  53.     /** Set one component.
  54.      * @param i index of the component
  55.      * @param value value of the component
  56.      */
  57.     public void setComponent(final int i, final double value) {
  58.         components[i] = value;
  59.     }

  60.     /** Set one angle.
  61.      * @param axis axis label
  62.      * @param angle value of the angle (rad)
  63.      */
  64.     public void setLabeledAngle(final char axis, final double angle) {
  65.         if (metadata.getEulerRotSeq() != null) {
  66.             for (int i = 0; i < components.length; ++i) {
  67.                 if (metadata.getEulerRotSeq().name().charAt(i) == axis && Double.isNaN(components[i])) {
  68.                     setComponent(i, angle);
  69.                     return;
  70.                 }
  71.             }
  72.         }
  73.     }

  74.     /** Set one rate.
  75.      * @param axis axis label
  76.      * @param rate value of the rate (rad/s)
  77.      */
  78.     public void setLabeledRate(final char axis, final double rate) {
  79.         if (metadata.getEulerRotSeq() != null) {
  80.             final int first = (metadata.getAttitudeType() == AttitudeType.QUATERNION_ANGVEL ||
  81.                                metadata.getAttitudeType() == AttitudeType.QUATERNION_EULER_RATES) ?
  82.                               4 : 3;
  83.             for (int i = 0; i < 3; ++i) {
  84.                 if (metadata.getEulerRotSeq().name().charAt(i) == axis && Double.isNaN(components[first + i])) {
  85.                     setComponent(first + i, rate);
  86.                     return;
  87.                 }
  88.             }
  89.         }
  90.     }

  91.     /** Get the angular coordinates entry.
  92.      * @return angular coordinates entry
  93.      */
  94.     public TimeStampedAngularCoordinates getCoordinates() {
  95.         return metadata.getAttitudeType().build(metadata.isFirst(),
  96.                                                 metadata.getEndpoints().isExternal2SpacecraftBody(),
  97.                                                 metadata.getEulerRotSeq(), metadata.isSpacecraftBodyRate(),
  98.                                                 epoch, components);
  99.     }

  100. }