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  
19  import org.orekit.errors.OrekitException;
20  import org.orekit.errors.OrekitMessages;
21  import org.orekit.files.ccsds.ndm.adm.AttitudeEndpoints;
22  import org.orekit.files.ccsds.section.CommentsContainer;
23  
24  /**
25   * Container for Attitude Parameter Message data lines.
26   * @author Bryan Cazabonne
27   * @since 10.2
28   */
29  public class SpinStabilized extends CommentsContainer {
30  
31      /** Endpoints (i.e. frames A, B and their relationship). */
32      private final AttitudeEndpoints endpoints;
33  
34      /** Right ascension of spin axis vector (rad). */
35      private double spinAlpha;
36  
37      /** Declination of the spin axis vector (rad). */
38      private double spinDelta;
39  
40      /** Phase of the satellite about the spin axis (rad). */
41      private double spinAngle;
42  
43      /** Angular velocity of satellite around spin axis (rad/s). */
44      private double spinAngleVel;
45  
46      /** Nutation angle of spin axis (rad). */
47      private double nutation;
48  
49      /** Body nutation period of the spin axis (s). */
50      private double nutationPer;
51  
52      /** Inertial nutation phase (rad). */
53      private double nutationPhase;
54  
55      /** Right ascension of angular momentum vector (rad).
56       * @since 12.0
57       */
58      private double momentumAlpha;
59  
60      /** Declination of the angular momentum vector (rad).
61       * @since 12.0
62       */
63      private double momentumDelta;
64  
65      /** Angular velocity of spin vector around the angular momentum vector (rad/s).
66       * @since 12.0
67       */
68      private double nutationVel;
69  
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  
86      /** {@inheritDoc} */
87      @Override
88      public void validate(final double version) {
89          super.validate(version);
90          endpoints.checkMandatoryEntriesExceptExternalFrame(version,
91                                                             SpinStabilizedKey.SPIN_FRAME_A,
92                                                             SpinStabilizedKey.SPIN_FRAME_B,
93                                                             SpinStabilizedKey.SPIN_DIR);
94          endpoints.checkExternalFrame(SpinStabilizedKey.SPIN_FRAME_A, SpinStabilizedKey.SPIN_FRAME_B);
95          checkNotNaN(spinAlpha,    SpinStabilizedKey.SPIN_ALPHA.name());
96          checkNotNaN(spinDelta,    SpinStabilizedKey.SPIN_DELTA.name());
97          checkNotNaN(spinAngle,    SpinStabilizedKey.SPIN_ANGLE.name());
98          checkNotNaN(spinAngleVel, SpinStabilizedKey.SPIN_ANGLE_VEL.name());
99          if (Double.isNaN(nutation + nutationPer + nutationPhase)) {
100             // if at least one is NaN, all must be NaN (i.e. not initialized)
101             if (!(Double.isNaN(nutation) && Double.isNaN(nutationPer) && Double.isNaN(nutationPhase))) {
102                 throw new OrekitException(OrekitMessages.UNINITIALIZED_VALUE_FOR_KEY, "NUTATION*");
103             }
104         }
105         if (Double.isNaN(momentumAlpha + momentumDelta + nutationVel)) {
106             // if at least one is NaN, all must be NaN (i.e. not initialized)
107             if (!(Double.isNaN(momentumAlpha) && Double.isNaN(momentumDelta) && Double.isNaN(nutationVel))) {
108                 throw new OrekitException(OrekitMessages.UNINITIALIZED_VALUE_FOR_KEY, "MOMENTUM*/NUTATION_VEL");
109             }
110         }
111     }
112 
113     /** Get the endpoints (i.e. frames A, B and their relationship).
114      * @return endpoints
115      */
116     public AttitudeEndpoints getEndpoints() {
117         return endpoints;
118     }
119 
120     /**
121      * Get the right ascension of spin axis vector (rad).
122      * @return the right ascension of spin axis vector
123      */
124     public double getSpinAlpha() {
125         return spinAlpha;
126     }
127 
128     /**
129      * Set the right ascension of spin axis vector (rad).
130      * @param spinAlpha value to be set
131      */
132     public void setSpinAlpha(final double spinAlpha) {
133         refuseFurtherComments();
134         this.spinAlpha = spinAlpha;
135     }
136 
137     /**
138      * Get the declination of the spin axis vector (rad).
139      * @return the declination of the spin axis vector (rad).
140      */
141     public double getSpinDelta() {
142         return spinDelta;
143     }
144 
145     /**
146      * Set the declination of the spin axis vector (rad).
147      * @param spinDelta value to be set
148      */
149     public void setSpinDelta(final double spinDelta) {
150         refuseFurtherComments();
151         this.spinDelta = spinDelta;
152     }
153 
154     /**
155      * Get the phase of the satellite about the spin axis (rad).
156      * @return the phase of the satellite about the spin axis
157      */
158     public double getSpinAngle() {
159         return spinAngle;
160     }
161 
162     /**
163      * Set the phase of the satellite about the spin axis (rad).
164      * @param spinAngle value to be set
165      */
166     public void setSpinAngle(final double spinAngle) {
167         refuseFurtherComments();
168         this.spinAngle = spinAngle;
169     }
170 
171     /**
172      * Get the angular velocity of satellite around spin axis (rad/s).
173      * @return the angular velocity of satellite around spin axis
174      */
175     public double getSpinAngleVel() {
176         return spinAngleVel;
177     }
178 
179     /**
180      * Set the angular velocity of satellite around spin axis (rad/s).
181      * @param spinAngleVel value to be set
182      */
183     public void setSpinAngleVel(final double spinAngleVel) {
184         refuseFurtherComments();
185         this.spinAngleVel = spinAngleVel;
186     }
187 
188     /**
189      * Get the nutation angle of spin axis (rad).
190      * @return the nutation angle of spin axis
191      */
192     public double getNutation() {
193         return nutation;
194     }
195 
196     /**
197      * Set the nutation angle of spin axis (rad).
198      * @param nutation the nutation angle to be set
199      */
200     public void setNutation(final double nutation) {
201         refuseFurtherComments();
202         this.nutation = nutation;
203     }
204 
205     /**
206      * Get the body nutation period of the spin axis (s).
207      * @return the body nutation period of the spin axis
208      */
209     public double getNutationPeriod() {
210         return nutationPer;
211     }
212 
213     /**
214      * Set the body nutation period of the spin axis (s).
215      * @param period the nutation period to be set
216      */
217     public void setNutationPeriod(final double period) {
218         refuseFurtherComments();
219         this.nutationPer = period;
220     }
221 
222     /**
223      * Get the inertial nutation phase (rad).
224      * @return the inertial nutation phase
225      */
226     public double getNutationPhase() {
227         return nutationPhase;
228     }
229 
230     /**
231      * Set the inertial nutation phase (rad).
232      * @param nutationPhase the nutation phase to be set
233      */
234     public void setNutationPhase(final double nutationPhase) {
235         refuseFurtherComments();
236         this.nutationPhase = nutationPhase;
237     }
238 
239     /**
240      * Get the right ascension of angular momentum vector (rad).
241      * @return the right ascension of angular momentum vector
242      * @since 12.0
243      */
244     public double getMomentumAlpha() {
245         return momentumAlpha;
246     }
247 
248     /**
249      * Set the right ascension of angular momentum vector (rad).
250      * @param momentumAlpha value to be set
251      * @since 12.0
252      */
253     public void setMomentumAlpha(final double momentumAlpha) {
254         refuseFurtherComments();
255         this.momentumAlpha = momentumAlpha;
256     }
257 
258     /**
259      * Get the declination of the angular momentum vector (rad).
260      * @return the declination of the angular momentum vector (rad).
261      * @since 12.0
262      */
263     public double getMomentumDelta() {
264         return momentumDelta;
265     }
266 
267     /**
268      * Set the declination of the angular momentum vector (rad).
269      * @param momentumDelta value to be set
270      * @since 12.0
271      */
272     public void setMomentumDelta(final double momentumDelta) {
273         refuseFurtherComments();
274         this.momentumDelta = momentumDelta;
275     }
276 
277     /**
278      * Get the angular velocity of spin vector around angular momentum vector.
279      * @return angular velocity of spin vector around angular momentum vector (rad/s)
280      * @since 12.0
281      */
282     public double getNutationVel() {
283         return nutationVel;
284     }
285 
286     /**
287      * Set the angular velocity of spin vector around angular momentum vector.
288      * @param nutationVel angular velocity of spin vector around angular momentum vector (rad/s)
289      * @since 12.0
290      */
291     public void setNutationVel(final double nutationVel) {
292         refuseFurtherComments();
293         this.nutationVel = nutationVel;
294     }
295 
296     /** Check if the logical block includes nutation.
297      * @return true if logical block includes nutation
298      * @since 12.0
299      */
300     public boolean hasNutation() {
301         return !Double.isNaN(nutation + nutationPer + nutationPhase);
302     }
303 
304     /** Check if the logical block includes momentum.
305      * @return true if logical block includes momentum
306      * @since 12.0
307      */
308     public boolean hasMomentum() {
309         return !Double.isNaN(momentumAlpha + momentumDelta + nutationVel);
310     }
311 
312 }