Home | History | Annotate | Download | only in mag_diverse_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_MAGNETOMETER_MAG_DIVERSE_CAL_MAG_DIVERSE_CAL_H_
     18 #define LOCATION_LBS_CONTEXTHUB_NANOAPPS_CALIBRATION_ONLINE_CALIBRATION_MAGNETOMETER_MAG_DIVERSE_CAL_MAG_DIVERSE_CAL_H_
     19 
     20 #include "calibration/diversity_checker/diversity_checker.h"
     21 #include "calibration/magnetometer/mag_cal/mag_cal.h"
     22 #include "calibration/online_calibration/common_data/calibration_callback.h"
     23 #include "calibration/online_calibration/common_data/calibration_data.h"
     24 #include "calibration/online_calibration/common_data/online_calibration.h"
     25 #include "calibration/online_calibration/common_data/sensor_data.h"
     26 
     27 namespace online_calibration {
     28 
     29 /*
     30  * This class is a wrapper for the magnetometer offset calibration with
     31  * diversity checking.
     32  *
     33  * NOTE: Calibration quality reporting:
     34  *   Initialize             --> CalibrationQualityLevel::UNDETERMINED
     35  *                              CalibrationQuality.value =
     36  *                                kUndeterminedCalibrationQuality
     37  *   SetInitialCalibration  --> CalibrationQualityLevel::UNDETERMINED
     38  *                              CalibrationQuality.value =
     39  *                                kUndeterminedCalibrationQuality
     40  *   New Calibration Update --> CalibrationQualityLevel::HIGH_QUALITY
     41  *                              CalibrationQuality.value = kHighQualityUt
     42  */
     43 class MagDiverseCal final : public OnlineCalibration<CalibrationDataThreeAxis> {
     44  public:
     45   // Empirically estimated upper bounds on offset error.
     46   static constexpr float kLowQualityUt = 1000.0f;  // Units of micro Tesla
     47   static constexpr float kHighQualityUt = 5.0f;    // Units of micro Tesla
     48 
     49   MagDiverseCal() = default;
     50 
     51   // Creates an MagDiverseCal with specified algorithm parameters.
     52   MagDiverseCal(const MagCalParameters& mag_cal_parameters,
     53                 const DiversityCheckerParameters& diversity_parameters) {
     54     Initialize(mag_cal_parameters, diversity_parameters);
     55   }
     56 
     57   // Initializes with specified algorithm parameters.
     58   void Initialize(const MagCalParameters& mag_cal_parameters,
     59                   const DiversityCheckerParameters& diversity_parameters);
     60 
     61   // Sends new sensor data to the calibration algorithm, and returns the state
     62   // of the calibration update flags, 'cal_update_polling_flags_'.
     63   CalibrationTypeFlags SetMeasurement(const SensorData& sample) final;
     64 
     65   // Sets the initial calibration data of the calibration algorithm. Returns
     66   // true if set successfully.
     67   bool SetInitialCalibration(
     68       const CalibrationDataThreeAxis& input_cal_data) final;
     69 
     70   // Returns the calibration sensor type.
     71   SensorType get_sensor_type() const final {
     72     return SensorType::kMagnetometerUt;
     73   };
     74 
     75  private:
     76   // MagCal algorithm data structure.
     77   MagCal mag_cal_;
     78 };
     79 
     80 }  // namespace online_calibration
     81 
     82 #endif  // LOCATION_LBS_CONTEXTHUB_NANOAPPS_CALIBRATION_ONLINE_CALIBRATION_MAGNETOMETER_MAG_DIVERSE_CAL_MAG_DIVERSE_CAL_H_
     83