Draaiende motor op commando van knopje (WERKEND)

Dependencies:   Encoder MODSERIAL mbed

Fork of P_controller_motor by Bouke Scheltinga

Revision:
0:843492f4fe62
Child:
1:b0d3c64bd4d8
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Thu Sep 17 10:08:19 2015 +0000
@@ -0,0 +1,28 @@
+#include "mbed.h"
+#include "HIDScope.h"
+
+//P Motor Controller
+
+// Controller gain
+const double motorP_Kp=2.5;
+const double Convert_volt_to_position=0.00300;
+
+// Reusable P controller (FUNCTIE)
+double P (double error, const double Kp)
+    {
+            Return Kp*error;
+    }
+    
+// Error measurement and apply the output to the plant
+void motorP_Controller()
+    {
+        double reference_position = potmeter1.read();
+        double position = Convert_volt_to_position*encoder1.getPosition();
+        motorP=P(reference_position - position, motorP_Kp);
+    }
+    
+int main()
+    {
+        myControllerTicker.attach(&motorP_Controller,0.01f); //100Hz
+        while(1){}
+    }