View Javadoc
1   /*
2    * Copyright (C) 2021 Alberto Irurueta Carro (alberto@irurueta.com)
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *         http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package com.irurueta.navigation.inertial.calibration;
17  
18  import com.irurueta.navigation.NotReadyException;
19  import com.irurueta.navigation.inertial.INSLooselyCoupledKalmanInitializerConfig;
20  
21  /**
22   * Utility class to create {@link INSLooselyCoupledKalmanInitializerConfig} by combining
23   * different sources of estimated data.
24   * Sources of data can be any accelerometer calibrator implementing
25   * {@link AccelerometerBiasUncertaintySource}, or any gyroscope calibrator implementing
26   * {@link GyroscopeBiasUncertaintySource}.
27   */
28  public class INSLooselyCoupledKalmanInitializerConfigCreator {
29  
30      /**
31       * A source of estimated accelerometer bias uncertainty.
32       */
33      private AccelerometerBiasUncertaintySource accelerometerBiasUncertaintySource;
34  
35      /**
36       * A source of estimated gyroscope bias uncertainty.
37       */
38      private GyroscopeBiasUncertaintySource gyroscopeBiasUncertaintySource;
39  
40      /**
41       * A source of attitude uncertainty.
42       */
43      private AttitudeUncertaintySource attitudeUncertaintySource;
44  
45      /**
46       * A source of velocity uncertainty.
47       */
48      private VelocityUncertaintySource velocityUncertaintySource;
49  
50      /**
51       * A source of position uncertainty.
52       */
53      private PositionUncertaintySource positionUncertaintySource;
54  
55      /**
56       * Constructor.
57       */
58      public INSLooselyCoupledKalmanInitializerConfigCreator() {
59      }
60  
61      /**
62       * Constructor.
63       *
64       * @param accelerometerBiasUncertaintySource a source of estimated accelerometer bias uncertainty.
65       * @param gyroscopeBiasUncertaintySource     a source of estimated gyroscope bias uncertainty.
66       * @param attitudeUncertaintySource          a source of attitude uncertainty.
67       * @param velocityUncertaintySource          a source of velocity uncertainty.
68       * @param positionUncertaintySource          a source of position uncertainty.
69       */
70      public INSLooselyCoupledKalmanInitializerConfigCreator(
71              final AccelerometerBiasUncertaintySource accelerometerBiasUncertaintySource,
72              final GyroscopeBiasUncertaintySource gyroscopeBiasUncertaintySource,
73              final AttitudeUncertaintySource attitudeUncertaintySource,
74              final VelocityUncertaintySource velocityUncertaintySource,
75              final PositionUncertaintySource positionUncertaintySource) {
76          this.accelerometerBiasUncertaintySource = accelerometerBiasUncertaintySource;
77          this.gyroscopeBiasUncertaintySource = gyroscopeBiasUncertaintySource;
78          this.attitudeUncertaintySource = attitudeUncertaintySource;
79          this.velocityUncertaintySource = velocityUncertaintySource;
80          this.positionUncertaintySource = positionUncertaintySource;
81      }
82  
83      /**
84       * Constructor.
85       *
86       * @param accelerometerBiasUncertaintySource a source of estimated accelerometer bias uncertainty.
87       * @param gyroscopeBiasUncertaintySource     a source of estimated gyroscope bias uncertainty.
88       * @param randomWalkEstimator                a random walk estimator.
89       */
90      public INSLooselyCoupledKalmanInitializerConfigCreator(
91              final AccelerometerBiasUncertaintySource accelerometerBiasUncertaintySource,
92              final GyroscopeBiasUncertaintySource gyroscopeBiasUncertaintySource,
93              final RandomWalkEstimator randomWalkEstimator) {
94          this(accelerometerBiasUncertaintySource, gyroscopeBiasUncertaintySource, randomWalkEstimator,
95                  randomWalkEstimator, randomWalkEstimator);
96      }
97  
98      /**
99       * Gets the source of estimated accelerometer bias uncertainty.
100      *
101      * @return source of estimated accelerometer bias uncertainty.
102      */
103     public AccelerometerBiasUncertaintySource getAccelerometerBiasUncertaintySource() {
104         return accelerometerBiasUncertaintySource;
105     }
106 
107     /**
108      * Sets source of estimated accelerometer bias uncertainty.
109      *
110      * @param accelerometerBiasUncertaintySource source of estimated accelerometer bias uncertainty.
111      */
112     public void setAccelerometerBiasUncertaintySource(
113             final AccelerometerBiasUncertaintySource accelerometerBiasUncertaintySource) {
114         this.accelerometerBiasUncertaintySource = accelerometerBiasUncertaintySource;
115     }
116 
117     /**
118      * Gets the source of estimated gyroscope bias uncertainty.
119      *
120      * @return source of estimated gyroscope bias uncertainty.
121      */
122     public GyroscopeBiasUncertaintySource getGyroscopeBiasUncertaintySource() {
123         return gyroscopeBiasUncertaintySource;
124     }
125 
126     /**
127      * Sets source of estimated gyroscope bias uncertainty.
128      *
129      * @param gyroscopeBiasUncertaintySource source of estimated gyroscope bias uncertainty.
130      */
131     public void setGyroscopeBiasUncertaintySource(final GyroscopeBiasUncertaintySource gyroscopeBiasUncertaintySource) {
132         this.gyroscopeBiasUncertaintySource = gyroscopeBiasUncertaintySource;
133     }
134 
135     /**
136      * Gets source of attitude uncertainty.
137      *
138      * @return source of attitude uncertainty.
139      */
140     public AttitudeUncertaintySource getAttitudeUncertaintySource() {
141         return attitudeUncertaintySource;
142     }
143 
144     /**
145      * Sets source of attitude uncertainty.
146      *
147      * @param attitudeUncertaintySource source of attitude uncertainty.
148      */
149     public void setAttitudeUncertaintySource(final AttitudeUncertaintySource attitudeUncertaintySource) {
150         this.attitudeUncertaintySource = attitudeUncertaintySource;
151     }
152 
153     /**
154      * Gets the source of velocity uncertainty.
155      *
156      * @return source of velocity uncertainty.
157      */
158     public VelocityUncertaintySource getVelocityUncertaintySource() {
159         return velocityUncertaintySource;
160     }
161 
162     /**
163      * Sets source of velocity uncertainty.
164      *
165      * @param velocityUncertaintySource source of velocity uncertainty.
166      */
167     public void setVelocityUncertaintySource(final VelocityUncertaintySource velocityUncertaintySource) {
168         this.velocityUncertaintySource = velocityUncertaintySource;
169     }
170 
171     /**
172      * Gets the source of position uncertainty.
173      *
174      * @return source of position uncertainty.
175      */
176     public PositionUncertaintySource getPositionUncertaintySource() {
177         return positionUncertaintySource;
178     }
179 
180     /**
181      * Sets source of position uncertainty.
182      *
183      * @param positionUncertaintySource source of position uncertainty.
184      */
185     public void setPositionUncertaintySource(final PositionUncertaintySource positionUncertaintySource) {
186         this.positionUncertaintySource = positionUncertaintySource;
187     }
188 
189     /**
190      * Indicates whether all sources have been provided to be able to
191      * create a {@link INSLooselyCoupledKalmanInitializerConfig} instance.
192      *
193      * @return true if the creator is ready, false otherwise.
194      */
195     public boolean isReady() {
196         return accelerometerBiasUncertaintySource != null
197                 && accelerometerBiasUncertaintySource.getEstimatedBiasStandardDeviationNorm() != null
198                 && gyroscopeBiasUncertaintySource != null
199                 && gyroscopeBiasUncertaintySource.getEstimatedBiasStandardDeviationNorm() != null
200                 && attitudeUncertaintySource != null
201                 && velocityUncertaintySource != null
202                 && positionUncertaintySource != null;
203     }
204 
205     /**
206      * Creates a {@link INSLooselyCoupledKalmanInitializerConfig} instance containing estimated
207      * parameters during calibration.
208      *
209      * @return instance containing initial configuration data.
210      * @throws NotReadyException if the creator is not ready.
211      */
212     public INSLooselyCoupledKalmanInitializerConfig create() throws NotReadyException {
213         if (!isReady()) {
214             throw new NotReadyException();
215         }
216 
217         final var attitudeUncertainty = attitudeUncertaintySource.getAttitudeUncertainty();
218         final var velocityUncertainty = velocityUncertaintySource.getVelocityUncertainty();
219         final var positionUncertainty = positionUncertaintySource.getPositionUncertainty();
220         final var accelerationBiasUncertainty =
221                 accelerometerBiasUncertaintySource.getEstimatedBiasStandardDeviationNorm();
222         final var gyroBiasUncertainty = gyroscopeBiasUncertaintySource.getEstimatedBiasStandardDeviationNorm();
223 
224         return new INSLooselyCoupledKalmanInitializerConfig(attitudeUncertainty, velocityUncertainty,
225                 positionUncertainty, accelerationBiasUncertainty, gyroBiasUncertainty);
226     }
227 }