自動機

Dependencies:   EC mbed

Files at this revision

API Documentation at this revision

Comitter:
eri
Date:
Wed Sep 06 05:52:29 2017 +0000
Parent:
2:c8c264a9a7f6
Commit message:
???????

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Wed Sep 06 02:47:52 2017 +0000
+++ b/main.cpp	Wed Sep 06 05:52:29 2017 +0000
@@ -27,6 +27,7 @@
 double v();
 int e=0;
 int f=0;
+int k=0;
 
 
 
@@ -56,8 +57,9 @@
         //pc.printf("duty1=%f ",motor1.duty);
         //pc.printf("duty2=%f\r\n",motor2.duty);
         //pc.printf("d=%d",d);
-        //pc.printf("v=%f\r\n",v());
-        //pc.printf("ang=%d\r\n",ang);
+        pc.printf("c=%d",c);
+        pc.printf("a=%d",a);
+        pc.printf("ang=%d\r\n",ang);
         kai=0;
     }
     kai++;
@@ -79,7 +81,7 @@
     while(n==1) {
         dis=0.301*Ec1.getCount();
         if(dis < a) {
-            V=15;
+            V=10;
             e=400;
 
             if(dis > a-e) {
@@ -132,10 +134,10 @@
 {
   c=0;
   f=700;
+  k=0;
 
     while(n==2) {
         V=5;
-        
         if(b >= 0) {
 
 
@@ -147,31 +149,37 @@
                 a -= 3600;
             }
             print();
-            if(c==1 && a > 20) {
+            /*if(k>7000){
+                n=1;
+                Ec1.reset();
+                }
+            if(c==1 && a > 10) {
                 motor1.Sc(-v());
                 motor2.stop();
-            } else if(c==2 && a < -20) {
+            } else if(c==2 && a < -10) {
                 motor1.stop();
-                motor2.Sc(-v());
-            } else if(a < -f) {
+                motor2.Sc(-v());*/
+            //} else if(a < -f) {
+            if(a < -f) {
                 motor1.Sc(V);
                 motor2.stop();
             } else if(a > f) {
                 motor1.stop();
                 motor2.Sc(V);
-            } else if(a < -10) {
+            } else if(a < -20) {
                 motor1.Sc(v());
                 motor2.stop();
-                c=1;
-            } else if(a > 10) {
+              //  c=1;
+            } else if(a > 20) {
                 motor1.stop();
                 motor2.Sc(v());
-                c=2;
+              //  c=2;
             } else {
-                Ec1.reset();
                 motor1.stop();
                 motor2.stop();
+               // k+=1;
                 n=1;
+                Ec1.reset();
             }
 
         } else {
@@ -182,38 +190,41 @@
             } else if(a > 1800) {
                 a -= 3600;
             }
-
-            if(c==1 && a > 20) {
+            
+           /*if(k>7000){
+                n=1;
+                Ec1.reset();
+                }
+            if(c==1 && a > 10) {
                 motor1.stop();
                 motor2.Sc(v());
-            } else if(c==2 && a < -20) {
+            } else if(c==2 && a < -10) {
                 motor1.Sc(v());
-                motor2.stop();
-            } else if(a < -f) {
+                motor2.stop();*/
+            //} else if(a < -f) {
+            if(a < -f) {
                 motor1.stop();
                 motor2.Sc(-V);
             } else if(a > f) {
                 motor1.Sc(-V);
                 motor2.stop();
-            } else if(a < -10) {
+            } else if(a < -20) {
                 motor1.stop();
                 motor2.Sc(-v());
-                c=1;
-            } else if(a > 10) {
+                //c=1;
+            } else if(a > 20) {
                 motor1.Sc(-v());
                 motor2.stop();
-                c=2;
+                //c=2;
             } else {
-                Ec1.reset();
                 motor1.stop();
                 motor2.stop();
+                //k+=1;
                 n=1;
+                Ec1.reset();
             }
         }
     }
-    while(1){
-        print();
-        }
 }
 
 double v(){
@@ -253,13 +264,13 @@
         wait(0.5);
         d=ang;                       //初期角度
         n=2;
-        turn(3100);
-        str(950);
-        turn(2410);
-        str(1070);
+        turn(3050);
+        str(900);
+        turn(2400);
+        str(1080);
         turn(2700);
         servo.pulsewidth_us(1800);
-        str(870);
+        str(860);
         servo.pulsewidth_us(900);
         wait(1);
         back(0);
@@ -313,10 +324,10 @@
         servo.pulsewidth_us(1800);
         wait(0.5);
         d=ang - 1800;
-        str(450);
+        str(470);
         servo.pulsewidth_us(900);
         wait(1);
-        turn(880);
+        turn(860);
         str(820);
         turn(610);
         str(1080);