Modified Motor Driver Firmware to include Flash + Thermal
Dependencies: FastPWM3 mbed-dev-STM-lean
PositionSensor/PositionSensor.h@78:4f481ff040ee, 21 months ago (annotated)
- Committer:
- adimmit
- Date:
- Fri Nov 11 16:58:43 2022 +0000
- Revision:
- 78:4f481ff040ee
- Parent:
- 58:32e8927fe39f
changes w/ filter @ high speed;
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 | 47:e1196a851f76 | 5 | virtual void Sample(float dt) = 0; |
benkatz | 0:4e1c4df6aabd | 6 | virtual float GetMechPosition() {return 0.0f;} |
benkatz | 38:67e4e1453a4b | 7 | virtual float GetMechPositionFixed() {return 0.0f;} |
benkatz | 0:4e1c4df6aabd | 8 | virtual float GetElecPosition() {return 0.0f;} |
benkatz | 9:d7eb815cb057 | 9 | virtual float GetMechVelocity() {return 0.0f;} |
benkatz | 13:a3fa0a31b114 | 10 | virtual float GetElecVelocity() {return 0.0f;} |
benkatz | 22:60276ba87ac6 | 11 | virtual void ZeroPosition(void) = 0; |
benkatz | 22:60276ba87ac6 | 12 | virtual int GetRawPosition(void) = 0; |
benkatz | 22:60276ba87ac6 | 13 | virtual void SetElecOffset(float offset) = 0; |
benkatz | 22:60276ba87ac6 | 14 | virtual int GetCPR(void) = 0; |
benkatz | 22:60276ba87ac6 | 15 | virtual void WriteLUT(int new_lut[128]) = 0; |
benkatz | 0:4e1c4df6aabd | 16 | }; |
benkatz | 0:4e1c4df6aabd | 17 | |
benkatz | 0:4e1c4df6aabd | 18 | |
benkatz | 0:4e1c4df6aabd | 19 | class PositionSensorEncoder: public PositionSensor { |
benkatz | 0:4e1c4df6aabd | 20 | public: |
benkatz | 10:370851e6e132 | 21 | PositionSensorEncoder(int CPR, float offset, int ppairs); |
benkatz | 47:e1196a851f76 | 22 | virtual void Sample(float dt); |
benkatz | 0:4e1c4df6aabd | 23 | virtual float GetMechPosition(); |
benkatz | 0:4e1c4df6aabd | 24 | virtual float GetElecPosition(); |
benkatz | 3:6a0015d88d06 | 25 | virtual float GetMechVelocity(); |
benkatz | 3:6a0015d88d06 | 26 | virtual float GetElecVelocity(); |
benkatz | 22:60276ba87ac6 | 27 | virtual void ZeroPosition(void); |
benkatz | 22:60276ba87ac6 | 28 | virtual void SetElecOffset(float offset); |
benkatz | 22:60276ba87ac6 | 29 | virtual int GetRawPosition(void); |
benkatz | 22:60276ba87ac6 | 30 | virtual int GetCPR(void); |
benkatz | 22:60276ba87ac6 | 31 | virtual void WriteLUT(int new_lut[128]); |
benkatz | 0:4e1c4df6aabd | 32 | private: |
benkatz | 0:4e1c4df6aabd | 33 | InterruptIn *ZPulse; |
benkatz | 0:4e1c4df6aabd | 34 | DigitalIn *ZSense; |
benkatz | 1:b8bceb4daed5 | 35 | //DigitalOut *ZTest; |
benkatz | 0:4e1c4df6aabd | 36 | virtual void ZeroEncoderCount(void); |
benkatz | 7:dc5f27756e02 | 37 | virtual void ZeroEncoderCountDown(void); |
benkatz | 56:fe5056ac6740 | 38 | int _CPR, flag, rotations, _ppairs, raw, first_sample; |
benkatz | 1:b8bceb4daed5 | 39 | //int state; |
benkatz | 35:69b24894c11d | 40 | float _offset, MechPosition, MechOffset, dir, test_pos, oldVel, out_old, velVec[40]; |
benkatz | 22:60276ba87ac6 | 41 | int offset_lut[128]; |
benkatz | 8:10ae7bc88d6e | 42 | }; |
benkatz | 14:80ce59119d93 | 43 | |
benkatz | 14:80ce59119d93 | 44 | class PositionSensorAM5147: public PositionSensor{ |
benkatz | 14:80ce59119d93 | 45 | public: |
benkatz | 14:80ce59119d93 | 46 | PositionSensorAM5147(int CPR, float offset, int ppairs); |
benkatz | 47:e1196a851f76 | 47 | virtual void Sample(float dt); |
benkatz | 14:80ce59119d93 | 48 | virtual float GetMechPosition(); |
benkatz | 38:67e4e1453a4b | 49 | virtual float GetMechPositionFixed(); |
benkatz | 14:80ce59119d93 | 50 | virtual float GetElecPosition(); |
benkatz | 14:80ce59119d93 | 51 | virtual float GetMechVelocity(); |
benkatz | 37:c0f352d6e8e3 | 52 | virtual float GetElecVelocity(); |
benkatz | 14:80ce59119d93 | 53 | virtual int GetRawPosition(); |
benkatz | 14:80ce59119d93 | 54 | virtual void ZeroPosition(); |
benkatz | 22:60276ba87ac6 | 55 | virtual void SetElecOffset(float offset); |
benkatz | 37:c0f352d6e8e3 | 56 | virtual void SetMechOffset(float offset); |
benkatz | 22:60276ba87ac6 | 57 | virtual int GetCPR(void); |
benkatz | 22:60276ba87ac6 | 58 | virtual void WriteLUT(int new_lut[128]); |
benkatz | 14:80ce59119d93 | 59 | private: |
benkatz | 35:69b24894c11d | 60 | float position, ElecPosition, ElecOffset, MechPosition, MechOffset, modPosition, oldModPosition, oldVel, velVec[40], MechVelocity, ElecVelocity, ElecVelocityFilt; |
benkatz | 56:fe5056ac6740 | 61 | int raw, _CPR, rotations, old_counts, _ppairs, first_sample; |
benkatz | 14:80ce59119d93 | 62 | SPI *spi; |
benkatz | 14:80ce59119d93 | 63 | DigitalOut *cs; |
benkatz | 14:80ce59119d93 | 64 | int readAngleCmd; |
benkatz | 22:60276ba87ac6 | 65 | int offset_lut[128]; |
benkatz | 14:80ce59119d93 | 66 | |
benkatz | 14:80ce59119d93 | 67 | }; |
benkatz | 20:bf9ea5125d52 | 68 | |
benkatz | 57:0795d2add37e | 69 | |
benkatz | 57:0795d2add37e | 70 | |
benkatz | 57:0795d2add37e | 71 | class PositionSensoriCMU: public PositionSensor{ |
benkatz | 57:0795d2add37e | 72 | public: |
benkatz | 57:0795d2add37e | 73 | PositionSensoriCMU(int CPR, float offset, int ppairs); |
benkatz | 57:0795d2add37e | 74 | virtual void Sample(float dt); |
benkatz | 57:0795d2add37e | 75 | virtual float GetMechPosition(); |
benkatz | 57:0795d2add37e | 76 | virtual float GetMechPositionFixed(); |
benkatz | 57:0795d2add37e | 77 | virtual float GetElecPosition(); |
benkatz | 57:0795d2add37e | 78 | virtual float GetMechVelocity(); |
benkatz | 57:0795d2add37e | 79 | virtual float GetElecVelocity(); |
benkatz | 57:0795d2add37e | 80 | virtual int GetRawPosition(); |
benkatz | 57:0795d2add37e | 81 | virtual void ZeroPosition(); |
benkatz | 57:0795d2add37e | 82 | virtual void SetElecOffset(float offset); |
benkatz | 57:0795d2add37e | 83 | virtual void SetMechOffset(float offset); |
benkatz | 57:0795d2add37e | 84 | virtual int GetCPR(void); |
benkatz | 57:0795d2add37e | 85 | virtual void WriteLUT(int new_lut[128]); |
benkatz | 57:0795d2add37e | 86 | private: |
benkatz | 57:0795d2add37e | 87 | float position, ElecPosition, ElecOffset, MechPosition, MechOffset, modPosition, oldModPosition, oldVel, velVec[40], MechVelocity, ElecVelocity, ElecVelocityFilt; |
saloutos | 58:32e8927fe39f | 88 | int raw, lut_shift, _CPR, rotations, old_counts, _ppairs, first_sample, raw_bytes[8]; |
benkatz | 57:0795d2add37e | 89 | SPI *spi; |
benkatz | 57:0795d2add37e | 90 | DigitalOut *cs; |
benkatz | 57:0795d2add37e | 91 | int readAngleCmd; |
benkatz | 57:0795d2add37e | 92 | int offset_lut[128]; |
benkatz | 57:0795d2add37e | 93 | |
benkatz | 57:0795d2add37e | 94 | }; |
benkatz | 0:4e1c4df6aabd | 95 | #endif |