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_3/Motor_3.cpp
- Committer:
- himarsmty
- Date:
- 2018-05-07
- Revision:
- 0:5d1c1999d61d
File content as of revision 0:5d1c1999d61d:
#include "Motor_3.h" #include "mbed.h" #define HIGH 1 #define LOW 0 extern Serial pc; Motor_3::Motor_3(PinName dia1,PinName dia2,PinName pwa): _dia1(dia1),_dia2(dia2),_pwa(pwa),_pwmout(0) { //init DigitalOut pda1(_dia1,LOW); DigitalOut pda2(_dia2,LOW); } void Motor_3::mv(double speed) { // speed=speed/100*20/1000; // pc.printf("speed=%lf\n",speed); if(speed>0) { double temp_pwmout=6*pow(10.0,-10.0)*pow(speed,4.0)-4*pow(10.0,-7.0)*pow(speed,3.0)+3*pow(10.0,-5.0)*pow(speed,2.0)+0.0241*speed+0.0794;//拟合 // pc.printf("&&&temp_pwmout:%lf\n",temp_pwmout); int pwmout=(int)temp_pwmout; DigitalOut mydia1(_dia1,HIGH); DigitalOut mydia2(_dia2,LOW); // _pwmout=pwmout; _pwmout=20; PwmOut mypwa(_pwa); mypwa.period_ms(20); mypwa.pulsewidth_ms(_pwmout); } else if (speed<0) { double temp_pwmout=6*pow(10.0,-10.0)*pow(speed,4.0)-4*pow(10.0,-7.0)*pow(speed,3.0)+3*pow(10.0,-5.0)*pow(speed,2.0)+0.0241*speed+0.0794;//拟合 // pc.printf("temp_pwmout:%lf\n",temp_pwmout); int pwmout=(int)temp_pwmout; speed=abs(speed); DigitalOut mydia1(_dia1,LOW); DigitalOut mydia2(_dia2,HIGH); // _pwmout=pwmout; _pwmout=10; pc.printf("%d\n",_pwmout); PwmOut mypwa(_pwa); mypwa.period_ms(20); mypwa.pulsewidth_ms(_pwmout); } else { speed=abs(speed); DigitalOut mydia1(_dia1,LOW); DigitalOut mydia2(_dia2,LOW); _pwmout=0.0; PwmOut mypwa(_pwa); mypwa.period_ms(20); mypwa.pulsewidth(_pwmout); } }