code to drive the motors to the right position

Dependencies:   HIDScope QEI mbed

Fork of BMT-K9_potmeter_fade by First Last

Revision:
4:e481566a5b54
Parent:
3:6a97e1d68511
Child:
5:edac3771ede4
--- a/main.cpp	Wed Sep 23 09:44:06 2015 +0000
+++ b/main.cpp	Thu Sep 24 09:43:33 2015 +0000
@@ -20,6 +20,8 @@
 int countsPerRound = 32*131;
 float gototick;
 int currentpulses;
+int errorsignal;
+float Kf=0.2;
 //start 'main' function. Should be done once in every C(++) program
 int main()
 {
@@ -33,19 +35,22 @@
     while(1) {
         currentpulses=wheel.getPulses();
         gototick = pot1.read()*countsPerRound;
+        errorsignal=gototick-currentpulses;
         if (lastpotread != pot1.read()){
             lastpotread=pot1.read();
-            pc.printf("potvalue: %f, position: %d \n\r",gototick,currentpulses);
+            pc.printf("potvalue: %f, position: %d, control speed: %f \n\r",gototick,currentpulses,errorsignal*Kf);
         }
         
-        if (gototick > wheel.getPulses())
+        if (errorsignal > 0)
         {
-            motor1direction=0;
+            motor1direction=0; 
+            myled1=errorsignal*Kf;
             
         }
         else
         {
             motor1direction=1;
+            myled1=-errorsignal*Kf;
         }