hobbyking_cheetah source code modified 2020/12/15
Dependencies: mbed-dev-f303 FastPWM3
PositionSensor/PositionSensor.h@37:c0f352d6e8e3, 2018-04-13 (annotated)
- Committer:
- benkatz
- Date:
- Fri Apr 13 13:50:54 2018 +0000
- Revision:
- 37:c0f352d6e8e3
- Parent:
- 35:69b24894c11d
- Child:
- 38:67e4e1453a4b
always samples position sensor
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 | 35:69b24894c11d | 39 | float _offset, MechPosition, MechOffset, dir, test_pos, oldVel, out_old, velVec[40]; |
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 | 37:c0f352d6e8e3 | 50 | virtual float GetElecVelocity(); |
benkatz | 14:80ce59119d93 | 51 | virtual int GetRawPosition(); |
benkatz | 14:80ce59119d93 | 52 | virtual void ZeroPosition(); |
benkatz | 22:60276ba87ac6 | 53 | virtual void SetElecOffset(float offset); |
benkatz | 37:c0f352d6e8e3 | 54 | virtual void SetMechOffset(float offset); |
benkatz | 22:60276ba87ac6 | 55 | virtual int GetCPR(void); |
benkatz | 22:60276ba87ac6 | 56 | virtual void WriteLUT(int new_lut[128]); |
benkatz | 14:80ce59119d93 | 57 | private: |
benkatz | 35:69b24894c11d | 58 | float position, ElecPosition, ElecOffset, MechPosition, MechOffset, modPosition, oldModPosition, oldVel, velVec[40], MechVelocity, ElecVelocity, ElecVelocityFilt; |
benkatz | 22:60276ba87ac6 | 59 | int raw, _CPR, rotations, old_counts, _ppairs; |
benkatz | 14:80ce59119d93 | 60 | SPI *spi; |
benkatz | 14:80ce59119d93 | 61 | DigitalOut *cs; |
benkatz | 14:80ce59119d93 | 62 | int readAngleCmd; |
benkatz | 22:60276ba87ac6 | 63 | int offset_lut[128]; |
benkatz | 14:80ce59119d93 | 64 | |
benkatz | 14:80ce59119d93 | 65 | }; |
benkatz | 20:bf9ea5125d52 | 66 | |
benkatz | 0:4e1c4df6aabd | 67 | #endif |