Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: CANnucleo FastPWM3 mbed
Fork of Hobbyking_Cheetah_Compact by
PositionSensor.h
00001 #ifndef POSITIONSENSOR_H 00002 #define POSITIONSENSOR_H 00003 class PositionSensor { 00004 public: 00005 virtual float GetMechPosition() {return 0.0f;} 00006 virtual float GetElecPosition() {return 0.0f;} 00007 virtual float GetMechVelocity() {return 0.0f;} 00008 virtual float GetElecVelocity() {return 0.0f;} 00009 }; 00010 00011 00012 class PositionSensorEncoder: public PositionSensor { 00013 public: 00014 PositionSensorEncoder(int CPR, float offset, int ppairs); 00015 virtual void Sample(); 00016 virtual float GetMechPosition(); 00017 virtual float GetElecPosition(); 00018 virtual float GetMechVelocity(); 00019 virtual float GetElecVelocity(); 00020 private: 00021 InterruptIn *ZPulse; 00022 DigitalIn *ZSense; 00023 //DigitalOut *ZTest; 00024 virtual void ZeroEncoderCount(void); 00025 virtual void ZeroEncoderCountDown(void); 00026 int _CPR, flag, rotations, _ppairs; 00027 //int state; 00028 float _offset, MechPosition, MechOffset, dir, test_pos, oldVel, out_old, velVec[16]; 00029 }; 00030 00031 class PositionSensorMA700: public PositionSensor{ 00032 public: 00033 PositionSensorMA700(int CPR, float offset, int ppairs); 00034 virtual void Sample(); 00035 virtual float GetMechPosition(); 00036 virtual float GetElecPosition(); 00037 virtual float GetMechVelocity(); 00038 virtual int GetRawPosition(); 00039 virtual void ZeroPosition(); 00040 private: 00041 float _offset, MechPosition, MechOffset; 00042 int _CPR, rotations, old_counts, _ppairs; 00043 SPI *spi; 00044 DigitalOut *cs; 00045 }; 00046 00047 class PositionSensorAM5147: public PositionSensor{ 00048 public: 00049 PositionSensorAM5147(int CPR, float offset, int ppairs); 00050 virtual void Sample(); 00051 virtual float GetMechPosition(); 00052 virtual float GetElecPosition(); 00053 virtual float GetMechVelocity(); 00054 virtual int GetRawPosition(); 00055 virtual void ZeroPosition(); 00056 private: 00057 float position, ElecPosition, ElecOffset, MechPosition, MechOffset, modPosition, oldModPosition, oldVel, velVec[16], MechVelocity, ElecVelocity; 00058 int raw, _CPR, rotations, old_counts, _ppairs; 00059 SPI *spi; 00060 DigitalOut *cs; 00061 int readAngleCmd; 00062 00063 }; 00064 00065 #endif
Generated on Tue Aug 2 2022 05:17:53 by
