ApmQuaternion.java

  1. /* Copyright 2002-2024 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.apm;

  18. import java.util.Arrays;

  19. import org.hipparchus.complex.Quaternion;
  20. import org.orekit.errors.OrekitException;
  21. import org.orekit.errors.OrekitMessages;
  22. import org.orekit.files.ccsds.ndm.adm.AttitudeEndpoints;
  23. import org.orekit.files.ccsds.section.CommentsContainer;

  24. /**
  25.  * Container for Attitude Parameter Message quaternion logical block.
  26.  * @author Bryan Cazabonne
  27.  * @since 10.2
  28.  */
  29. public class ApmQuaternion extends CommentsContainer {

  30.     /** Endpoints (i.e. frames A, B and their relationship). */
  31.     private final AttitudeEndpoints endpoints;

  32.     /** Quaternion. */
  33.     private double[] q;

  34.     /** Quaternion derivative. */
  35.     private double[] qDot;

  36.     /** Simple constructor.
  37.      */
  38.     public ApmQuaternion() {
  39.         endpoints = new AttitudeEndpoints();
  40.         q         = new double[4];
  41.         qDot      = new double[4];
  42.         Arrays.fill(q,    Double.NaN);
  43.         Arrays.fill(qDot, Double.NaN);
  44.     }

  45.     /** {@inheritDoc} */
  46.     @Override
  47.     public void validate(final double version) {
  48.         super.validate(version);
  49.         if (version < 2.0) {
  50.             endpoints.checkMandatoryEntriesExceptExternalFrame(version,
  51.                                                                ApmQuaternionKey.Q_FRAME_A,
  52.                                                                ApmQuaternionKey.Q_FRAME_B,
  53.                                                                ApmQuaternionKey.Q_DIR);
  54.             endpoints.checkExternalFrame(ApmQuaternionKey.Q_FRAME_A, ApmQuaternionKey.Q_FRAME_B);
  55.         } else {
  56.             endpoints.checkMandatoryEntriesExceptExternalFrame(version,
  57.                                                                ApmQuaternionKey.REF_FRAME_A,
  58.                                                                ApmQuaternionKey.REF_FRAME_B,
  59.                                                                ApmQuaternionKey.Q_DIR);
  60.             endpoints.checkExternalFrame(ApmQuaternionKey.REF_FRAME_A, ApmQuaternionKey.REF_FRAME_B);
  61.         }
  62.         if (Double.isNaN(q[0] + q[1] + q[2] + q[3])) {
  63.             throw new OrekitException(OrekitMessages.UNINITIALIZED_VALUE_FOR_KEY, "Q{C|1|2|3}");
  64.         }
  65.     }

  66.     /** Get the endpoints (i.e. frames A, B and their relationship).
  67.      * @return endpoints
  68.      */
  69.     public AttitudeEndpoints getEndpoints() {
  70.         return endpoints;
  71.     }

  72.     /**
  73.      * Get the quaternion.
  74.      * @return quaternion
  75.      */
  76.     public Quaternion getQuaternion() {
  77.         return new Quaternion(q[0], q[1], q[2], q[3]);
  78.     }

  79.     /**
  80.      * Set quaternion component.
  81.      * @param index component index (0 is scalar part)
  82.      * @param value quaternion component
  83.      */
  84.     public void setQ(final int index, final double value) {
  85.         refuseFurtherComments();
  86.         this.q[index] = value;
  87.     }

  88.     /**
  89.      * Get the quaternion derivative.
  90.      * @return quaternion derivative
  91.      */
  92.     public Quaternion getQuaternionDot() {
  93.         return new Quaternion(qDot[0], qDot[1], qDot[2], qDot[3]);
  94.     }

  95.     /**
  96.      * Set quaternion derivative component.
  97.      * @param index component index (0 is scalar part)
  98.      * @param derivative quaternion derivative component
  99.      */
  100.     public void setQDot(final int index, final double derivative) {
  101.         refuseFurtherComments();
  102.         this.qDot[index] = derivative;
  103.     }

  104.     /** Check if the logical block includes rates.
  105.      * @return true if logical block includes rates
  106.      */
  107.     public boolean hasRates() {
  108.         return !Double.isNaN(qDot[0] + qDot[1] + qDot[2] + qDot[3]);
  109.     }

  110. }