SpinStabilized.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.apm;

  18. import org.orekit.errors.OrekitException;
  19. import org.orekit.errors.OrekitMessages;
  20. import org.orekit.files.ccsds.ndm.adm.AttitudeEndpoints;
  21. import org.orekit.files.ccsds.section.CommentsContainer;

  22. /**
  23.  * Container for Attitude Parameter Message data lines.
  24.  * <p>
  25.  * Beware that the Orekit getters and setters all rely on SI units. The parsers
  26.  * and writers take care of converting these SI units into CCSDS mandatory units.
  27.  * The {@link org.orekit.utils.units.Unit Unit} class provides useful
  28.  * {@link org.orekit.utils.units.Unit#fromSI(double) fromSi} and
  29.  * {@link org.orekit.utils.units.Unit#toSI(double) toSI} methods in case the callers
  30.  * already use CCSDS units instead of the API SI units. The general-purpose
  31.  * {@link org.orekit.utils.units.Unit Unit} class (without an 's') and the
  32.  * CCSDS-specific {@link org.orekit.files.ccsds.definitions.Units Units} class
  33.  * (with an 's') also provide some predefined units. These predefined units and the
  34.  * {@link org.orekit.utils.units.Unit#fromSI(double) fromSi} and
  35.  * {@link org.orekit.utils.units.Unit#toSI(double) toSI} conversion methods are indeed
  36.  * what the parsers and writers use for the conversions.
  37.  * </p>
  38.  * @author Bryan Cazabonne
  39.  * @since 10.2
  40.  */
  41. public class SpinStabilized extends CommentsContainer {

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

  44.     /** Right ascension of spin axis vector (rad). */
  45.     private double spinAlpha;

  46.     /** Declination of the spin axis vector (rad). */
  47.     private double spinDelta;

  48.     /** Phase of the satellite about the spin axis (rad). */
  49.     private double spinAngle;

  50.     /** Angular velocity of satellite around spin axis (rad/s). */
  51.     private double spinAngleVel;

  52.     /** Nutation angle of spin axis (rad). */
  53.     private double nutation;

  54.     /** Body nutation period of the spin axis (s). */
  55.     private double nutationPer;

  56.     /** Inertial nutation phase (rad). */
  57.     private double nutationPhase;

  58.     /** Right ascension of angular momentum vector (rad).
  59.      * @since 12.0
  60.      */
  61.     private double momentumAlpha;

  62.     /** Declination of the angular momentum vector (rad).
  63.      * @since 12.0
  64.      */
  65.     private double momentumDelta;

  66.     /** Angular velocity of spin vector around the angular momentum vector (rad/s).
  67.      * @since 12.0
  68.      */
  69.     private double nutationVel;

  70.     /** Simple constructor.
  71.      */
  72.     public SpinStabilized() {
  73.         endpoints      = new AttitudeEndpoints();
  74.         spinAlpha      = Double.NaN;
  75.         spinDelta      = Double.NaN;
  76.         spinAngle      = Double.NaN;
  77.         spinAngleVel   = Double.NaN;
  78.         nutation       = Double.NaN;
  79.         nutationPer    = Double.NaN;
  80.         nutationPhase  = Double.NaN;
  81.         momentumAlpha  = Double.NaN;
  82.         momentumDelta  = Double.NaN;
  83.         nutationVel    = Double.NaN;
  84.     }

  85.     /** {@inheritDoc} */
  86.     @Override
  87.     public void validate(final double version) {
  88.         super.validate(version);
  89.         endpoints.checkMandatoryEntriesExceptExternalFrame(version,
  90.                                                            SpinStabilizedKey.SPIN_FRAME_A,
  91.                                                            SpinStabilizedKey.SPIN_FRAME_B,
  92.                                                            SpinStabilizedKey.SPIN_DIR);
  93.         endpoints.checkExternalFrame(SpinStabilizedKey.SPIN_FRAME_A, SpinStabilizedKey.SPIN_FRAME_B);
  94.         checkNotNaN(spinAlpha,    SpinStabilizedKey.SPIN_ALPHA.name());
  95.         checkNotNaN(spinDelta,    SpinStabilizedKey.SPIN_DELTA.name());
  96.         checkNotNaN(spinAngle,    SpinStabilizedKey.SPIN_ANGLE.name());
  97.         checkNotNaN(spinAngleVel, SpinStabilizedKey.SPIN_ANGLE_VEL.name());
  98.         if (Double.isNaN(nutation + nutationPer + nutationPhase)) {
  99.             // if at least one is NaN, all must be NaN (i.e. not initialized)
  100.             if (!(Double.isNaN(nutation) && Double.isNaN(nutationPer) && Double.isNaN(nutationPhase))) {
  101.                 throw new OrekitException(OrekitMessages.UNINITIALIZED_VALUE_FOR_KEY, "NUTATION*");
  102.             }
  103.         }
  104.         if (Double.isNaN(momentumAlpha + momentumDelta + nutationVel)) {
  105.             // if at least one is NaN, all must be NaN (i.e. not initialized)
  106.             if (!(Double.isNaN(momentumAlpha) && Double.isNaN(momentumDelta) && Double.isNaN(nutationVel))) {
  107.                 throw new OrekitException(OrekitMessages.UNINITIALIZED_VALUE_FOR_KEY, "MOMENTUM*/NUTATION_VEL");
  108.             }
  109.         }
  110.     }

  111.     /** Get the endpoints (i.e. frames A, B and their relationship).
  112.      * @return endpoints
  113.      */
  114.     public AttitudeEndpoints getEndpoints() {
  115.         return endpoints;
  116.     }

  117.     /**
  118.      * Get the right ascension of spin axis vector (rad).
  119.      * @return the right ascension of spin axis vector
  120.      */
  121.     public double getSpinAlpha() {
  122.         return spinAlpha;
  123.     }

  124.     /**
  125.      * Set the right ascension of spin axis vector (rad).
  126.      * @param spinAlpha value to be set
  127.      */
  128.     public void setSpinAlpha(final double spinAlpha) {
  129.         refuseFurtherComments();
  130.         this.spinAlpha = spinAlpha;
  131.     }

  132.     /**
  133.      * Get the declination of the spin axis vector (rad).
  134.      * @return the declination of the spin axis vector (rad).
  135.      */
  136.     public double getSpinDelta() {
  137.         return spinDelta;
  138.     }

  139.     /**
  140.      * Set the declination of the spin axis vector (rad).
  141.      * @param spinDelta value to be set
  142.      */
  143.     public void setSpinDelta(final double spinDelta) {
  144.         refuseFurtherComments();
  145.         this.spinDelta = spinDelta;
  146.     }

  147.     /**
  148.      * Get the phase of the satellite about the spin axis (rad).
  149.      * @return the phase of the satellite about the spin axis
  150.      */
  151.     public double getSpinAngle() {
  152.         return spinAngle;
  153.     }

  154.     /**
  155.      * Set the phase of the satellite about the spin axis (rad).
  156.      * @param spinAngle value to be set
  157.      */
  158.     public void setSpinAngle(final double spinAngle) {
  159.         refuseFurtherComments();
  160.         this.spinAngle = spinAngle;
  161.     }

  162.     /**
  163.      * Get the angular velocity of satellite around spin axis (rad/s).
  164.      * @return the angular velocity of satellite around spin axis
  165.      */
  166.     public double getSpinAngleVel() {
  167.         return spinAngleVel;
  168.     }

  169.     /**
  170.      * Set the angular velocity of satellite around spin axis (rad/s).
  171.      * @param spinAngleVel value to be set
  172.      */
  173.     public void setSpinAngleVel(final double spinAngleVel) {
  174.         refuseFurtherComments();
  175.         this.spinAngleVel = spinAngleVel;
  176.     }

  177.     /**
  178.      * Get the nutation angle of spin axis (rad).
  179.      * @return the nutation angle of spin axis
  180.      */
  181.     public double getNutation() {
  182.         return nutation;
  183.     }

  184.     /**
  185.      * Set the nutation angle of spin axis (rad).
  186.      * @param nutation the nutation angle to be set
  187.      */
  188.     public void setNutation(final double nutation) {
  189.         refuseFurtherComments();
  190.         this.nutation = nutation;
  191.     }

  192.     /**
  193.      * Get the body nutation period of the spin axis (s).
  194.      * @return the body nutation period of the spin axis
  195.      */
  196.     public double getNutationPeriod() {
  197.         return nutationPer;
  198.     }

  199.     /**
  200.      * Set the body nutation period of the spin axis (s).
  201.      * @param period the nutation period to be set
  202.      */
  203.     public void setNutationPeriod(final double period) {
  204.         refuseFurtherComments();
  205.         this.nutationPer = period;
  206.     }

  207.     /**
  208.      * Get the inertial nutation phase (rad).
  209.      * @return the inertial nutation phase
  210.      */
  211.     public double getNutationPhase() {
  212.         return nutationPhase;
  213.     }

  214.     /**
  215.      * Set the inertial nutation phase (rad).
  216.      * @param nutationPhase the nutation phase to be set
  217.      */
  218.     public void setNutationPhase(final double nutationPhase) {
  219.         refuseFurtherComments();
  220.         this.nutationPhase = nutationPhase;
  221.     }

  222.     /**
  223.      * Get the right ascension of angular momentum vector (rad).
  224.      * @return the right ascension of angular momentum vector
  225.      * @since 12.0
  226.      */
  227.     public double getMomentumAlpha() {
  228.         return momentumAlpha;
  229.     }

  230.     /**
  231.      * Set the right ascension of angular momentum vector (rad).
  232.      * @param momentumAlpha value to be set
  233.      * @since 12.0
  234.      */
  235.     public void setMomentumAlpha(final double momentumAlpha) {
  236.         refuseFurtherComments();
  237.         this.momentumAlpha = momentumAlpha;
  238.     }

  239.     /**
  240.      * Get the declination of the angular momentum vector (rad).
  241.      * @return the declination of the angular momentum vector (rad).
  242.      * @since 12.0
  243.      */
  244.     public double getMomentumDelta() {
  245.         return momentumDelta;
  246.     }

  247.     /**
  248.      * Set the declination of the angular momentum vector (rad).
  249.      * @param momentumDelta value to be set
  250.      * @since 12.0
  251.      */
  252.     public void setMomentumDelta(final double momentumDelta) {
  253.         refuseFurtherComments();
  254.         this.momentumDelta = momentumDelta;
  255.     }

  256.     /**
  257.      * Get the angular velocity of spin vector around angular momentum vector.
  258.      * @return angular velocity of spin vector around angular momentum vector (rad/s)
  259.      * @since 12.0
  260.      */
  261.     public double getNutationVel() {
  262.         return nutationVel;
  263.     }

  264.     /**
  265.      * Set the angular velocity of spin vector around angular momentum vector.
  266.      * @param nutationVel angular velocity of spin vector around angular momentum vector (rad/s)
  267.      * @since 12.0
  268.      */
  269.     public void setNutationVel(final double nutationVel) {
  270.         refuseFurtherComments();
  271.         this.nutationVel = nutationVel;
  272.     }

  273.     /** Check if the logical block includes nutation.
  274.      * @return true if logical block includes nutation
  275.      * @since 12.0
  276.      */
  277.     public boolean hasNutation() {
  278.         return !Double.isNaN(nutation + nutationPer + nutationPhase);
  279.     }

  280.     /** Check if the logical block includes momentum.
  281.      * @return true if logical block includes momentum
  282.      * @since 12.0
  283.      */
  284.     public boolean hasMomentum() {
  285.         return !Double.isNaN(momentumAlpha + momentumDelta + nutationVel);
  286.     }

  287. }