robot

Dependencies:   Encoder HIDScope MODSERIAL TouchButton mbed-dsp mbed

Fork of Robot2false by BMT M9 Groep01

Revision:
37:35fda673beb3
Parent:
36:0c8d4397c02f
Child:
38:cc14faf38326
diff -r 0c8d4397c02f -r 35fda673beb3 main.cpp
--- a/main.cpp	Sat Nov 01 23:23:49 2014 +0000
+++ b/main.cpp	Sun Nov 02 12:17:33 2014 +0000
@@ -10,8 +10,8 @@
 #define K_D (0  /TSAMP1)
 #define I_LIMIT 1.
 #define K_Pp (0.2)
-#define K_Ip (0.02  *TSAMP1)
-#define K_Dp (0  /TSAMP1)
+#define K_Ip (0.02  *TSAMP2)//-----------------------------TSAMP1 veranderd naar TSAMP2
+#define K_Dp (0  /TSAMP2)//--------------------------------TSAMP1 veranderd naar TSAMP2
 
 #define TSAMP1 0.01
 #define TSAMP2 0.01
@@ -27,7 +27,7 @@
 void Calibratie_Triceps();
 void Calibratie_Biceps();
 float pid(float setspeed, float measurement, bool reset = false);
-float pidpositie(float setposition, float measurement);
+float pidpositie(float setposition, float measurement, bool reset = false);  //------------------,bool reset = false toegevoegd
 void motor2aansturing();
 void motor1aansturing();
 void motor1aansturingdeel2();
@@ -473,13 +473,17 @@
     return out_p + out_i + out_d;
 }
 
-float pidpositie(float setposition, float measurement)
+float pidpositie(float setposition, float measurement, bool reset ) //----------------------------bool reset toegevoegd
 {
     float error;
     static float prev_error = 0;
     float           out_p = 0;
     static float    out_i = 0;
     float           out_d = 0;
+    if(reset==true) {//-------------------------------------------------------------------if reset stukje toegevoegd
+        out_i = 0;
+        prev_error = 0;
+    }
     error  = setposition-measurement;
     out_p  = error*K_Pp;
     out_i += error*K_Ip;