LCOV - code coverage report
Current view: top level - AP_TempCalibration - AP_TempCalibration.h (source / functions) Hit Total Coverage
Test: lcov.info Lines: 1 1 100.0 %
Date: 2026-09-09 11:02:08 Functions: 1 1 100.0 %

          Line data    Source code
       1             : #pragma once
       2             : /*
       3             :    This program is free software: you can redistribute it and/or modify
       4             :    it under the terms of the GNU General Public License as published by
       5             :    the Free Software Foundation, either version 3 of the License, or
       6             :    (at your option) any later version.
       7             : 
       8             :    This program is distributed in the hope that it will be useful,
       9             :    but WITHOUT ANY WARRANTY; without even the implied warranty of
      10             :    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      11             :    GNU General Public License for more details.
      12             : 
      13             :    You should have received a copy of the GNU General Public License
      14             :    along with this program.  If not, see <http://www.gnu.org/licenses/>.
      15             :  */
      16             : /*
      17             :   temperature calibration library. This monitors temperature changes
      18             :   and opportunistically calibrates sensors when the vehicle is still
      19             :  */
      20             : 
      21             : #include "AP_TempCalibration_config.h"
      22             : 
      23             : #if AP_TEMPCALIBRATION_ENABLED
      24             : 
      25             : #include <AP_HAL/AP_HAL.h>
      26             : #include <AP_Param/AP_Param.h>
      27             : #include <AP_InertialSensor/AP_InertialSensor.h>
      28             : 
      29             : class AP_TempCalibration
      30             : {
      31             : public:
      32             :     // constructor.  This remains because construction of Copter's g2
      33             :     // object becomes problematic if we don't have at least one object
      34             :     // to initialise
      35        1001 :     AP_TempCalibration() {}
      36             : 
      37             :     // settable parameters
      38             :     static const struct AP_Param::GroupInfo var_info[];
      39             : 
      40             :     void update(void);
      41             : 
      42             :     /* Do not allow copies */
      43             :     CLASS_NO_COPY(AP_TempCalibration);
      44             : 
      45             :     enum {
      46             :         TC_DISABLED = 0,
      47             :         TC_ENABLE_USE = 1,
      48             :         TC_ENABLE_LEARN = 2,
      49             :     };
      50             :     
      51             : private:
      52             : 
      53             :     AP_Int8 enabled;
      54             :     AP_Int8 temp_min;
      55             :     AP_Int8 temp_max;
      56             :     AP_Float baro_exponent;
      57             :     
      58             :     Vector3f last_accels;
      59             : 
      60             :     float learn_temp_start;
      61             :     float learn_temp_step;
      62             :     uint16_t learn_count;
      63             :     uint16_t learn_i;
      64             :     float *learn_values;
      65             :     uint32_t last_learn_ms;
      66             : 
      67             :     // temperature at which baro correction starts
      68             :     const float Tzero = 25;
      69             : 
      70             :     const float exp_limit_max = 2;
      71             :     const float exp_limit_min = 0;
      72             :     float learn_delta = 0.01f;
      73             :     
      74             :     // require observation of at least 5 degrees of temp range to
      75             :     // start learning
      76             :     const float min_learn_temp_range = 7;
      77             :     
      78             :     void setup_learning(void);
      79             :     void learn_calibration(void);
      80             :     void apply_calibration(void);
      81             :     void calculate_calibration();
      82             :     float calculate_correction(float temp, float exponent) const;
      83             :     float calculate_p_range(float baro_factor) const;
      84             :     
      85             : };
      86             : 
      87             : #endif  // AP_TEMPCALIBRATION_ENABLED

Generated by: LCOV version 1.14