From 5db3312a91637aebcb31ffc11538eb265c5e2967 Mon Sep 17 00:00:00 2001 From: HampusM Date: Tue, 1 Mar 2022 09:43:10 +0100 Subject: refactor: improve calibration value handling --- src/sensor/calibration.hpp | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) (limited to 'src/sensor/calibration.hpp') diff --git a/src/sensor/calibration.hpp b/src/sensor/calibration.hpp index a808fe9..a2da58b 100644 --- a/src/sensor/calibration.hpp +++ b/src/sensor/calibration.hpp @@ -28,6 +28,18 @@ constexpr uint32_t CALIBRATION_TIMEOUT = 120000; // Milliseconds constexpr unsigned int SENSOR_READ_CNT = 20; constexpr float SENSOR_VAL_ADJUST = 0.05; +class SensorCalibratorValues +{ +public: + double accel_x = 0; + double accel_y = 0; + double accel_z = 0; + + double gyro_x = 0; + double gyro_y = 0; + double gyro_z = 0; +}; + /** * Sensor calibrator. */ @@ -52,22 +64,13 @@ public: bool calibrate(unsigned int throttle_time); private: - void _resetValues(); - void _updateValues(); - void _adjustValues(); - bool _isValuesInRange() const; + void _updateValues(SensorCalibratorValues &values); + void _adjustCalibrationWithValues(const SensorCalibratorValues &values); - void _adjustCalibration(); + static void _adjustValues(SensorCalibratorValues &values); + static bool _isValuesInRange(const SensorCalibratorValues &values); UniquePtr _sensor; SerialStream _sout; - - double _accel_x = 0; - double _accel_y = 0; - double _accel_z = 0; - - double _gyro_x = 0; - double _gyro_y = 0; - double _gyro_z = 0; }; -- cgit v1.2.3-18-g5258