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
19 import java.util.Arrays;
20
21 import org.orekit.files.ccsds.ndm.adm.AttitudeType;
22 import org.orekit.time.AbsoluteDate;
23 import org.orekit.utils.TimeStampedAngularCoordinates;
24
25 /** Container for one attitude entry.
26 * @author Luc Maisonobe
27 * @since 11.0
28 */
29 class AttitudeEntry {
30
31 /** Metadata used to interpret the data fields. */
32 private final AemMetadata metadata;
33
34 /** Epoch. */
35 private AbsoluteDate epoch;
36
37 /** Attitude components. */
38 private double[] components;
39
40 /** Build an uninitialized entry.
41 * @param metadata metadata used to interpret the data fields
42 */
43 AttitudeEntry(final AemMetadata metadata) {
44 this.metadata = metadata;
45 this.components = new double[8];
46 Arrays.fill(components, Double.NaN);
47 }
48
49 /** Get the metadata.
50 * @return metadata
51 */
52 public AemMetadata getMetadata() {
53 return metadata;
54 }
55
56 /** Set epoch.
57 * @param epoch epoch to set
58 */
59 public void setEpoch(final AbsoluteDate epoch) {
60 this.epoch = epoch;
61 }
62
63 /** Set one component.
64 * @param i index of the component
65 * @param value value of the component
66 */
67 public void setComponent(final int i, final double value) {
68 components[i] = value;
69 }
70
71 /** Set one angle.
72 * @param axis axis label
73 * @param angle value of the angle (rad)
74 */
75 public void setLabeledAngle(final char axis, final double angle) {
76 if (metadata.getEulerRotSeq() != null) {
77 for (int i = 0; i < components.length; ++i) {
78 if (metadata.getEulerRotSeq().name().charAt(i) == axis && Double.isNaN(components[i])) {
79 setComponent(i, angle);
80 return;
81 }
82 }
83 }
84 }
85
86 /** Set one rate.
87 * @param axis axis label
88 * @param rate value of the rate (rad/s)
89 */
90 public void setLabeledRate(final char axis, final double rate) {
91 if (metadata.getEulerRotSeq() != null) {
92 final int first = (metadata.getAttitudeType() == AttitudeType.QUATERNION_ANGVEL ||
93 metadata.getAttitudeType() == AttitudeType.QUATERNION_EULER_RATES) ?
94 4 : 3;
95 for (int i = 0; i < 3; ++i) {
96 if (metadata.getEulerRotSeq().name().charAt(i) == axis && Double.isNaN(components[first + i])) {
97 setComponent(first + i, rate);
98 return;
99 }
100 }
101 }
102 }
103
104 /** Get the angular coordinates entry.
105 * @return angular coordinates entry
106 */
107 public TimeStampedAngularCoordinates getCoordinates() {
108 return metadata.getAttitudeType().build(metadata.isFirst(),
109 metadata.getEndpoints().isExternal2SpacecraftBody(),
110 metadata.getEulerRotSeq(), metadata.isSpacecraftBodyRate(),
111 epoch, components);
112 }
113
114 }