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.
MotorControler.h
00001 #ifndef MOTORCONTROLER_H 00002 #define MOTORCONTROLER_H 00003 #include "mbed.h" 00004 00005 #define FLIP_MOTOR_DIR 0 00006 00007 typedef enum{ 00008 CW = 0, 00009 CCW = 1, 00010 }MotorDirection; 00011 00012 typedef enum{ 00013 SM = 0, 00014 LAP = 1, 00015 }ControlType; 00016 00017 class MotorControler 00018 { 00019 public: 00020 MotorControler(PinName DIR, PinName PWM, PinName nSLP, ControlType control_type=SM); 00021 float operator = (float speed); 00022 float operator + (float speed); 00023 float operator += (float speed); 00024 float operator - (float speed); 00025 float operator -= (float speed); 00026 float operator * (float val); 00027 float operator *= (float val); 00028 float operator / (float val); 00029 float operator /= (float val); 00030 00031 virtual void enableDriver(){} 00032 virtual void disableDriver(){} 00033 00034 // speed(-1.0 - 1.0) 00035 void setSpeed(float speed); 00036 00037 // dir(CW, or CCW) 00038 void setMotorDirection(MotorDirection dir); 00039 void setPinUsingSignMagnitude(int8_t dir, float speed); 00040 void setPinusingLockedUntiPhase(int8_t dir, float speed); 00041 00042 // set PWM frequency 00043 // frequency[Hz] 00044 void setPwmFrequency(float frequency); 00045 00046 protected: 00047 // if you want use LAP control, change DigitalOut -> PwmOut DIR_ 00048 DigitalOut DIR_; 00049 PwmOut PWM_; 00050 DigitalOut nSLP_; 00051 uint8_t reverse_direction_; 00052 ControlType control_type_; 00053 float current_speed_; 00054 }; 00055 00056 class POLOLUControler : public MotorControler 00057 { 00058 public: 00059 POLOLUControler(PinName DIR, PinName PWM, PinName nSLP, ControlType control_type=SM) : MotorControler(DIR, PWM, nSLP, control_type) 00060 { 00061 } 00062 00063 virtual void enableDriver() 00064 { 00065 nSLP_ = 1; 00066 } 00067 00068 virtual void disableDriver() 00069 { 00070 nSLP_ = 0; 00071 } 00072 00073 using MotorControler::operator=; 00074 using MotorControler::operator+; 00075 using MotorControler::operator+=; 00076 using MotorControler::operator-; 00077 using MotorControler::operator-=; 00078 using MotorControler::operator*; 00079 using MotorControler::operator*=; 00080 using MotorControler::operator/; 00081 using MotorControler::operator/=; 00082 }; 00083 00084 00085 class TEXNITISControler : public MotorControler 00086 { 00087 public: 00088 TEXNITISControler(PinName DIR, PinName PWM, PinName nSLP, ControlType control_type=SM) : MotorControler(DIR, PWM, nSLP, control_type) 00089 { 00090 nSLP_ = 1; 00091 } 00092 00093 virtual void enableDriver() 00094 { 00095 // do nothing; 00096 } 00097 00098 virtual void disableDriver() 00099 { 00100 PWM_ = 0; 00101 } 00102 00103 using MotorControler::operator=; 00104 using MotorControler::operator+; 00105 using MotorControler::operator+=; 00106 using MotorControler::operator-; 00107 using MotorControler::operator-=; 00108 using MotorControler::operator*; 00109 using MotorControler::operator*=; 00110 using MotorControler::operator/; 00111 using MotorControler::operator/=; 00112 }; 00113 00114 00115 #endif
Generated on Fri Jul 15 2022 04:43:50 by
1.7.2