fsdfds

Dependencies:   mbed

Revision:
11:6bbe8da4b16a
Parent:
10:ca38e4d775c8
Child:
12:ee175985ef09
diff -r ca38e4d775c8 -r 6bbe8da4b16a main.cpp
--- a/main.cpp	Fri May 22 12:01:26 2020 +0000
+++ b/main.cpp	Fri May 22 13:27:01 2020 +0000
@@ -17,8 +17,6 @@
 
 #define DIR_LEFT 0
 #define DIR_RIGHT 1
-//попробовать поменять дир_лефт на -1
-
 
 DigitalOut RCout(D10);
 DigitalOut dir(D9);
@@ -31,7 +29,8 @@
 DigitalOut  myled(LED2);
 RawSerial rpc(D1,D0,9600);
 
-int period_us = 26;//300 26
+
+int period_us = 22;//300 26
 int posCounter = 0;
 
 long pos=0;
@@ -77,6 +76,11 @@
 bool calibrated = false;
 bool dirUpdated = false;
 
+
+DigitalOut led(LED1);
+Timeout flipper;
+
+
 typedef union {
     float number[6];
     uint8_t numberCh[24];
@@ -216,13 +220,13 @@
         pos += (dir.read() * 2 - 1);
         RCout = !RCout;
     }
+    flipper.attach_us(stepperFlip, period_us/2);    
 }
 
 
 void updatePeriod(){
-    tick.detach();
+    //tick.detach();
     tick.attach_us (&stepperFlip, period_us / 2.0f);
-    wait_ms(20);
 }
 
 void leftEnd() {
@@ -289,10 +293,6 @@
 int dirCounter = 0;
 int perCounter = 0;
 
-void changeDir(int direction)
-{
-        dir = direction;
-}
 
 void Rx_interrupt() {
     int command = rpc.getc();
@@ -305,35 +305,25 @@
             speedTicker.attach(calcSpeed, 1);
             break;
         case 65:
-            if (dirCounter == 10) {
-                dirCounter = 0; 
-                int direction = rpc.getc();
-                if (direction <= 0) {
-                    if (dir != DIR_RIGHT) {
-                    changeDir(DIR_RIGHT);
-                    }
-                } else if (direction > 0) {
-                    if (dir != DIR_LEFT) {
-                        changeDir(DIR_LEFT);    
-                    }
+            int direction = rpc.getc();
+            if (direction <= 0) {
+                if (dir != DIR_RIGHT) {
+                    dir = DIR_RIGHT;
                 }
-            } else {
-                dirCounter += 1;
+            } else if (direction > 0) {
+                if (dir != DIR_LEFT) {
+                    dir = DIR_LEFT;    
+                }
             }
             break;
         case 70:
-            if (perCounter == 40) {
-                perCounter = 0;
-                int newPeriod = rpc.getc();
-                if (newPeriod < 26) {
-                    tick.detach();
-                } else if (period_us != newPeriod) {
-                    period_us = newPeriod;
-                    periodUpdated = true;
-                }
-            } else {
-                perCounter += 1;
-            }
+            /*int newPeriod = rpc.getc();
+            if (newPeriod < 22) {
+                flipper.detach();
+            } else if (period_us != newPeriod) {
+                period_us = newPeriod;
+                periodUpdated = true;
+            }*/
             break;
         default:
             break;
@@ -341,6 +331,11 @@
     return;
 }
 
+/*void flipLed()
+{
+    flipper.attach_us(stepperFlip, period_us);    
+}*/
+
 int main() {
     RCout = 1;
     wait_ms(500);
@@ -358,20 +353,22 @@
     calibrated = true;
     //wait(12);
     wait(7);
-    updatePeriod();
+    //updatePeriod();
     calcControl();
     state=STATE_GOTO_START;
     dir=DIR_LEFT;
+    flipper.attach_us(stepperFlip, period_us/2);
     while(1) {
         getAngularSpeed();
         if (canSend) {
             sendData();
         }
-        /*if (periodUpdated) {
+        if (periodUpdated) {
             calcControl();
-            updatePeriod();
+           // updatePeriod();
+            //flipper.attach_us(stepperFlip, period_us/2);
             periodUpdated = false;
-        }*/
+        }
         switch(state) {
             case STATE_WAITING:
                 //state = STATE_GOTO_SWING;