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.StandardDeviationBodyKinematics;
22 import com.irurueta.navigation.inertial.calibration.StandardDeviationTimedBodyKinematics;
23 import com.irurueta.navigation.inertial.calibration.accelerometer.AccelerometerCalibratorMeasurementType;
24 import com.irurueta.navigation.inertial.calibration.accelerometer.AccelerometerNonLinearCalibrator;
25 import com.irurueta.navigation.inertial.calibration.gyroscope.GyroscopeCalibratorMeasurementOrSequenceType;
26 import com.irurueta.navigation.inertial.calibration.gyroscope.GyroscopeNonLinearCalibrator;
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41 public class ExhaustiveAccelerometerAndGyroscopeIntervalDetectorThresholdFactorOptimizer extends
42 AccelerometerAndGyroscopeIntervalDetectorThresholdFactorOptimizer {
43
44
45
46
47 public static final double DEFAULT_STEP = 1.0;
48
49
50
51
52
53 private double thresholdFactorStep = DEFAULT_STEP;
54
55
56
57
58 public ExhaustiveAccelerometerAndGyroscopeIntervalDetectorThresholdFactorOptimizer() {
59 super();
60 }
61
62
63
64
65
66
67 public ExhaustiveAccelerometerAndGyroscopeIntervalDetectorThresholdFactorOptimizer(
68 final AccelerometerAndGyroscopeIntervalDetectorThresholdFactorOptimizerDataSource dataSource) {
69 super(dataSource);
70 }
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85 public ExhaustiveAccelerometerAndGyroscopeIntervalDetectorThresholdFactorOptimizer(
86 final AccelerometerNonLinearCalibrator accelerometerCalibrator,
87 final GyroscopeNonLinearCalibrator gyroscopeCalibrator) {
88 super(accelerometerCalibrator, gyroscopeCalibrator);
89 }
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106 public ExhaustiveAccelerometerAndGyroscopeIntervalDetectorThresholdFactorOptimizer(
107 final AccelerometerAndGyroscopeIntervalDetectorThresholdFactorOptimizerDataSource dataSource,
108 final AccelerometerNonLinearCalibrator accelerometerCalibrator,
109 final GyroscopeNonLinearCalibrator gyroscopeCalibrator) {
110 super(dataSource, accelerometerCalibrator, gyroscopeCalibrator);
111 }
112
113
114
115
116
117
118
119 public double getThresholdFactorStep() {
120 return thresholdFactorStep;
121 }
122
123
124
125
126
127
128
129
130
131 public void setThresholdFactorStep(final double thresholdStep) throws LockedException {
132 if (running) {
133 throw new LockedException();
134 }
135 if (thresholdStep <= 0.0) {
136 throw new IllegalArgumentException();
137 }
138
139 thresholdFactorStep = thresholdStep;
140 }
141
142
143
144
145
146
147
148
149
150
151
152
153 @Override
154 public double optimize() throws NotReadyException, LockedException,
155 IntervalDetectorThresholdFactorOptimizerException {
156 if (running) {
157 throw new LockedException();
158 }
159
160 if (!isReady()) {
161 throw new NotReadyException();
162 }
163
164 var hasResult = false;
165 minMse = Double.MAX_VALUE;
166 try {
167 running = true;
168
169 initProgress();
170 final var progressStep = (float) (thresholdFactorStep
171 / (thresholdFactorStep + maxThresholdFactor - minThresholdFactor));
172
173 if (listener != null) {
174 listener.onOptimizeStart(this);
175 }
176
177 for (var thresholdFactor = minThresholdFactor;
178 thresholdFactor <= maxThresholdFactor;
179 thresholdFactor += thresholdFactorStep) {
180 try {
181 evaluateForThresholdFactor(thresholdFactor);
182 hasResult = true;
183 } catch (final Exception ignore) {
184
185 }
186
187 progress += progressStep;
188 checkAndNotifyProgress();
189 }
190
191 if (!hasResult) {
192 throw new IntervalDetectorThresholdFactorOptimizerException();
193 }
194
195 if (listener != null) {
196 listener.onOptimizeEnd(this);
197 }
198
199 } finally {
200 running = false;
201 }
202
203 return optimalThresholdFactor;
204 }
205 }