DRV8323RS Version

Dependencies:   mbed-dev-f303 FastPWM3

Committer:
benkatz
Date:
Wed Jul 17 03:40:12 2019 +0000
Revision:
51:6cd89bd6fcaa
Parent:
47:e1196a851f76
adding field-weakening to the user menu, switch "torque limit" to "current limit"

Who changed what in which revision?

UserRevisionLine numberNew 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 22:60276ba87ac6 38 int _CPR, flag, rotations, _ppairs, raw;
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 22:60276ba87ac6 61 int raw, _CPR, rotations, old_counts, _ppairs;
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 0:4e1c4df6aabd 69 #endif