Draaiende motor op commando van knopje (WERKEND)

Dependencies:   Encoder MODSERIAL mbed

Fork of P_controller_motor by Bouke Scheltinga

Revision:
3:eee8d5461256
Parent:
2:f5c9d981de51
Child:
4:dfdfcb518e60
--- a/main.cpp	Thu Sep 17 10:15:44 2015 +0000
+++ b/main.cpp	Thu Sep 17 10:45:54 2015 +0000
@@ -1,28 +1,11 @@
 #include "mbed.h"
 #include "HIDScope.h"
+#include "encoder.h"
 
 // Define the HIDScope and Ticker object
 HIDScope    scope(1);
 Ticker      scopeTimer;
  
-// Read the analog input
-float triangle_signal = 3;
- 
-// The data read and send function
-void scopeSend()
-{
-    scope.set(0,triangle_signal);
-    scope.send();
-}
- 
-int main()
-{
-    // Attach the data read and send function at 100 Hz
-    scopeTimer.attach_us(&scopeSend, 1e4);   
-    
-    while(1) { }
-}
-
 ////// P Motor Controller
 
 // Controller gain
@@ -32,8 +15,23 @@
 // Reusable P controller (FUNCTIE)
 double P (double error, const double Kp)
     {
-            Return Kp*error;
+            return Kp*error;
     }
+
+#include "Encoder.h"
+ *
+ *   Encoder motor1(PTD0,PTC9,true);
+ *   Serial pc(USBTX,USBRX);
+ *   pc.baud(115200);
+   while(1) {
+    wait(0.2);
+    pc.printf("pos: %d, speed %f \r\n",motor1.getPosition(), motor1.getSpeed());
+    }
+ 
+AnalogIn potmeter1(POT1);
+
+// encoder1
+// potmeter1
     
 // Error measurement and apply the output to the plant
 void motorP_Controller()
@@ -48,3 +46,22 @@
         myControllerTicker.attach(&motorP_Controller,0.01f); //100Hz
         while(1){}
     }
+
+
+// Read the analog input
+float triangle_signal = 2.05;
+ 
+// The data read and send function
+void scopeSend()
+{
+    scope.set(0,motorP);
+    scope.send();
+}
+ 
+int main()
+{
+    // Attach the data read and send function at 200 Hz
+    scopeTimer.attach_us(&scopeSend, 2e4);   
+    
+    while(1) { }
+}