Controller futhers (PI)

Dependencies:   QEI mbed

Revision:
1:71617831bc4e
Parent:
0:2b481a8db14f
Child:
2:22f0ce494b16
--- a/main.cpp	Thu Oct 08 11:35:49 2015 +0000
+++ b/main.cpp	Thu Oct 08 12:17:09 2015 +0000
@@ -10,18 +10,19 @@
 
 // define ticker
 Ticker aansturen;
+Ticker Printen;
 
 // define rotation direction
 const int cw = 1;
 const int ccw = 0;
 
 // Controller gain proportional
-const double motor1_Kp = 2.5;
+const double motor1_Kp = 5; // more or les random number.
 
 // calculating pulses to rotations in degree.
-const double Offset = 10341 ;//8400 counts is aangegeven op de motor ( is te weinig) 10511 schiet iets over
+const double Offset = 8400 ;//8400 counts is aangegeven op de motor ( is te weinig) 10511 schiet iets over
 const double resolution = Offset / 360;
-double Rotation = 4; // rotation in degree
+double Rotation = 1; // rotation in degree
 double movement = Rotation * 360 * resolution; // times 360 to make Rotations degree.
 
 
@@ -44,12 +45,17 @@
 
     double output = P( error, motor1_Kp );
 
+
+
     if(error > 0) {
         directionPin.write(cw);
         PWM.write(output);
-    } else {
+        //pc.printf("ref %.0f count%.0f cw\n",movement,position);
+         
+    } if(error < 0) {
         directionPin.write(ccw);
-        PWM.write(output);
+        PWM.write(-output); //min output to get output possitif
+        //pc.printf("a");
     }
 
 
@@ -57,10 +63,18 @@
 }
 
 
+void counts_showing()
+{ 
+
+ double kijken = wheel.getPulses();
+pc.printf("ref %.0f count%.0f\n",movement,kijken);
+    
+    }
 
 int main()
 {
     aansturen.attach( &motor1_Controller, 0.01f ); // 100 Hz
+    Printen.attach(&counts_showing,0.1f); // 10 Hz // printstatement here because printing cost to much time. the motor void wouldn't be completed
     while( 1 ) { }
 }