60 lines
1.5 KiB
C++
60 lines
1.5 KiB
C++
#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
|
|
@param minPos Minimum position in Openloop
|
|
@param maxPos Maximum position in Openloop
|
|
*/
|
|
LinearHallSensor(uint8_t ch1, uint8_t ch2, float minPos, float maxPos);
|
|
|
|
|
|
/**
|
|
* @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:
|
|
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 angle value measured (so command from 0 to that value)
|
|
|
|
float _minPositionEndValue; // min pos in open loop mode
|
|
float _maxPositionEndValue;
|
|
};
|
|
|
|
#endif |