DJI-Gimbal-FOC/src/linearHallSensor.h

68 lines
1.3 KiB
C
Raw Normal View History

2022-05-19 21:32:31 +00:00
#ifndef LinearHallSensor_h
#define LinearHallSensor_h
#include "Arduino.h"
#include "BLDCMotor.h"
enum Slope : int8_t{
INCREASING = 1,
DECREASING = -1,
EQUAL = 0
};
/**
* @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();
private:
uint8_t _analogPin1;
uint8_t _analogPin2;
uint16_t _maxCh1;
uint16_t _maxCh2;
uint16_t _minCh1;
uint16_t _minCh2;
float _currentPosition;
float _offset;
float _minPositionEndValue;
float _maxPositionEndValue;
uint16_t _prevCh1;
uint16_t _prevCh2;
int8_t _directionCh1;
int8_t _directionCh2;
uint8_t _state;
};
#endif