2022-05-19 21:32:31 +00:00
|
|
|
#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
|
|
|
|
*/
|
2022-08-30 09:21:03 +00:00
|
|
|
LinearHallSensor(uint8_t ch1, uint8_t ch2);
|
2022-05-19 21:32:31 +00:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @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();
|
2022-11-07 10:09:23 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief retrun the max angle of the motor
|
|
|
|
*
|
|
|
|
* @return max angle in rad
|
|
|
|
*/
|
|
|
|
float getMaxAngle();
|
|
|
|
|
2022-05-19 21:32:31 +00:00
|
|
|
|
|
|
|
private:
|
2022-05-24 08:32:15 +00:00
|
|
|
uint32_t _analogPin1;
|
|
|
|
uint32_t _analogPin2;
|
2022-05-19 21:32:31 +00:00
|
|
|
|
2022-05-24 08:32:15 +00:00
|
|
|
// max values read from the ADC on channels during init
|
|
|
|
uint32_t _maxCh1;
|
|
|
|
uint32_t _maxCh2;
|
|
|
|
uint32_t _minCh1;
|
|
|
|
uint32_t _minCh2;
|
2022-05-19 21:32:31 +00:00
|
|
|
|
2022-05-24 08:32:15 +00:00
|
|
|
float _prevPosition;
|
2022-05-19 21:32:31 +00:00
|
|
|
float _currentPosition;
|
2022-05-24 08:32:15 +00:00
|
|
|
float _estimatePosition; // current position + offset
|
|
|
|
float _offset; // offset angle measured at init
|
2022-11-07 10:09:23 +00:00
|
|
|
float _maxSensor; // Max range angle value measured (so command from 0 to that value)
|
2022-05-19 21:32:31 +00:00
|
|
|
|
2022-05-24 08:32:15 +00:00
|
|
|
float _minPositionEndValue; // min pos in open loop mode
|
2022-05-19 21:32:31 +00:00
|
|
|
float _maxPositionEndValue;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|