Robot tryout

Dependencies:   mbed QEI biquadFilter MODSERIAL FastPWM ttmath Math

Revision:
12:2382468d36a4
Parent:
9:61bdf58f856e
Child:
13:18dd7a15603f
--- a/Motor_tryout.cpp	Thu Oct 03 14:43:45 2019 +0000
+++ b/Motor_tryout.cpp	Sat Oct 05 12:27:51 2019 +0000
@@ -1,23 +1,34 @@
 #include "mbed.h" 
 #include "MODSERIAL.h"
+#include "QEI.h"
 
-// test, hallo
-
+// ALLE INPUT EN OUTPUT SIGNALEN
 DigitalOut motor1_pwm(PTC2);    // aansturen motor 1, via poort PTC2
+DigitalOut motor1_dir(PTC3);    // richting motor 1
+DigitalOut motor2_pwm(PTA2);    // aansturen motor 2, via poort PTA2
+DigitalOut motor2_dir(PTB23);   // richting motor 2
 DigitalIn motor1_1(PTD1);       // data vanuit motor 1
 DigitalIn motor1_2(PTD3);       // data vanuit motor 1
-
-
-DigitalOut motor2_pwm(PTA2);    // aansturen motor 2, via poort PTA2
 AnalogIn input(PTB3);           // input van ECG
 MODSERIAL pc(USBTX, USBRX);
+QEI Encoder(D12,D13,NC,64,QEI::X4_ENCODING);
 
+// DE TICKERS, deze ticker
+Ticker pulse;
+int counts;
+void pulseget()
+    {
+    counts = Encoder.getPulses();
+    }
+
+// DE MAIN FUNCTIE
 int main(void)
     {   
     pc.baud(115200);
-    char c = pc.getc();
+    char cc = pc.getc();
     pc.printf("In de main, check\r\n");
-    if (c == 'm')
+    pc.putc(cc);
+    if (cc == 'm' or cc == 'm')
         {
         pc.printf("In de if, check\r\n");
         pc.baud(115200);
@@ -29,27 +40,24 @@
         while(true)
             {   
             pc.printf("In de while, check\r\n");
-            int DataM[1000];
-            for(int pct = 0 ; pct <= 100 ; pct += 10)
+            
+            // MOTOR 1 START
+            int limit = 20000;
+                for(int pct = 55 ; pct <= 70 ; pct ++)
                 {
-                pc.printf("Motor 1\r\n");
                 motor1_pwm.write(pct/100.0); // write Duty Cycle
+                pulse.attach(pulseget,1.0/100);
+                pc.printf("Motor 1 speed %i and the count is %i\r\n", pct, counts);
                 wait(1.0f);
-                //for(int tijd = 0 ; pct <= 100 ; pct += 1)
-                //    {
-                //       int tijd2 = tijd + pct/10*10;
-                //        int Outm1 = motor1_1.read();
-                //        DataM[tijd2] = Outm1;
-                //        wait(0.1f);
-                //        }
-                      }
-            for (int pr = 0 ; pr <= 100; pr += 1);
-            {
-                int value = DataM[pr];
-                pc.printf("Data motor 1 is %i", value);
+                if(counts > limit)
+                    {
+                    break;
+                    }
                 }
             motor1_pwm.write(0.0f); // motor 1 off again
             pc.printf("Motor 1 off\r\n");
+            
+            // MOTOR TWEE START
             for(int pct = 0 ; pct <= 100 ; pct += 10)
                 {
                 pc.printf("Motor 2\r\n");
@@ -60,14 +68,4 @@
             pc.printf("Motor 2 off\r\n");
             }
         }
-    if (c == 'e')
-    {
-        pc.printf("In de tweede if, check");
-        while (true)
-        {
-            int sample = input.read();
-            pc.printf("Input is %i \r\n", sample);
-            wait(1.0f);
-        }  
-    }
-}
\ No newline at end of file
+    }
\ No newline at end of file