a dc_motor drive lib use two PWM IO to drive the dc_motor
Dependents: Nucleo_F411RE_OS_Robot_Tank
Revision 1:d31307e787fd, committed 2018-06-19
- Comitter:
- adaphoto
- Date:
- Tue Jun 19 12:24:42 2018 +0000
- Parent:
- 0:cd71771d494f
- Commit message:
- ??????
Changed in this revision
motodriver.cpp | Show annotated file Show diff for this revision Revisions of this file |
motodriver.h | Show annotated file Show diff for this revision Revisions of this file |
diff -r cd71771d494f -r d31307e787fd motodriver.cpp --- a/motodriver.cpp Tue Jun 19 08:50:21 2018 +0000 +++ b/motodriver.cpp Tue Jun 19 12:24:42 2018 +0000 @@ -9,11 +9,11 @@ void Motor::init() { // Set initial condition of PWM - _pwm1.period(0.001); + _pwm1.period(0.001); //初始化PWM的周期,参数的单位是s,0.001s=1ms,所以PWM周期是1KHz _pwm1 = 0; // Set initial condition of PWM - _pwm2.period(0.001); + _pwm2.period(0.001); //初始化PWM的周期,参数的单位是s,0.001s=1ms,所以PWM周期是1KHz _pwm2 = 0; }
diff -r cd71771d494f -r d31307e787fd motodriver.h --- a/motodriver.h Tue Jun 19 08:50:21 2018 +0000 +++ b/motodriver.h Tue Jun 19 12:24:42 2018 +0000 @@ -6,15 +6,17 @@ public: Motor(PinName pwm1pin, PinName pwm2pin); + // 电机的开环控制函数,speed直接赋予PWM占空比,所以取值范围在0.0-1.0之间 float Speed(float speed); + // 关闭电机控制函数 void Stop(); private: PwmOut _pwm1; PwmOut _pwm2; - /** Initialization. */ + // 初始化函数 void init(); };