motor controller with P velocity control

Dependencies:   HIDScope PID QEI mbed EMG

Fork of PID_VelocityExample by Aaron Berk

Revision:
13:40141b362092
Parent:
12:d7bb475bb82d
Child:
14:102a2b4f5c86
Child:
20:8064435d21da
diff -r d7bb475bb82d -r 40141b362092 main.cpp
--- a/main.cpp	Tue Oct 06 10:51:02 2015 +0000
+++ b/main.cpp	Tue Oct 06 11:30:38 2015 +0000
@@ -6,9 +6,20 @@
 #include "inits.h" // all globals, pin and variable initialization 
 
 void setGoFlag(){
+    if (goFlag==true){
+        // flag is already set true: code too slow or frequency too high    
+    }
     goFlag=true;
 }
 
+void systemStart(){
+    systemOn=true;
+}
+void systemStop(){
+    systemOn=false;
+    leftMotor=0;
+    rightMotor=0;
+}
 int main() {
     
     // initialize (defined in inits.h)
@@ -17,9 +28,12 @@
     
     motorControlTicker.attach(&setGoFlag, RATE);
     
+    startButton.rise(&systemStart);
+    stopButton.rise(&systemStop);
+    
     endTimer.start(); //Run for 100 seconds.
     while (endTimer.read() < 100){
-        if (goFlag==true){
+        if (goFlag==true && systemOn==true){
             // get 'emg' signal
             request_pos = pot1.read();
             request_neg = pot2.read();