Draaiende motor op commando van knopje (WERKEND)

Dependencies:   Encoder MODSERIAL mbed

Fork of P_controller_motor by Bouke Scheltinga

Revision:
11:c5befe79aa53
Parent:
10:1d8b21515ed1
Child:
12:27abe8ee588c
--- a/main.cpp	Thu Sep 17 12:53:08 2015 +0000
+++ b/main.cpp	Mon Sep 21 09:04:28 2015 +0000
@@ -1,61 +1,14 @@
 #include "mbed.h"
 #include "HIDScope.h"
 #include "encoder.h"
-
-// Define the HIDScope and Ticker object
-HIDScope    scope(2);
-Ticker      scopeTimer;
-Ticker      motorP;
-
-// Define Encoder
-
-Encoder encoder1(PTD0,PTC9,true);
-Serial pc(USBTX,USBRX);
+#include "MODSERIAL.h"
 
-// Define Potmeter
-AnalogIn potmeter1(PTB0);
-
-////// P Motor Controller
-
-// Controller gain
-const double motorP_Kp=2.500 ;
-const double Convert_volt_to_position=0.00300 ;
-
-// Reusable P controller (FUNCTIE)
-double P (double error, const double Kp)
-    {
-            return Kp*error;
-    }
-
+Encoder encoder1(D13,D12);
+DigitalOut motor2direction(D4); //D4 en D5 zijn motor 2 (op het motorshield)
+PwmOut motor2speed(D5);
 
-// 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();
-        double motorP = P(reference_position-position, motorP_Kp);
-    }
-    
 int main()
-    {
-        motorP.attach(&motorP_Controller, 0.01f); //100Hz
-        while(1){}
-    }
-
-// Read the analog input
-
- 
-// The data read and send function
-void scopeSend()
 {
-    scope.set(0,Ticker motorP);
-    scope.send();
+    motor2direction = 1;
+    motor2speed = 0.2f;
 }
- 
-int scopeattach()
-{
-    // Attach the data read and send function at 100 Hz
-    scopeTimer.attach_us(&scopeSend, 1e4);   
-    
-    while(1) { }
-}