#ifndef LinearHallSensor_h #define LinearHallSensor_h #include "Arduino.h" #include "BLDCMotor.h" /** * @brief Linear Hall sensor class * */ class LinearHallSensor { public: /** Linear Hall Sensor class constructor @param ch1 Analog pin for channel 1 @param ch2 Analog pin for channel 2 */ LinearHallSensor(uint8_t ch1, uint8_t ch2); /** * @brief Initialize variable by measuring max and min value * */ void init(BLDCMotor motor); /** * @brief Read the sensors and return the current angle in rad * * @return rad and angle */ float readSensorCallbackStateMachine(); float readSensorCallback(); /** * @brief retrun the max angle of the motor * * @return max angle in rad */ float getMaxAngle(); private: uint32_t _analogPin1; uint32_t _analogPin2; // max values read from the ADC on channels during init uint32_t _maxCh1; uint32_t _maxCh2; uint32_t _minCh1; uint32_t _minCh2; float _prevPosition; float _currentPosition; float _estimatePosition; // current position + offset float _offset; // offset angle measured at init float _maxSensor; // Max range angle value measured (so command from 0 to that value) float _minPositionEndValue; // min pos in open loop mode float _maxPositionEndValue; }; #endif