1 /*
2 * Copyright (C) 2020 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.accelerometer;
17
18 import com.irurueta.algebra.Matrix;
19 import com.irurueta.navigation.LockedException;
20 import com.irurueta.navigation.NotReadyException;
21 import com.irurueta.navigation.inertial.calibration.CalibrationException;
22 import com.irurueta.navigation.inertial.calibration.StandardDeviationFrameBodyKinematics;
23 import com.irurueta.numerical.robust.MSACRobustEstimator;
24 import com.irurueta.numerical.robust.MSACRobustEstimatorListener;
25 import com.irurueta.numerical.robust.RobustEstimator;
26 import com.irurueta.numerical.robust.RobustEstimatorException;
27 import com.irurueta.numerical.robust.RobustEstimatorMethod;
28 import com.irurueta.units.Acceleration;
29
30 import java.util.List;
31
32 /**
33 * Robustly estimates accelerometer cross couplings and scaling factors using
34 * a MSAC algorithm to discard outliers.
35 * This estimator assumes that biases are known.
36 * <p>
37 * To use this calibrator at least 4 measurements at different known frames must
38 * be provided. In other words, accelerometer samples must be obtained at 4
39 * different positions, orientations and velocities (although typically velocities are
40 * always zero).
41 * <p>
42 * Measured specific force is assumed to follow the model shown below:
43 * <pre>
44 * fmeas = ba + (I + Ma) * ftrue + w
45 * </pre>
46 * Where:
47 * - fmeas is the measured specific force. This is a 3x1 vector.
48 * - ba is accelerometer bias. Ideally, on a perfect accelerometer, this should be a
49 * 3x1 zero vector.
50 * - I is the 3x3 identity matrix.
51 * - Ma is the 3x3 matrix containing cross-couplings and scaling factors. Ideally, on
52 * a perfect accelerometer, this should be a 3x3 zero matrix.
53 * - ftrue is ground-truth specific force.
54 * - w is measurement noise.
55 */
56 public class MSACRobustKnownBiasAndFrameAccelerometerCalibrator extends RobustKnownBiasAndFrameAccelerometerCalibrator {
57
58 /**
59 * Constant defining default threshold to determine whether samples are
60 * inliers or not.
61 */
62 public static final double DEFAULT_THRESHOLD = 1e-2;
63
64 /**
65 * Minimum value that can be set as threshold.
66 * Threshold must be strictly greater than 0.0.
67 */
68 public static final double MIN_THRESHOLD = 0.0;
69
70 /**
71 * Threshold to determine whether samples are inliers or not when
72 * testing possible estimation solutions.
73 */
74 private double threshold = DEFAULT_THRESHOLD;
75
76 /**
77 * Constructor.
78 */
79 public MSACRobustKnownBiasAndFrameAccelerometerCalibrator() {
80 super();
81 }
82
83 /**
84 * Constructor.
85 *
86 * @param listener listener to be notified of events such as when estimation
87 * starts, ends or its progress significantly changes.
88 */
89 public MSACRobustKnownBiasAndFrameAccelerometerCalibrator(
90 final RobustKnownBiasAndFrameAccelerometerCalibratorListener listener) {
91 super(listener);
92 }
93
94 /**
95 * Constructor.
96 *
97 * @param measurements list of body kinematics measurements with standard
98 * deviations taken at different frames (positions, orientations
99 * and velocities).
100 */
101 public MSACRobustKnownBiasAndFrameAccelerometerCalibrator(
102 final List<StandardDeviationFrameBodyKinematics> measurements) {
103 super(measurements);
104 }
105
106 /**
107 * Constructor.
108 *
109 * @param measurements list of body kinematics measurements with standard
110 * deviations taken at different frames (positions, orientations
111 * and velocities).
112 * @param listener listener to handle events raised by this calibrator.
113 */
114 public MSACRobustKnownBiasAndFrameAccelerometerCalibrator(
115 final List<StandardDeviationFrameBodyKinematics> measurements,
116 final RobustKnownBiasAndFrameAccelerometerCalibratorListener listener) {
117 super(measurements, listener);
118 }
119
120 /**
121 * Constructor.
122 *
123 * @param commonAxisUsed indicates whether z-axis is assumed to be common for
124 * accelerometer and gyroscope.
125 */
126 public MSACRobustKnownBiasAndFrameAccelerometerCalibrator(final boolean commonAxisUsed) {
127 super(commonAxisUsed);
128 }
129
130 /**
131 * Constructor.
132 *
133 * @param commonAxisUsed indicates whether z-axis is assumed to be common for
134 * accelerometer and gyroscope.
135 * @param listener listener to handle events raised by this calibrator.
136 */
137 public MSACRobustKnownBiasAndFrameAccelerometerCalibrator(
138 final boolean commonAxisUsed, final RobustKnownBiasAndFrameAccelerometerCalibratorListener listener) {
139 super(commonAxisUsed, listener);
140 }
141
142 /**
143 * Constructor.
144 *
145 * @param measurements list of body kinematics measurements with standard
146 * deviations taken at different frames (positions, orientations
147 * and velocities).
148 * @param commonAxisUsed indicates whether z-axis is assumed to be common for
149 * accelerometer and gyroscope.
150 */
151 public MSACRobustKnownBiasAndFrameAccelerometerCalibrator(
152 final List<StandardDeviationFrameBodyKinematics> measurements, final boolean commonAxisUsed) {
153 super(measurements, commonAxisUsed);
154 }
155
156 /**
157 * Constructor.
158 *
159 * @param measurements list of body kinematics measurements with standard
160 * deviations taken at different frames (positions, orientations
161 * and velocities).
162 * @param commonAxisUsed indicates whether z-axis is assumed to be common for
163 * accelerometer and gyroscope.
164 * @param listener listener to handle events raised by this calibrator.
165 */
166 public MSACRobustKnownBiasAndFrameAccelerometerCalibrator(
167 final List<StandardDeviationFrameBodyKinematics> measurements, final boolean commonAxisUsed,
168 final RobustKnownBiasAndFrameAccelerometerCalibratorListener listener) {
169 super(measurements, commonAxisUsed, listener);
170 }
171
172 /**
173 * Constructor.
174 *
175 * @param biasX known x coordinate of accelerometer bias expressed in meters per
176 * squared second (m/s^2).
177 * @param biasY known y coordinate of accelerometer bias expressed in meters per
178 * squared second (m/s^2).
179 * @param biasZ known z coordinate of accelerometer bias expressed in meters per
180 * squared second (m/s^2).
181 */
182 public MSACRobustKnownBiasAndFrameAccelerometerCalibrator(
183 final double biasX, final double biasY, final double biasZ) {
184 super(biasX, biasY, biasZ);
185 }
186
187 /**
188 * Constructor.
189 *
190 * @param biasX known x coordinate of accelerometer bias expressed in meters per
191 * squared second (m/s^2).
192 * @param biasY known y coordinate of accelerometer bias expressed in meters per
193 * squared second (m/s^2).
194 * @param biasZ known z coordinate of accelerometer bias expressed in meters per
195 * squared second (m/s^2).
196 * @param listener listener to be notified of events such as when estimation
197 * starts, ends or its progress significantly changes.
198 */
199 public MSACRobustKnownBiasAndFrameAccelerometerCalibrator(
200 final double biasX, final double biasY, final double biasZ,
201 final RobustKnownBiasAndFrameAccelerometerCalibratorListener listener) {
202 super(biasX, biasY, biasZ, listener);
203 }
204
205 /**
206 * Constructor.
207 *
208 * @param measurements list of body kinematics measurements with standard
209 * deviations taken at different frames (positions, orientations
210 * and velocities).
211 * @param biasX known x coordinate of accelerometer bias expressed in meters per
212 * squared second (m/s^2).
213 * @param biasY known y coordinate of accelerometer bias expressed in meters per
214 * squared second (m/s^2).
215 * @param biasZ known z coordinate of accelerometer bias expressed in meters per
216 * squared second (m/s^2).
217 */
218 public MSACRobustKnownBiasAndFrameAccelerometerCalibrator(
219 final List<StandardDeviationFrameBodyKinematics> measurements,
220 final double biasX, final double biasY, final double biasZ) {
221 super(measurements, biasX, biasY, biasZ);
222 }
223
224 /**
225 * Constructor.
226 *
227 * @param measurements list of body kinematics measurements with standard
228 * deviations taken at different frames (positions, orientations
229 * and velocities).
230 * @param biasX known x coordinate of accelerometer bias expressed in meters per
231 * squared second (m/s^2).
232 * @param biasY known y coordinate of accelerometer bias expressed in meters per
233 * squared second (m/s^2).
234 * @param biasZ known z coordinate of accelerometer bias expressed in meters per
235 * squared second (m/s^2).
236 * @param listener listener to handle events raised by this calibrator.
237 */
238 public MSACRobustKnownBiasAndFrameAccelerometerCalibrator(
239 final List<StandardDeviationFrameBodyKinematics> measurements,
240 final double biasX, final double biasY, final double biasZ,
241 final RobustKnownBiasAndFrameAccelerometerCalibratorListener listener) {
242 super(measurements, biasX, biasY, biasZ, listener);
243 }
244
245 /**
246 * Constructor.
247 *
248 * @param biasX known x coordinate of accelerometer bias expressed in meters per
249 * squared second (m/s^2).
250 * @param biasY known y coordinate of accelerometer bias expressed in meters per
251 * squared second (m/s^2).
252 * @param biasZ known z coordinate of accelerometer bias expressed in meters per
253 * squared second (m/s^2).
254 * @param commonAxisUsed indicates whether z-axis is assumed to be common for
255 * accelerometer and gyroscope.
256 */
257 public MSACRobustKnownBiasAndFrameAccelerometerCalibrator(
258 final double biasX, final double biasY, final double biasZ, final boolean commonAxisUsed) {
259 super(biasX, biasY, biasZ, commonAxisUsed);
260 }
261
262 /**
263 * Constructor.
264 *
265 * @param biasX known x coordinate of accelerometer bias expressed in meters per
266 * squared second (m/s^2).
267 * @param biasY known y coordinate of accelerometer bias expressed in meters per
268 * squared second (m/s^2).
269 * @param biasZ known z coordinate of accelerometer bias expressed in meters per
270 * squared second (m/s^2).
271 * @param commonAxisUsed indicates whether z-axis is assumed to be common for
272 * accelerometer and gyroscope.
273 * @param listener listener to handle events raised by this calibrator.
274 */
275 public MSACRobustKnownBiasAndFrameAccelerometerCalibrator(
276 final double biasX, final double biasY, final double biasZ, final boolean commonAxisUsed,
277 final RobustKnownBiasAndFrameAccelerometerCalibratorListener listener) {
278 super(biasX, biasY, biasZ, commonAxisUsed, listener);
279 }
280
281 /**
282 * Constructor.
283 *
284 * @param measurements list of body kinematics measurements with standard
285 * deviations taken at different frames (positions, orientations
286 * and velocities).
287 * @param biasX known x coordinate of accelerometer bias expressed in meters per
288 * squared second (m/s^2).
289 * @param biasY known y coordinate of accelerometer bias expressed in meters per
290 * squared second (m/s^2).
291 * @param biasZ known z coordinate of accelerometer bias expressed in meters per
292 * squared second (m/s^2).
293 * @param commonAxisUsed indicates whether z-axis is assumed to be common for
294 * accelerometer and gyroscope.
295 */
296 public MSACRobustKnownBiasAndFrameAccelerometerCalibrator(
297 final List<StandardDeviationFrameBodyKinematics> measurements,
298 final double biasX, final double biasY, final double biasZ, final boolean commonAxisUsed) {
299 super(measurements, biasX, biasY, biasZ, commonAxisUsed);
300 }
301
302 /**
303 * Constructor.
304 *
305 * @param measurements list of body kinematics measurements with standard
306 * deviations taken at different frames (positions, orientations
307 * and velocities).
308 * @param biasX known x coordinate of accelerometer bias expressed in meters per
309 * squared second (m/s^2).
310 * @param biasY known y coordinate of accelerometer bias expressed in meters per
311 * squared second (m/s^2).
312 * @param biasZ known z coordinate of accelerometer bias expressed in meters per
313 * squared second (m/s^2).
314 * @param commonAxisUsed indicates whether z-axis is assumed to be common for
315 * accelerometer and gyroscope.
316 * @param listener listener to handle events raised by this calibrator.
317 */
318 public MSACRobustKnownBiasAndFrameAccelerometerCalibrator(
319 final List<StandardDeviationFrameBodyKinematics> measurements,
320 final double biasX, final double biasY, final double biasZ, final boolean commonAxisUsed,
321 final RobustKnownBiasAndFrameAccelerometerCalibratorListener listener) {
322 super(measurements, biasX, biasY, biasZ, commonAxisUsed, listener);
323 }
324
325 /**
326 * Constructor.
327 *
328 * @param biasX known x coordinate of accelerometer bias.
329 * @param biasY known y coordinate of accelerometer bias.
330 * @param biasZ known z coordinate of accelerometer bias.
331 */
332 public MSACRobustKnownBiasAndFrameAccelerometerCalibrator(
333 final Acceleration biasX, final Acceleration biasY, final Acceleration biasZ) {
334 super(biasX, biasY, biasZ);
335 }
336
337 /**
338 * Constructor.
339 *
340 * @param biasX known x coordinate of accelerometer bias.
341 * @param biasY known y coordinate of accelerometer bias.
342 * @param biasZ known z coordinate of accelerometer bias.
343 * @param listener listener to be notified of events such as when estimation
344 * starts, ends or its progress significantly changes.
345 */
346 public MSACRobustKnownBiasAndFrameAccelerometerCalibrator(
347 final Acceleration biasX, final Acceleration biasY, final Acceleration biasZ,
348 final RobustKnownBiasAndFrameAccelerometerCalibratorListener listener) {
349 super(biasX, biasY, biasZ, listener);
350 }
351
352 /**
353 * Constructor.
354 *
355 * @param measurements list of body kinematics measurements with standard
356 * deviations taken at different frames (positions, orientations
357 * and velocities).
358 * @param biasX known x coordinate of accelerometer bias.
359 * @param biasY known y coordinate of accelerometer bias.
360 * @param biasZ known z coordinate of accelerometer bias.
361 */
362 public MSACRobustKnownBiasAndFrameAccelerometerCalibrator(
363 final List<StandardDeviationFrameBodyKinematics> measurements,
364 final Acceleration biasX, final Acceleration biasY, final Acceleration biasZ) {
365 super(measurements, biasX, biasY, biasZ);
366 }
367
368 /**
369 * Constructor.
370 *
371 * @param measurements list of body kinematics measurements with standard
372 * deviations taken at different frames (positions, orientations
373 * and velocities).
374 * @param biasX known x coordinate of accelerometer bias.
375 * @param biasY known y coordinate of accelerometer bias.
376 * @param biasZ known z coordinate of accelerometer bias.
377 * @param listener listener to handle events raised by this calibrator.
378 */
379 public MSACRobustKnownBiasAndFrameAccelerometerCalibrator(
380 final List<StandardDeviationFrameBodyKinematics> measurements,
381 final Acceleration biasX, final Acceleration biasY, final Acceleration biasZ,
382 final RobustKnownBiasAndFrameAccelerometerCalibratorListener listener) {
383 super(measurements, biasX, biasY, biasZ, listener);
384 }
385
386 /**
387 * Constructor.
388 *
389 * @param biasX known x coordinate of accelerometer bias.
390 * @param biasY known y coordinate of accelerometer bias.
391 * @param biasZ known z coordinate of accelerometer bias.
392 * @param commonAxisUsed indicates whether z-axis is assumed to be common for
393 * accelerometer and gyroscope.
394 */
395 public MSACRobustKnownBiasAndFrameAccelerometerCalibrator(
396 final Acceleration biasX, final Acceleration biasY, final Acceleration biasZ,
397 final boolean commonAxisUsed) {
398 super(biasX, biasY, biasZ, commonAxisUsed);
399 }
400
401 /**
402 * Constructor.
403 *
404 * @param biasX known x coordinate of accelerometer bias.
405 * @param biasY known y coordinate of accelerometer bias.
406 * @param biasZ known z coordinate of accelerometer bias.
407 * @param commonAxisUsed indicates whether z-axis is assumed to be common for
408 * accelerometer and gyroscope.
409 * @param listener listener to handle events raised by this calibrator.
410 */
411 public MSACRobustKnownBiasAndFrameAccelerometerCalibrator(
412 final Acceleration biasX, final Acceleration biasY, final Acceleration biasZ, final boolean commonAxisUsed,
413 final RobustKnownBiasAndFrameAccelerometerCalibratorListener listener) {
414 super(biasX, biasY, biasZ, commonAxisUsed, listener);
415 }
416
417 /**
418 * Constructor.
419 *
420 * @param measurements list of body kinematics measurements with standard
421 * deviations taken at different frames (positions, orientations
422 * and velocities).
423 * @param biasX known x coordinate of accelerometer bias.
424 * @param biasY known y coordinate of accelerometer bias.
425 * @param biasZ known z coordinate of accelerometer bias.
426 * @param commonAxisUsed indicates whether z-axis is assumed to be common for
427 * accelerometer and gyroscope.
428 */
429 public MSACRobustKnownBiasAndFrameAccelerometerCalibrator(
430 final List<StandardDeviationFrameBodyKinematics> measurements,
431 final Acceleration biasX, final Acceleration biasY, final Acceleration biasZ,
432 final boolean commonAxisUsed) {
433 super(measurements, biasX, biasY, biasZ, commonAxisUsed);
434 }
435
436 /**
437 * Constructor.
438 *
439 * @param measurements list of body kinematics measurements with standard
440 * deviations taken at different frames (positions, orientations
441 * and velocities).
442 * @param biasX known x coordinate of accelerometer bias.
443 * @param biasY known y coordinate of accelerometer bias.
444 * @param biasZ known z coordinate of accelerometer bias.
445 * @param commonAxisUsed indicates whether z-axis is assumed to be common for
446 * accelerometer and gyroscope.
447 * @param listener listener to handle events raised by this calibrator.
448 */
449 public MSACRobustKnownBiasAndFrameAccelerometerCalibrator(
450 final List<StandardDeviationFrameBodyKinematics> measurements,
451 final Acceleration biasX, final Acceleration biasY, final Acceleration biasZ, final boolean commonAxisUsed,
452 final RobustKnownBiasAndFrameAccelerometerCalibratorListener listener) {
453 super(measurements, biasX, biasY, biasZ, commonAxisUsed, listener);
454 }
455
456 /**
457 * Constructor.
458 *
459 * @param bias known accelerometer bias.
460 * @throws IllegalArgumentException if provided array does not have length 3.
461 */
462 public MSACRobustKnownBiasAndFrameAccelerometerCalibrator(final double[] bias) {
463 super(bias);
464 }
465
466 /**
467 * Constructor.
468 *
469 * @param bias known accelerometer bias.
470 * @param listener listener to be notified of events such as when estimation
471 * starts, ends or its progress significantly changes.
472 * @throws IllegalArgumentException if provided array does not have length 3.
473 */
474 public MSACRobustKnownBiasAndFrameAccelerometerCalibrator(
475 final double[] bias, final RobustKnownBiasAndFrameAccelerometerCalibratorListener listener) {
476 super(bias, listener);
477 }
478
479 /**
480 * Constructor.
481 *
482 * @param measurements list of body kinematics measurements with standard
483 * deviations taken at different frames (positions, orientations
484 * and velocities).
485 * @param bias known accelerometer bias.
486 * @throws IllegalArgumentException if provided array does not have length 3.
487 */
488 public MSACRobustKnownBiasAndFrameAccelerometerCalibrator(
489 final List<StandardDeviationFrameBodyKinematics> measurements, final double[] bias) {
490 super(measurements, bias);
491 }
492
493 /**
494 * Constructor.
495 *
496 * @param measurements list of body kinematics measurements with standard
497 * deviations taken at different frames (positions, orientations
498 * and velocities).
499 * @param bias known accelerometer bias.
500 * @param listener listener to handle events raised by this calibrator.
501 * @throws IllegalArgumentException if provided array does not have length 3.
502 */
503 public MSACRobustKnownBiasAndFrameAccelerometerCalibrator(
504 final List<StandardDeviationFrameBodyKinematics> measurements, final double[] bias,
505 final RobustKnownBiasAndFrameAccelerometerCalibratorListener listener) {
506 super(measurements, bias, listener);
507 }
508
509 /**
510 * Constructor.
511 *
512 * @param bias known accelerometer bias.
513 * @param commonAxisUsed indicates whether z-axis is assumed to be common for
514 * accelerometer and gyroscope.
515 * @throws IllegalArgumentException if provided array does not have length 3.
516 */
517 public MSACRobustKnownBiasAndFrameAccelerometerCalibrator(final double[] bias, final boolean commonAxisUsed) {
518 super(bias, commonAxisUsed);
519 }
520
521 /**
522 * Constructor.
523 *
524 * @param bias known accelerometer bias.
525 * @param commonAxisUsed indicates whether z-axis is assumed to be common for
526 * accelerometer and gyroscope.
527 * @param listener listener to handle events raised by this calibrator.
528 * @throws IllegalArgumentException if provided array does not have length 3.
529 */
530 public MSACRobustKnownBiasAndFrameAccelerometerCalibrator(
531 final double[] bias, final boolean commonAxisUsed,
532 final RobustKnownBiasAndFrameAccelerometerCalibratorListener listener) {
533 super(bias, commonAxisUsed, listener);
534 }
535
536 /**
537 * Constructor.
538 *
539 * @param measurements list of body kinematics measurements with standard
540 * deviations taken at different frames (positions, orientations
541 * and velocities).
542 * @param bias known accelerometer bias.
543 * @param commonAxisUsed indicates whether z-axis is assumed to be common for
544 * accelerometer and gyroscope.
545 * @throws IllegalArgumentException if provided array does not have length 3.
546 */
547 public MSACRobustKnownBiasAndFrameAccelerometerCalibrator(
548 final List<StandardDeviationFrameBodyKinematics> measurements, final double[] bias,
549 final boolean commonAxisUsed) {
550 super(measurements, bias, commonAxisUsed);
551 }
552
553 /**
554 * Constructor.
555 *
556 * @param measurements list of body kinematics measurements with standard
557 * deviations taken at different frames (positions, orientations
558 * and velocities).
559 * @param bias known accelerometer bias.
560 * @param commonAxisUsed indicates whether z-axis is assumed to be common for
561 * accelerometer and gyroscope.
562 * @param listener listener to handle events raised by this calibrator.
563 * @throws IllegalArgumentException if provided array does not have length 3.
564 */
565 public MSACRobustKnownBiasAndFrameAccelerometerCalibrator(
566 final List<StandardDeviationFrameBodyKinematics> measurements, final double[] bias,
567 final boolean commonAxisUsed, final RobustKnownBiasAndFrameAccelerometerCalibratorListener listener) {
568 super(measurements, bias, commonAxisUsed, listener);
569 }
570
571 /**
572 * Constructor.
573 *
574 * @param bias known accelerometer bias.
575 * @throws IllegalArgumentException if provided matrix is not 3x1.
576 */
577 public MSACRobustKnownBiasAndFrameAccelerometerCalibrator(final Matrix bias) {
578 super(bias);
579 }
580
581 /**
582 * Constructor.
583 *
584 * @param bias known accelerometer bias.
585 * @param listener listener to be notified of events such as when estimation
586 * starts, ends or its progress significantly changes.
587 * @throws IllegalArgumentException if provided matrix is not 3x1.
588 */
589 public MSACRobustKnownBiasAndFrameAccelerometerCalibrator(
590 final Matrix bias, final RobustKnownBiasAndFrameAccelerometerCalibratorListener listener) {
591 super(bias, listener);
592 }
593
594 /**
595 * Constructor.
596 *
597 * @param measurements list of body kinematics measurements with standard
598 * deviations taken at different frames (positions, orientations
599 * and velocities).
600 * @param bias known accelerometer bias.
601 * @throws IllegalArgumentException if provided matrix is not 3x1.
602 */
603 public MSACRobustKnownBiasAndFrameAccelerometerCalibrator(
604 final List<StandardDeviationFrameBodyKinematics> measurements, final Matrix bias) {
605 super(measurements, bias);
606 }
607
608 /**
609 * Constructor.
610 *
611 * @param measurements list of body kinematics measurements with standard
612 * deviations taken at different frames (positions, orientations
613 * and velocities).
614 * @param bias known accelerometer bias.
615 * @param listener listener to handle events raised by this calibrator.
616 * @throws IllegalArgumentException if provided matrix is not 3x1.
617 */
618 public MSACRobustKnownBiasAndFrameAccelerometerCalibrator(
619 final List<StandardDeviationFrameBodyKinematics> measurements, final Matrix bias,
620 final RobustKnownBiasAndFrameAccelerometerCalibratorListener listener) {
621 super(measurements, bias, listener);
622 }
623
624 /**
625 * Constructor.
626 *
627 * @param bias known accelerometer bias.
628 * @param commonAxisUsed indicates whether z-axis is assumed to be common for
629 * accelerometer and gyroscope.
630 * @throws IllegalArgumentException if provided matrix is not 3x1.
631 */
632 public MSACRobustKnownBiasAndFrameAccelerometerCalibrator(final Matrix bias, final boolean commonAxisUsed) {
633 super(bias, commonAxisUsed);
634 }
635
636 /**
637 * Constructor.
638 *
639 * @param bias known accelerometer bias.
640 * @param commonAxisUsed indicates whether z-axis is assumed to be common for
641 * accelerometer and gyroscope.
642 * @param listener listener to handle events raised by this calibrator.
643 * @throws IllegalArgumentException if provided matrix is not 3x1.
644 */
645 public MSACRobustKnownBiasAndFrameAccelerometerCalibrator(
646 final Matrix bias, final boolean commonAxisUsed,
647 final RobustKnownBiasAndFrameAccelerometerCalibratorListener listener) {
648 super(bias, commonAxisUsed, listener);
649 }
650
651 /**
652 * Constructor.
653 *
654 * @param measurements list of body kinematics measurements with standard
655 * deviations taken at different frames (positions, orientations
656 * and velocities).
657 * @param bias known accelerometer bias.
658 * @param commonAxisUsed indicates whether z-axis is assumed to be common for
659 * accelerometer and gyroscope.
660 * @throws IllegalArgumentException if provided matrix is not 3x1.
661 */
662 public MSACRobustKnownBiasAndFrameAccelerometerCalibrator(
663 final List<StandardDeviationFrameBodyKinematics> measurements, final Matrix bias,
664 final boolean commonAxisUsed) {
665 super(measurements, bias, commonAxisUsed);
666 }
667
668 /**
669 * Constructor.
670 *
671 * @param measurements list of body kinematics measurements with standard
672 * deviations taken at different frames (positions, orientations
673 * and velocities).
674 * @param bias known accelerometer bias.
675 * @param commonAxisUsed indicates whether z-axis is assumed to be common for
676 * accelerometer and gyroscope.
677 * @param listener listener to handle events raised by this calibrator.
678 * @throws IllegalArgumentException if provided matrix is not 3x1.
679 */
680 public MSACRobustKnownBiasAndFrameAccelerometerCalibrator(
681 final List<StandardDeviationFrameBodyKinematics> measurements, final Matrix bias,
682 final boolean commonAxisUsed, final RobustKnownBiasAndFrameAccelerometerCalibratorListener listener) {
683 super(measurements, bias, commonAxisUsed, listener);
684 }
685
686 /**
687 * Returns threshold to determine whether samples are inliers or not.
688 *
689 * @return threshold to determine whether samples are inliers or not.
690 */
691 public double getThreshold() {
692 return threshold;
693 }
694
695 /**
696 * Sets threshold to determine whether samples are inliers or not.
697 *
698 * @param threshold threshold to be set.
699 * @throws IllegalArgumentException if provided value is equal or less than
700 * zero.
701 * @throws LockedException if calibrator is currently running.
702 */
703 public void setThreshold(final double threshold) throws LockedException {
704 if (running) {
705 throw new LockedException();
706 }
707 if (threshold <= MIN_THRESHOLD) {
708 throw new IllegalArgumentException();
709 }
710 this.threshold = threshold;
711 }
712
713 /**
714 * Estimates accelerometer calibration parameters containing scale factors
715 * and cross-coupling errors.
716 *
717 * @throws LockedException if calibrator is currently running.
718 * @throws NotReadyException if calibrator is not ready.
719 * @throws CalibrationException if estimation fails for numerical reasons.
720 */
721 @Override
722 public void calibrate() throws LockedException, NotReadyException, CalibrationException {
723 if (running) {
724 throw new LockedException();
725 }
726 if (!isReady()) {
727 throw new NotReadyException();
728 }
729
730 final var innerEstimator = new MSACRobustEstimator<>(new MSACRobustEstimatorListener<Matrix>() {
731 @Override
732 public double getThreshold() {
733 return threshold;
734 }
735
736 @Override
737 public int getTotalSamples() {
738 return measurements.size();
739 }
740
741 @Override
742 public int getSubsetSize() {
743 return preliminarySubsetSize;
744 }
745
746 @Override
747 public void estimatePreliminarSolutions(final int[] samplesIndices, final List<Matrix> solutions) {
748 computePreliminarySolutions(samplesIndices, solutions);
749 }
750
751 @Override
752 public double computeResidual(final Matrix currentEstimation, final int i) {
753 return computeError(measurements.get(i), currentEstimation);
754 }
755
756 @Override
757 public boolean isReady() {
758 return MSACRobustKnownBiasAndFrameAccelerometerCalibrator.super.isReady();
759 }
760
761 @Override
762 public void onEstimateStart(final RobustEstimator<Matrix> estimator) {
763 // no action needed
764 }
765
766 @Override
767 public void onEstimateEnd(final RobustEstimator<Matrix> estimator) {
768 // no action needed
769 }
770
771 @Override
772 public void onEstimateNextIteration(final RobustEstimator<Matrix> estimator, final int iteration) {
773 if (listener != null) {
774 listener.onCalibrateNextIteration(
775 MSACRobustKnownBiasAndFrameAccelerometerCalibrator.this, iteration);
776 }
777 }
778
779 @Override
780 public void onEstimateProgressChange(final RobustEstimator<Matrix> estimator, final float progress) {
781 if (listener != null) {
782 listener.onCalibrateProgressChange(
783 MSACRobustKnownBiasAndFrameAccelerometerCalibrator.this, progress);
784 }
785 }
786 });
787
788 try {
789 running = true;
790
791 if (listener != null) {
792 listener.onCalibrateStart(this);
793 }
794
795 inliersData = null;
796 innerEstimator.setConfidence(confidence);
797 innerEstimator.setMaxIterations(maxIterations);
798 innerEstimator.setProgressDelta(progressDelta);
799 final var preliminaryResult = innerEstimator.estimate();
800 inliersData = innerEstimator.getInliersData();
801
802 attemptRefine(preliminaryResult);
803
804 if (listener != null) {
805 listener.onCalibrateEnd(this);
806 }
807
808 } catch (final com.irurueta.numerical.LockedException e) {
809 throw new LockedException(e);
810 } catch (final com.irurueta.numerical.NotReadyException e) {
811 throw new NotReadyException(e);
812 } catch (final RobustEstimatorException e) {
813 throw new CalibrationException(e);
814 } finally {
815 running = false;
816 }
817 }
818
819 /**
820 * Returns method being used for robust estimation.
821 *
822 * @return method being used for robust estimation.
823 */
824 @Override
825 public RobustEstimatorMethod getMethod() {
826 return RobustEstimatorMethod.MSAC;
827 }
828
829 /**
830 * Indicates whether this calibrator requires quality scores for each
831 * measurement or not.
832 *
833 * @return true if quality scores are required, false otherwise.
834 */
835 @Override
836 public boolean isQualityScoresRequired() {
837 return false;
838 }
839 }