View Javadoc
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.generators;
17  
18  import com.irurueta.navigation.inertial.BodyKinematics;
19  import com.irurueta.navigation.inertial.calibration.StandardDeviationBodyKinematics;
20  
21  /**
22   * Generates measurements for the calibration of accelerometers by alternating
23   * static and dynamic intervals where device is kept static or moved.
24   * Generated measurements must be used with accelerometer calibrators based
25   * on the knowledge of gravity norm (or Earth position) when the device orientation
26   * is unknown.
27   * Such calibrators are the following ones:
28   * - {@link com.irurueta.navigation.inertial.calibration.accelerometer.KnownGravityNormAccelerometerCalibrator}
29   * - {@link com.irurueta.navigation.inertial.calibration.accelerometer.KnownPositionAccelerometerCalibrator}
30   * - {@link com.irurueta.navigation.inertial.calibration.accelerometer.KnownBiasAndGravityNormAccelerometerCalibrator}
31   * - {@link com.irurueta.navigation.inertial.calibration.accelerometer.KnownBiasAndPositionAccelerometerCalibrator}
32   * - {@link com.irurueta.navigation.inertial.calibration.accelerometer.RobustKnownGravityNormAccelerometerCalibrator}
33   * and all its implementations.
34   * - {@link com.irurueta.navigation.inertial.calibration.accelerometer.RobustKnownPositionAccelerometerCalibrator}
35   * and all its implementations.
36   * - {@link com.irurueta.navigation.inertial.calibration.accelerometer.RobustKnownBiasAndGravityNormAccelerometerCalibrator}
37   * and all its implementations.
38   * - {@link com.irurueta.navigation.inertial.calibration.accelerometer.RobustKnownBiasAndPositionAccelerometerCalibrator}
39   * and all its implementations.
40   */
41  public class AccelerometerMeasurementsGenerator extends
42          MeasurementsGenerator<StandardDeviationBodyKinematics, AccelerometerMeasurementsGenerator,
43                  AccelerometerMeasurementsGeneratorListener, BodyKinematics> {
44  
45      /**
46       * Constructor.
47       */
48      public AccelerometerMeasurementsGenerator() {
49          super();
50      }
51  
52      /**
53       * Constructor.
54       *
55       * @param listener listener to handle events raised by this generator.
56       */
57      public AccelerometerMeasurementsGenerator(final AccelerometerMeasurementsGeneratorListener listener) {
58          super(listener);
59      }
60  
61      /**
62       * Post process provided input sample.
63       *
64       * @param sample an input sample.
65       */
66      @Override
67      protected void postProcess(final BodyKinematics sample) {
68          // no action required for accelerometer calibration
69      }
70  
71      /**
72       * Gets corresponding acceleration triad from provided input sample.
73       * This method must store the result into {@link #triad}.
74       *
75       * @param sample input sample.
76       */
77      @Override
78      protected void getAccelerationTriadFromInputSample(final BodyKinematics sample) {
79          sample.getSpecificForceTriad(triad);
80      }
81  
82      /**
83       * Handles a static-to-dynamic interval change.
84       *
85       * @param accumulatedAvgX average x-coordinate of measurements during last
86       *                        static period expressed in meters per squared
87       *                        second (m/s^2).
88       * @param accumulatedAvgY average y-coordinate of specific force during last
89       *                        static period expressed in meters per squared
90       *                        second (m/s^2).
91       * @param accumulatedAvgZ average z-coordinate of specific force during last
92       *                        static period expressed in meters per squared
93       *                        second (m/s^2).
94       * @param accumulatedStdX standard deviation of x-coordinate of measurements
95       *                        during last static period expressed in meters per
96       *                        squared second (m/s^2).
97       * @param accumulatedStdY standard deviation of y-coordinate of measurements
98       *                        during last static period expressed in meters per
99       *                        squared second (m/s^2).
100      * @param accumulatedStdZ standard deviation of z-coordinate of measurements
101      *                        during last static period expressed in meters per
102      *                        squared second (m/s^2).
103      */
104     @Override
105     protected void handleStaticToDynamicChange(
106             final double accumulatedAvgX, final double accumulatedAvgY, final double accumulatedAvgZ,
107             final double accumulatedStdX, final double accumulatedStdY, final double accumulatedStdZ) {
108         // if last static interval must not be skipped, keep accumulated average
109         // specific force during last static interval and generate new measurement
110         // NOTE: generated body kinematics instances will have zero angular rate
111         // since it is not needed for accelerometer calibration
112         if (!isStaticIntervalSkipped()) {
113 
114             final var kinematics = new BodyKinematics();
115             kinematics.setSpecificForceCoordinates(accumulatedAvgX, accumulatedAvgY, accumulatedAvgZ);
116 
117             final var measurement = new StandardDeviationBodyKinematics();
118             measurement.setKinematics(kinematics);
119 
120             final var avgStd = (accumulatedStdX + accumulatedStdY + accumulatedStdZ) / 3.0;
121             measurement.setSpecificForceStandardDeviation(avgStd);
122 
123             if (listener != null) {
124                 listener.onGeneratedMeasurement(this, measurement);
125             }
126         }
127     }
128 
129     /**
130      * Handles a dynamic-to-static interval change.
131      */
132     @Override
133     protected void handleDynamicToStaticChange() {
134         // no action needed.
135     }
136 
137     /**
138      * Handles an initialization completion.
139      */
140     @Override
141     protected void handleInitializationCompleted() {
142         // no action needed.
143     }
144 
145     /**
146      * Handles an error during initialization.
147      */
148     @Override
149     protected void handleInitializationFailed() {
150         // no action needed.
151     }
152 }