1   /* Copyright 2022-2026 Luc Maisonobe
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  
18  package org.orekit.files.ccsds.ndm.adm.acm;
19  
20  import java.util.Optional;
21  
22  import org.orekit.annotation.Nullable;
23  import org.orekit.errors.OrekitException;
24  import org.orekit.errors.OrekitMessages;
25  import org.orekit.files.ccsds.section.CommentsContainer;
26  
27  /** Attitude determination sensor data.
28   * <p>
29   * Beware that the Orekit getters and setters all rely on SI units. The parsers
30   * and writers take care of converting these SI units into CCSDS mandatory units.
31   * The {@link org.orekit.utils.units.Unit Unit} class provides useful
32   * {@link org.orekit.utils.units.Unit#fromSI(double) fromSi} and
33   * {@link org.orekit.utils.units.Unit#toSI(double) toSI} methods in case the callers
34   * already use CCSDS units instead of the API SI units. The general-purpose
35   * {@link org.orekit.utils.units.Unit Unit} class (without an 's') and the
36   * CCSDS-specific {@link org.orekit.files.ccsds.definitions.Units Units} class
37   * (with an 's') also provide some predefined units. These predefined units and the
38   * {@link org.orekit.utils.units.Unit#fromSI(double) fromSi} and
39   * {@link org.orekit.utils.units.Unit#toSI(double) toSI} conversion methods are indeed
40   * what the parsers and writers use for the conversions.
41   * </p>
42   * @author Luc Maisonobe
43   * @since 12.0
44   */
45  public class AttitudeDeterminationSensor extends CommentsContainer {
46  
47      /** Sensor number. */
48      private int sensorNumber;
49  
50      /** Sensor used. */
51      private String sensorUsed;
52  
53      /** Number of noise elements for sensor. */
54      @Nullable
55      private Integer nbSensorNoiseCovariance;
56  
57      /** Standard deviation of sensor noises for sensor. */
58      @Nullable
59      private double[] sensorNoiseCovariance;
60  
61      /** Frequency of sensor data. */
62      @Nullable
63      private Double sensorFrequency;
64  
65      /** Simple constructor.
66       */
67      public AttitudeDeterminationSensor() {
68      }
69  
70      /** {@inheritDoc} */
71      @Override
72      public void validate(final double version) {
73          super.validate(version);
74          checkNotNegative(sensorNumber, AttitudeDeterminationSensorKey.SENSOR_NUMBER.name());
75          checkNotNull(sensorUsed, AttitudeDeterminationSensorKey.SENSOR_USED.name());
76          if (nbSensorNoiseCovariance != null) {
77              final int n = sensorNoiseCovariance == null ? 0 : sensorNoiseCovariance.length;
78              if (nbSensorNoiseCovariance != n) {
79                  throw new OrekitException(OrekitMessages.INCONSISTENT_NUMBER_OF_ELEMENTS,
80                                            nbSensorNoiseCovariance, n);
81              }
82          }
83      }
84  
85      /** Get number of the sensor.
86       * @return number of the sensor
87       */
88      public int getSensorNumber() {
89          return sensorNumber;
90      }
91  
92      /** Set number of the sensor.
93       * @param sensorNumber number of the sensor
94       */
95      public void setSensorNumber(final int sensorNumber) {
96          this.sensorNumber = sensorNumber;
97      }
98  
99      /** Get sensor used.
100      * @return sensor used
101      */
102     public String getSensorUsed() {
103         return sensorUsed;
104     }
105 
106     /** Set sensor used.
107      * @param sensorUsed sensor used
108      */
109     public void setSensorUsed(final String sensorUsed) {
110         this.sensorUsed = sensorUsed;
111     }
112 
113     /** Get number of noise elements for sensor.
114      * @return number of noise elements for sensor
115      */
116     public Optional<Integer> getNbSensorNoiseCovariance() {
117         return Optional.ofNullable(nbSensorNoiseCovariance);
118     }
119 
120     /** Set number of noise elements for sensor.
121      * @param n number of noise elements for sensor
122      */
123     public void setNbSensorNoiseCovariance(final int n) {
124         nbSensorNoiseCovariance = n;
125     }
126 
127     /** Get standard deviation of sensor noise for sensor.
128      * @return standard deviation of sensor noise for sensor
129      */
130     public Optional<double[]> getSensorNoiseCovariance() {
131         return sensorNoiseCovariance == null ? Optional.empty() : Optional.of(sensorNoiseCovariance.clone());
132     }
133 
134     /** Set standard deviation of sensor noise for sensor.
135      * @param stddev standard deviation of sensor noise
136      */
137     public void setSensorNoiseCovariance(final double[] stddev) {
138         if (stddev.length != nbSensorNoiseCovariance) {
139             throw new OrekitException(OrekitMessages.INCONSISTENT_NUMBER_OF_ELEMENTS,
140                                       nbSensorNoiseCovariance, stddev.length);
141         }
142         sensorNoiseCovariance = stddev.clone();
143     }
144 
145     /** Get frequency of sensor data for sensor.
146      * @return frequency of sensor data for sensor
147      */
148     public Optional<Double> getSensorFrequency() {
149         return Optional.ofNullable(sensorFrequency);
150     }
151 
152     /** Set frequency of sensor data for sensor.
153      * @param frequency frequency of sensor data for sensor
154      */
155     public void setSensorFrequency(final double frequency) {
156         sensorFrequency = frequency;
157     }
158 
159 }