pot controller voor positie, kp handmatig instellen, werkt met motor 1 en 2

Dependencies:   MODSERIAL QEI mbed-dsp mbed

Fork of PI_controller_verbeteringen by ProjectGroep23

Revision:
5:f07bafaf11d7
Parent:
4:651d06e860e7
Child:
6:1ee8795b7578
--- a/main.cpp	Wed Sep 12 12:18:25 2018 +0000
+++ b/main.cpp	Mon Sep 24 14:15:12 2018 +0000
@@ -7,120 +7,15 @@
 DigitalOut ledg(LED_GREEN);
 DigitalOut ledb(LED_BLUE);
 
+PwmOut  pwmpin(PTA2);
+DigitalOut direct(PTB23);
+AnalogIn enc1(A0);
+
 InterruptIn  sw2(SW2);
 InterruptIn  sw3(SW3);
 
 MODSERIAL pc(USBTX, USBRX);
 
-volatile char c;
-volatile char  color;
-
-void Buttonpress()
-{    
-    if (c == 'r')
-    {
-        color = 'r';
-    }
-    else if (c == 'g')
-    {
-        color = 'g';        
-    }
-    else if (c == 'b')
-    {
-        color = 'b';
-    }
-    else if (c == NULL)
-    {
-        ledr = 1;
-        ledg = 1;
-        ledb = 1;
-    }
-    else
-    {
-        pc.printf("Character %c is not valid \r\n",c);
-        c = color;
-        
-        ledr = 0;
-        ledg = 0;
-        ledb = 0;
-        wait(0.1f);
-        ledr = 1;
-        ledg = 1;
-        ledb = 1;
-        wait(0.1f);
-        ledr = 0;
-        ledg = 0;
-        ledb = 0;
-        wait(0.1f);
-        ledr = 1;
-        ledg = 1;
-        ledb = 1;
-        wait(0.1f);
-        ledr = 0;
-        ledg = 0;
-        ledb = 0;
-        wait(0.1f);
-        ledr = 1;
-        ledg = 1;
-        ledb = 1;
-        wait(0.1f);        
-    }     
-    
-    if (color == 'r')
-    {
-        ledr = !ledr;
-        ledg = 1;
-        ledb = 1;
-    }
-    else if (color == 'g')
-    {
-        ledr = 1;
-        ledg = !ledg;
-        ledb = 1;
-    }
-    else if (color == 'b')
-    {
-        ledr = 1;
-        ledg = 1;
-        ledb = !ledb;
-    }
-    
-    wait(0.25f);
-    ledr = 1;
-    ledg = 1;
-    ledb = 1;
-       
-}
-
-void CurrentColor()
-{
-    if (color == 'r')
-    {
-        pc.printf("The current blinking color is: red. \r\n");
-    }
-    else if (color == 'g')
-    {
-        pc.printf("The current blinking color is: green. \r\n");
-    }
-    else if (color == 'b')
-    {
-        pc.printf("The current blinking color is: blue. \r\n");
-    }
-    else
-    {
-        pc.printf("The LED is currently not blinking.\r\n");
-    }
-}
-
-void LEDOFF()
-{
-    color = NULL;
-    c = NULL;
-    
-    ledr = 1;
-    ledg = 1;
-    ledb = 1;
-}
 
 int main()
 {
@@ -130,18 +25,16 @@
     
     pc.printf("\r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n ~~~A$$De$troyer69~~~ \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n");
     
-    pc.baud(115200);
-    Blinker.attach(Buttonpress, 0.5);
-    sw2.fall(CurrentColor);
-    sw3.rise(LEDOFF);
-    
-    
+    pwmpin.period_us(60);
+    pwmpin = 0;
+  
     while (true)
     {
-        c = pc.getc();
-        
+            pwmpin.write(enc1.read());
+            direct = 1;
+            pc.printf("%f \r\n", enc1.read());
+            wait(0.2f);
     }
-    
 }