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.
motor.h
00001 #ifndef __MOTOR_H 00002 #define __MOTOR_H 00003 00004 #include "mbed.h" 00005 //#define ALARM 00006 #define MOTOR_SIDE 1 00007 #define NON_MOTOR_SIDE 0 00008 #define CD_2D34M__TxCM_S 625.0 00009 #define CD_2D24MB__TxCM_S 125.0 00010 #define CD_2D34M__CW 1 00011 #define CD_2D24MB__CW 0 00012 00013 class Motor 00014 { 00015 public: 00016 Motor(PinName p, PinName d, PinName e, char* n, float Tcs, int cw/*, InterruptIn *c, InterruptIn *cc*/); 00017 // p_us = signal period in micro_seconds 00018 // dc = signal duty-cycle (0.0 to 1.0) 00019 void pwm_io(int p_us, float dc); // not used... 00020 void go(int direction); 00021 void setSpeed(float cm_s); 00022 float speed() { 00023 return (float)_TXcm_s/(_onDelay+_offDelay); 00024 } 00025 void reset() { 00026 if(_lock){ 00027 return; 00028 } 00029 _pos=0; 00030 } 00031 void to(float p); 00032 float position() { 00033 if(_lock){ 00034 return -1; 00035 } 00036 return _pos; 00037 } 00038 bool moving(){ return _lock; } 00039 void setPosition(float p) { 00040 if(_lock){ 00041 return; 00042 } 00043 _pos = p; 00044 } 00045 void stop(void); 00046 protected: 00047 void toggleOn(void); 00048 void toggleOff(void); 00049 void rotateCallBack(void); 00050 Timeout _pulseTimeout, _rotateTimeout; 00051 DigitalOut _pulse, _dir, _error; 00052 int _onDelay; 00053 int _offDelay; 00054 float _TXcm_s; 00055 char* _name; 00056 float _pos, _goal; 00057 int _cw,_ccw; 00058 bool _lock; 00059 // InterruptIn *_clockStop, *_counterClockStop; 00060 }; 00061 00062 class CD_2D34M: public Motor 00063 { 00064 public: 00065 CD_2D34M(char* n, PinName d, PinName p, PinName a, PinName e); 00066 private: 00067 void alarm_event(); 00068 void alarm_reset(); 00069 InterruptIn alarm; 00070 }; 00071 00072 class CD_2D24MB: public Motor 00073 { 00074 public: 00075 CD_2D24MB(char* n, PinName p, PinName d, PinName e); 00076 00077 }; 00078 00079 #endif // __MOTOR_H
Generated on Tue Jul 12 2022 17:26:53 by
1.7.2