dfd

Dependencies:   stepper mbed

Fork of puma_test by Keegan Hu

Files at this revision

API Documentation at this revision

Comitter:
glintligo
Date:
Fri May 11 10:42:09 2018 +0000
Parent:
2:ecf401a37aa3
Commit message:
???

Changed in this revision

Stepper_motor.cpp Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r ecf401a37aa3 -r 09f6061e6e5d Stepper_motor.cpp
--- a/Stepper_motor.cpp	Fri May 11 10:25:12 2018 +0000
+++ b/Stepper_motor.cpp	Fri May 11 10:42:09 2018 +0000
@@ -52,7 +52,7 @@
         dir = pos_dir;
     }
     long long int remain = rec * ratio * microstep / Ori_rec;
-    Info.printf("remain:%d frequency:%d\n",remain, frequency);
+   // Info.printf("remain:%d frequency:%d\n",remain, frequency);
     this->enable();
     this->step(dir,frequency,remain);
     
diff -r ecf401a37aa3 -r 09f6061e6e5d main.cpp
--- a/main.cpp	Fri May 11 10:25:12 2018 +0000
+++ b/main.cpp	Fri May 11 10:42:09 2018 +0000
@@ -3,36 +3,60 @@
 #include "robo.h"
 Serial Info(PB_10,PB_11);
 Ticker t1;
+void serial_ticker();//蓝牙串口中断函数
+// puma black
 /*Stepper_motor s1(PB_9,PB_0,PB_7,PA_11,10,16,1);
 Stepper_motor s2(PB_6,PA_7,PB_4,PA_15,10,16,1);
 Stepper_motor s3(PB_3,PA_6,PA_12,PB_1,10,16,1);
 */
 //                en  step  dir button 减速比 细分数 初始方向
-Stepper_motor s1(PA_6,PC_5,PC_4,PB_14,10,16,0);//x
+Stepper_motor s1(PA_6,PC_5,PC_4,PB_14,10,16,0);//x  puma white
 Stepper_motor s2(PA_2,PA_5,PA_4,PC_6,10,16,1);//y
 Stepper_motor s3(PC_13,PC_3,PC_2,PB_15,10,16,0);//z
-PwmOut pwm2(PA_1);
-DigitalOut button(PA_0);
+//PwmOut pwm2(PA_1);
+//DigitalOut button(PA_0);
 
+float moterXdeg, moterYdeg, moterZdeg;
 int main()
-{
-    pwm2.period_ms(1);
-    pwm2.pulsewidth_us(500);
-    /*s1.Init();
-    wait(5);
-    s2.Init();
-    wait(5);
-    s3.Init();//电机初始化
-    wait(5);
-    s3.Config(5,-90);
-    */
+{ 
+    {//初始化
+        Info.attach(&serial_ticker);
+        s1.Init();
+        wait(5);
+        s2.Init();
+        wait(5);
+        s3.Init();
+        wait(5);
+    }
+    
+    {//计算电机角度
+     moterXdeg = 1;
+     moterYdeg = 2;
+     moterZdeg = 3; 
+     //Info.printf("moterXdeg:%f moterYdeg:%f moterZdeg:%f\n",moterXdeg, moterYdeg,moterZdeg);  
+    }
+    
+    {   //运动
+        /*若转动的角度为-1 则会一直转,此时rec_rate需大于0
+         * 除此之外,若转动角度或转速小于0,则电机反转
+         * 如在电机尚未停止前再次调用该函数,则会立刻开始新的电机运动
+         */
+        s1.Config(5,moterXdeg);
+        //wait(5);
+        //如果运动出现bug,可将上方注释去掉
+        s2.Config(5,moterYdeg);
+        //wait(5);
+        s3.Config(5,moterZdeg);
+        //wait(5);
+        }
     while(1)
     {
    
-    button = 0;
-    wait(5);
-    button = 1;
-    //pwm2.pulsewidth_us(1000);
-    wait(5);
-        }
+ 
+    }
 }
+
+void serial_ticker()
+{
+    
+}
\ No newline at end of file