DJI-Gimbal-FOC/src/linearHallSensor.h

60 lines
1.5 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"
/**
* @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-05-24 08:32:15 +00:00
@param minPos Minimum position in Openloop
@param maxPos Maximum position in Openloop
2022-05-19 21:32:31 +00:00
*/
2022-05-24 08:32:15 +00:00
LinearHallSensor(uint8_t ch1, uint8_t ch2, float minPos, float maxPos);
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();
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
float _maxSensor; // Max 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