Home | History | Annotate | Download | only in accel_offset_cal
      1 /*
      2  * Copyright (C) 2018 The Android Open Source Project
      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 
     17 #ifndef LOCATION_LBS_CONTEXTHUB_NANOAPPS_CALIBRATION_ONLINE_CALIBRATION_ACCELEROMETER_ACCEL_OFFSET_CAL_ACCEL_OFFSET_CAL_H_
     18 #define LOCATION_LBS_CONTEXTHUB_NANOAPPS_CALIBRATION_ONLINE_CALIBRATION_ACCELEROMETER_ACCEL_OFFSET_CAL_ACCEL_OFFSET_CAL_H_
     19 
     20 #include "calibration/accelerometer/accel_cal.h"
     21 #include "calibration/online_calibration/common_data/calibration_callback.h"
     22 #include "calibration/online_calibration/common_data/calibration_data.h"
     23 #include "calibration/online_calibration/common_data/online_calibration.h"
     24 #include "calibration/online_calibration/common_data/sensor_data.h"
     25 
     26 namespace online_calibration {
     27 
     28 /*
     29  * This class is a wrapper for accelerometer offset calibration.
     30  *
     31  * NOTE: Calibration quality reporting (quantitative metric is not used):
     32  *   Initialize             --> CalibrationQualityLevel::UNDETERMINED
     33  *                              CalibrationQuality.value =
     34  *                                kUndeterminedCalibrationQuality
     35  *   SetInitialCalibration  --> CalibrationQualityLevel::LOW_QUALITY
     36  *                              CalibrationQuality.value =
     37  *                                kUndeterminedCalibrationQuality
     38  *   New Calibration Update --> CalibrationQualityLevel::HIGH_QUALITY
     39  *                              CalibrationQuality.value =
     40  *                                kUndeterminedCalibrationQuality
     41  */
     42 class AccelOffsetCal final
     43     : public OnlineCalibration<CalibrationDataThreeAxis> {
     44  public:
     45   // Default constructor.
     46   AccelOffsetCal() = default;
     47 
     48   // Creates an AccelOffsetCal with specified algorithm parameters.
     49   explicit AccelOffsetCal(const AccelCalParameters& accel_cal_parameters) {
     50     Initialize(accel_cal_parameters);
     51   }
     52 
     53   // Initializes with specified algorithm parameters, and resets the calibration
     54   // data.
     55   void Initialize(const AccelCalParameters& accel_cal_parameters);
     56 
     57   // Sends new sensor data to the calibration algorithm, and returns the state
     58   // of the calibration update flags, 'cal_update_polling_flags_'.
     59   CalibrationTypeFlags SetMeasurement(const SensorData& sample) final;
     60 
     61   // Sets the initial calibration data of the calibration algorithm. Returns
     62   // true if set successfully.
     63   bool SetInitialCalibration(
     64       const CalibrationDataThreeAxis& input_cal_data) final;
     65 
     66   // Returns the calibration sensor type.
     67   SensorType get_sensor_type() const final {
     68     return SensorType::kAccelerometerMps2;
     69   };
     70 
     71  private:
     72   // Accelerometer offset calibration algorithm data structure.
     73   AccelCal accel_cal_;
     74 };
     75 
     76 }  // namespace online_calibration
     77 
     78 #endif  // LOCATION_LBS_CONTEXTHUB_NANOAPPS_CALIBRATION_ONLINE_CALIBRATION_ACCELEROMETER_ACCEL_OFFSET_CAL_ACCEL_OFFSET_CAL_H_
     79