1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package com.irurueta.navigation.inertial.calibration.intervals.thresholdfactor;
17
18 import com.irurueta.navigation.LockedException;
19 import com.irurueta.navigation.NotReadyException;
20 import com.irurueta.navigation.inertial.calibration.BodyKinematicsSequence;
21 import com.irurueta.navigation.inertial.calibration.gyroscope.GyroscopeCalibratorMeasurementOrSequenceType;
22 import com.irurueta.navigation.inertial.calibration.gyroscope.GyroscopeNonLinearCalibrator;
23
24
25
26
27
28
29
30
31
32
33
34 public class ExhaustiveGyroscopeIntervalDetectorThresholdFactorOptimizer extends
35 GyroscopeIntervalDetectorThresholdFactorOptimizer {
36
37
38
39
40 public static final double DEFAULT_STEP = 1.0;
41
42
43
44
45
46 private double thresholdFactorStep = DEFAULT_STEP;
47
48
49
50
51 public ExhaustiveGyroscopeIntervalDetectorThresholdFactorOptimizer() {
52 super();
53 }
54
55
56
57
58
59
60 public ExhaustiveGyroscopeIntervalDetectorThresholdFactorOptimizer(
61 final GyroscopeIntervalDetectorThresholdFactorOptimizerDataSource dataSource) {
62 super(dataSource);
63 }
64
65
66
67
68
69
70
71
72
73 public ExhaustiveGyroscopeIntervalDetectorThresholdFactorOptimizer(final GyroscopeNonLinearCalibrator calibrator) {
74 super(calibrator);
75 }
76
77
78
79
80
81
82
83
84
85
86 public ExhaustiveGyroscopeIntervalDetectorThresholdFactorOptimizer(
87 final GyroscopeIntervalDetectorThresholdFactorOptimizerDataSource dataSource,
88 final GyroscopeNonLinearCalibrator calibrator) {
89 super(dataSource, calibrator);
90 }
91
92
93
94
95
96
97
98 public double getThresholdFactorStep() {
99 return thresholdFactorStep;
100 }
101
102
103
104
105
106
107
108
109
110 public void setThresholdFactorStep(final double thresholdStep) throws LockedException {
111 if (running) {
112 throw new LockedException();
113 }
114 if (thresholdStep <= 0.0) {
115 throw new IllegalArgumentException();
116 }
117
118 thresholdFactorStep = thresholdStep;
119 }
120
121
122
123
124
125
126
127
128
129
130
131
132 @Override
133 public double optimize() throws NotReadyException, LockedException,
134 IntervalDetectorThresholdFactorOptimizerException {
135 if (running) {
136 throw new LockedException();
137 }
138
139 if (!isReady()) {
140 throw new NotReadyException();
141 }
142
143 var hasResult = false;
144 minMse = Double.MAX_VALUE;
145 try {
146 running = true;
147
148 initProgress();
149 final var progressStep = (float) (thresholdFactorStep
150 / (thresholdFactorStep + maxThresholdFactor - minThresholdFactor));
151
152 if (listener != null) {
153 listener.onOptimizeStart(this);
154 }
155
156 for (var thresholdFactor = minThresholdFactor;
157 thresholdFactor <= maxThresholdFactor;
158 thresholdFactor += thresholdFactorStep) {
159 try {
160 evaluateForThresholdFactor(thresholdFactor);
161 hasResult = true;
162 } catch (final Exception ignore) {
163
164 }
165
166 progress += progressStep;
167 checkAndNotifyProgress();
168 }
169
170 if (!hasResult) {
171 throw new IntervalDetectorThresholdFactorOptimizerException();
172 }
173
174 if (listener != null) {
175 listener.onOptimizeEnd(this);
176 }
177
178 } finally {
179 running = false;
180 }
181
182 return optimalThresholdFactor;
183 }
184 }