Doesn't hit the ends

Dependencies:   Motordriver QEI mbed

Files at this revision

API Documentation at this revision

Comitter:
meikefrok
Date:
Fri Oct 21 11:28:55 2016 +0000
Commit message:
Encoder Cart

Changed in this revision

Motordriver.lib Show annotated file Show diff for this revision Revisions of this file
QEI.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Motordriver.lib	Fri Oct 21 11:28:55 2016 +0000
@@ -0,0 +1,1 @@
+http://developer.mbed.org/users/littlexc/code/Motordriver/#3110b9209d3c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/QEI.lib	Fri Oct 21 11:28:55 2016 +0000
@@ -0,0 +1,1 @@
+http://developer.mbed.org/users/aberk/code/QEI/#5c2ad81551aa
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Fri Oct 21 11:28:55 2016 +0000
@@ -0,0 +1,76 @@
+#include "QEI.h"
+#include "mbed.h"
+#include "motordriver.h"
+
+//======== Serial Communication ================================================
+Serial pc(USBTX, USBRX);
+
+
+//======== Motor and QEI =======================================================
+QEI wheel (D12, D13, NC, 62);
+
+//Safety for Motor
+int Brakeable;
+int sign;
+
+//Motor
+Motor A(D6, D7, D7, Brakeable); // pwm, fwd, rev, brake          LEFT
+
+
+//======== Miscellaneous =======================================================
+AnalogIn pot(A1);               //Potmeter
+DigitalOut led(LED_GREEN);      //Green LED
+InterruptIn btn(SW2);           //Button
+InterruptIn btn2(SW3);          //Button
+
+
+//======== Variables ===========================================================
+float factor = 0.03279;
+int position;
+float ain;   /* Variable to store the analog input*/
+
+
+
+
+//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+//======== Functions and main ==================================================
+int main() {
+   while(1){
+   
+   if(btn && btn2) {   
+        A.speed(0)==0;
+      
+   }else if(btn && !btn2){
+        if(position <= -105){
+        A.speed(0.2)==0.2;
+    
+        }else{
+        A.speed(-0.5)==-0.5;
+        }
+    
+    }else if(!btn && btn2){
+        if(position >= 105){
+        A.speed(-0.2)==-0.2;
+    
+        }else{
+        A.speed(0.5)==0.5;
+        }
+    }
+    
+    else{
+    A.speed(0)==0;
+    }   
+    
+    position = (wheel.getPulses()*factor) ; // position of the motor      
+    ain = pot.read();
+   
+            if (ain == 0){
+                wheel.reset();   
+            }
+            else {}
+        wait(0.1);
+        pc.baud(115200);
+        pc.printf("Afgelegde milimeters is: %i\n", position);
+    }
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Fri Oct 21 11:28:55 2016 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/25aea2a3f4e3
\ No newline at end of file