DRV8323RS Version
Dependencies: mbed-dev-f303 FastPWM3
PositionSensor/PositionSensor.h@22:60276ba87ac6, 2017-03-31 (annotated)
- Committer:
- benkatz
- Date:
- Fri Mar 31 18:24:46 2017 +0000
- Revision:
- 22:60276ba87ac6
- Parent:
- 20:bf9ea5125d52
- Child:
- 34:51647c6c500d
Encoder autocalibration for dc offset and harmonics
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
benkatz | 0:4e1c4df6aabd | 1 | #ifndef POSITIONSENSOR_H |
benkatz | 0:4e1c4df6aabd | 2 | #define POSITIONSENSOR_H |
benkatz | 0:4e1c4df6aabd | 3 | class PositionSensor { |
benkatz | 0:4e1c4df6aabd | 4 | public: |
benkatz | 22:60276ba87ac6 | 5 | virtual void Sample(void) = 0; |
benkatz | 0:4e1c4df6aabd | 6 | virtual float GetMechPosition() {return 0.0f;} |
benkatz | 0:4e1c4df6aabd | 7 | virtual float GetElecPosition() {return 0.0f;} |
benkatz | 9:d7eb815cb057 | 8 | virtual float GetMechVelocity() {return 0.0f;} |
benkatz | 13:a3fa0a31b114 | 9 | virtual float GetElecVelocity() {return 0.0f;} |
benkatz | 22:60276ba87ac6 | 10 | virtual void ZeroPosition(void) = 0; |
benkatz | 22:60276ba87ac6 | 11 | virtual int GetRawPosition(void) = 0; |
benkatz | 22:60276ba87ac6 | 12 | virtual void SetElecOffset(float offset) = 0; |
benkatz | 22:60276ba87ac6 | 13 | virtual int GetCPR(void) = 0; |
benkatz | 22:60276ba87ac6 | 14 | virtual void WriteLUT(int new_lut[128]) = 0; |
benkatz | 0:4e1c4df6aabd | 15 | }; |
benkatz | 0:4e1c4df6aabd | 16 | |
benkatz | 0:4e1c4df6aabd | 17 | |
benkatz | 0:4e1c4df6aabd | 18 | class PositionSensorEncoder: public PositionSensor { |
benkatz | 0:4e1c4df6aabd | 19 | public: |
benkatz | 10:370851e6e132 | 20 | PositionSensorEncoder(int CPR, float offset, int ppairs); |
benkatz | 22:60276ba87ac6 | 21 | virtual void Sample(); |
benkatz | 0:4e1c4df6aabd | 22 | virtual float GetMechPosition(); |
benkatz | 0:4e1c4df6aabd | 23 | virtual float GetElecPosition(); |
benkatz | 3:6a0015d88d06 | 24 | virtual float GetMechVelocity(); |
benkatz | 3:6a0015d88d06 | 25 | virtual float GetElecVelocity(); |
benkatz | 22:60276ba87ac6 | 26 | virtual void ZeroPosition(void); |
benkatz | 22:60276ba87ac6 | 27 | virtual void SetElecOffset(float offset); |
benkatz | 22:60276ba87ac6 | 28 | virtual int GetRawPosition(void); |
benkatz | 22:60276ba87ac6 | 29 | virtual int GetCPR(void); |
benkatz | 22:60276ba87ac6 | 30 | virtual void WriteLUT(int new_lut[128]); |
benkatz | 0:4e1c4df6aabd | 31 | private: |
benkatz | 0:4e1c4df6aabd | 32 | InterruptIn *ZPulse; |
benkatz | 0:4e1c4df6aabd | 33 | DigitalIn *ZSense; |
benkatz | 1:b8bceb4daed5 | 34 | //DigitalOut *ZTest; |
benkatz | 0:4e1c4df6aabd | 35 | virtual void ZeroEncoderCount(void); |
benkatz | 7:dc5f27756e02 | 36 | virtual void ZeroEncoderCountDown(void); |
benkatz | 22:60276ba87ac6 | 37 | int _CPR, flag, rotations, _ppairs, raw; |
benkatz | 1:b8bceb4daed5 | 38 | //int state; |
benkatz | 22:60276ba87ac6 | 39 | float _offset, MechPosition, MechOffset, dir, test_pos, oldVel, out_old, velVec[16]; |
benkatz | 22:60276ba87ac6 | 40 | int offset_lut[128]; |
benkatz | 8:10ae7bc88d6e | 41 | }; |
benkatz | 14:80ce59119d93 | 42 | |
benkatz | 14:80ce59119d93 | 43 | class PositionSensorAM5147: public PositionSensor{ |
benkatz | 14:80ce59119d93 | 44 | public: |
benkatz | 14:80ce59119d93 | 45 | PositionSensorAM5147(int CPR, float offset, int ppairs); |
benkatz | 22:60276ba87ac6 | 46 | virtual void Sample(); |
benkatz | 14:80ce59119d93 | 47 | virtual float GetMechPosition(); |
benkatz | 14:80ce59119d93 | 48 | virtual float GetElecPosition(); |
benkatz | 14:80ce59119d93 | 49 | virtual float GetMechVelocity(); |
benkatz | 14:80ce59119d93 | 50 | virtual int GetRawPosition(); |
benkatz | 14:80ce59119d93 | 51 | virtual void ZeroPosition(); |
benkatz | 22:60276ba87ac6 | 52 | virtual void SetElecOffset(float offset); |
benkatz | 22:60276ba87ac6 | 53 | virtual int GetCPR(void); |
benkatz | 22:60276ba87ac6 | 54 | virtual void WriteLUT(int new_lut[128]); |
benkatz | 14:80ce59119d93 | 55 | private: |
benkatz | 22:60276ba87ac6 | 56 | float position, ElecPosition, ElecOffset, MechPosition, MechOffset, modPosition, oldModPosition, oldVel, velVec[16], MechVelocity, ElecVelocity; |
benkatz | 22:60276ba87ac6 | 57 | int raw, _CPR, rotations, old_counts, _ppairs; |
benkatz | 14:80ce59119d93 | 58 | SPI *spi; |
benkatz | 14:80ce59119d93 | 59 | DigitalOut *cs; |
benkatz | 14:80ce59119d93 | 60 | int readAngleCmd; |
benkatz | 22:60276ba87ac6 | 61 | int offset_lut[128]; |
benkatz | 14:80ce59119d93 | 62 | |
benkatz | 14:80ce59119d93 | 63 | }; |
benkatz | 20:bf9ea5125d52 | 64 | |
benkatz | 0:4e1c4df6aabd | 65 | #endif |