Aukie Hooglugt / Mbed 2 deprecated Regelaar_motor

Dependencies:   Encoder HIDScope mbed

Revision:
5:7fb05dfead4d
Parent:
4:91b583d4d8c4
Child:
6:2887ad4c5d97
diff -r 91b583d4d8c4 -r 7fb05dfead4d main.cpp
--- a/main.cpp	Thu Oct 23 13:47:21 2014 +0000
+++ b/main.cpp	Thu Oct 23 14:18:58 2014 +0000
@@ -5,6 +5,8 @@
 
 HIDScope scope(4);
 
+void keep_in_range(float * in, float min, float max);
+
 int main()
 {
     //motor 1, 25D
@@ -24,7 +26,7 @@
     float setpoint1 = 3;
     float dt1 = 0.01;
     float Kp1 = 1;
-    float Ki1 = 0.5;
+    float Ki1 = 0.1;
     float error1 = 0;
     float output1 = 0;
     float omrekenfactor = 4480.0/6.28;
@@ -35,14 +37,15 @@
         //motorpositie omgerekend naar rad/s
         integral1 = integral1 + error1*dt1;
         output1 = Kp1*error1 + Ki1*integral1;
+        keep_in_range(&output1,-1,1);
         pwm_motor1.write(abs(output1));
         wait(dt1);
 
 
         if(output1 > 0) {
-            motor1dir = 0;
+            motor1dir = 1;
         } else {
-            motor1dir = 1;
+            motor1dir = 0;
         }
         scope.set(0, error1);
         scope.set(1, output1);
@@ -51,4 +54,8 @@
         scope.send();
 
     }
+}
+void keep_in_range(float * in, float min, float max)
+{
+*in > min ? *in < max? : *in = max: *in = max;
 }
\ No newline at end of file