Library with P, PI and PID controller

Dependents:   buttoncontrol includeair includeair Oudverslag

Revision:
10:37bdb3e5f03a
Parent:
9:2d57152425d1
Child:
11:ef8d28e010a2
--- a/controlandadjust.cpp	Thu Oct 08 14:04:20 2015 +0000
+++ b/controlandadjust.cpp	Thu Oct 08 14:19:50 2015 +0000
@@ -8,6 +8,7 @@
 float speed1;
 float direction2;
 float speed2;
+float maxvaluepwm=0;
 
 DigitalOut motor1_dir(D7);// draairichting motor 1 (1 is CW encoder als je daar op kijkt en CW shaft als je daar op kijkt)
 PwmOut motor1_speed(D6);//aanstuursnelheid motor 1
@@ -16,12 +17,9 @@
 
 
 
-controlandadjust::controlandadjust(void)
+controlandadjust::controlandadjust(float safety_cutoff)
 {
-    //motor1_speed.write(0);
-    // motor2_speed.write(0);
-
-
+    maxvaluepwm=safety_cutoff;
 }
 
 void controlandadjust::verwerksignaal(float signaal1,float signaal2)
@@ -33,8 +31,8 @@
         direction1=CCW;
     }
 
-    if (fabs(signaal1)>=1) { //check if signal is <1
-        speed1=1;//if signal >1 make it 1 to not damage motor
+    if (fabs(signaal1)>=maxvaluepwm) { //check if signal is <1
+        speed1=maxvaluepwm;//if signal >1 make it 1 to not damage motor
     } else {
         speed1=fabs(signaal1);// if signal<1 use signal
     }
@@ -46,8 +44,8 @@
         direction2=CCW;
     }
 
-    if (fabs(signaal2)>=1) { //check if signal is <1
-        speed2=1;//if signal >1 make it 1 to not damage motor
+    if (fabs(signaal2)>=maxvaluepwm) { //check if signal is <1
+        speed2=maxvaluepwm;//if signal >1 make it 1 to not damage motor
     } else {
         speed2=fabs(signaal2);// if signal<1 use signal
     }