robot

Dependencies:   Encoder HIDScope MODSERIAL TouchButton mbed-dsp mbed

Fork of Robot2false by BMT M9 Groep01

Revision:
9:ba7f541cef3a
Parent:
8:7bf274156e1f
Child:
10:22047a8e634a
Child:
11:d1260f8e5300
--- a/main.cpp	Thu Oct 30 15:18:06 2014 +0000
+++ b/main.cpp	Thu Oct 30 16:24:22 2014 +0000
@@ -395,18 +395,18 @@
 }//end int main
 
 
-float pid(float setspeed, float measurement, bool reset)
+float pid(float setspeed, float measurement, bool reset )
 {
     float error;
     static float prev_error = 0;
     float           out_p = 0;
     static float    out_i = 0;
     float           out_d = 0;
-    if(reset)
-    {
-        out_i = 0;
-        prev_error = 0;
-    }
+    //if(reset==true)
+    //{
+    //    out_i = 0;
+    //    prev_error = 0;
+    //}
     error  = setspeed-measurement;
     out_p  = error*K_P;
     out_i += error*K_I;
@@ -619,7 +619,7 @@
     if (motor1.getPosition()>= ANGLEMIN && toestand != SLAAN) {
         toestand = WACHTEN;
         //out_i=0;
-        pid(0,0,true); 
+        //pid(0,0,true); 
         pc.printf("if1\n");
     }
     if (snelheidsstand != 0 && toestand == WACHTEN && stop == 0) { // stop = 0 in het begin let op dat dit na reset nog zo is
@@ -638,13 +638,13 @@
     if (toestand == SLAAN && motor1.getPosition() <= ANGLEMAX) {
         pc.printf("toestand = terugkeren\n\r");
         //out_i=0;
-        pid(0,0,true);
+        //pid(0,0,true);
         toestand = TERUGKEREN; 
         stop = 1; //zorgt dat hij niet weer gaat slaan tot er gereset is...
     }
     if (toestand == TERUGKEREN) {
         pc.printf("motor gaat terugkeren\n\r");
-        new_pwm=pid(setspeed, motor1.getSpeed());
+        new_pwm=pid(setspeed, motor1.getSpeed(),false);
         
         pwm_motor1.write(new_pwm);
         pc.printf("new pwm %f\r\n",new_pwm);
@@ -655,7 +655,7 @@
         pc.printf("ifwachten\n");
     }
     if (toestand == SLAAN) {
-        pid(setspeed, motor1.getSpeed());
+        pid(setspeed, motor1.getSpeed(),false);
         motordir1 = 1;
         pwm_motor1.write(new_pwm);
         pc.printf("SLAAN\n");