motor met p controller, aangestuurd via pc.

Dependencies:   HIDScope MODSERIAL QEI mbed

Fork of frdm_Motor by Margreeth de Breij

Files at this revision

API Documentation at this revision

Comitter:
Rvs94
Date:
Mon Sep 28 13:43:14 2015 +0000
Parent:
3:687729d7996e
Commit message:
p_control werkt, afwijkingen en overshoot is nog groot. Volgende stap is PI.

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 687729d7996e -r 0d4aff8b57b3 main.cpp
--- a/main.cpp	Mon Sep 28 13:25:19 2015 +0000
+++ b/main.cpp	Mon Sep 28 13:43:14 2015 +0000
@@ -17,7 +17,7 @@
 float Aantal_pulses;
 float Error;
 float refference;
-const float Kp = 0.01;
+const float Kp = 0.005;
 
 
 void ScopeSend()//Functie die de gegevens voor de scope uitleest en doorstuurt
@@ -26,7 +26,7 @@
     scope.set(1, motor2speed.read());
     scope.set(2, Aantal_Degs);
     Aantal_Degs = Encoder.getPulses()*360/31/131;
-    Error = refference - Aantal_Degs;
+
     scope.send();
     
 }
@@ -45,28 +45,32 @@
     
     while (true) 
     {
+        
         char c = pc.getc();   
         if(c == 'r')
         {
             refference = refference + 10;
             pc.printf("rx \n");
+            Error = refference - Aantal_Degs;
+            while(abs(Error) > 2)
+                {
+                    Error = refference - Aantal_Degs;
+                    motor2speed = Kp*abs(Error);
+                    pc.printf("reffence = %f,error = %f \n",refference,Error);
+                    if(Error > 0)
+                    {
+                        motor2direction = 0;
+                    }
+                    else
+                    {
+                    motor2direction = 1;
+                    }
+
+                }
         }
-        if(c=='f')
-        {
-            refference = refference - 10;
-            pc.printf("fx \n");
-        }
+
         
-        if(Error > 0)
-        {
-            motor2direction = 0;
-        }
-        else
-        {
-            motor2direction = 1;
-        }
-        motor2speed = Kp*abs(Error);
-        pc.printf("reffence = %f,error = %f \n",refference,Error);
+
 
     }
 }
\ No newline at end of file