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.
Diff: Motor_3/Motor_3.cpp
- Revision:
- 0:5d1c1999d61d
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Motor_3/Motor_3.cpp Mon May 07 06:58:54 2018 +0000
@@ -0,0 +1,60 @@
+#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);
+ }
+
+}