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.intervals.thresholdfactor;
17  
18  import com.irurueta.navigation.inertial.calibration.BodyKinematicsSequence;
19  import com.irurueta.navigation.inertial.calibration.StandardDeviationTimedBodyKinematics;
20  
21  /**
22   * Default implementation to map a given measurement into a given quality score to be
23   * used for gyroscope calibration.
24   */
25  public class DefaultGyroscopeQualityScoreMapper implements
26          QualityScoreMapper<BodyKinematicsSequence<StandardDeviationTimedBodyKinematics>> {
27  
28      /**
29       * Maps a given value corresponding to a generated measurement, into a given quality score.
30       *
31       * @param value type of measurement.
32       * @return mapped quality score.
33       */
34      @Override
35      public double map(final BodyKinematicsSequence<StandardDeviationTimedBodyKinematics> value) {
36          final var items = value.getSortedItems();
37          if (items != null) {
38              final var count = value.getItemsCount();
39  
40              var avg = 0.0;
41              for (var item : items) {
42                  avg += (item.getSpecificForceStandardDeviation() + item.getAngularRateStandardDeviation()) / count;
43              }
44  
45              return 1.0 / (1.0 + avg);
46          } else {
47              return 0.0;
48          }
49      }
50  }