Control up to two motors using filtered EMG signals and a PID controller

Dependencies:   FastPWM HIDScope MODSERIAL QEI Matrix biquadFilter controller errorFetch mbed motorConfig refGen MatrixMath inverseKinematics

Fork of Minor_test_serial by First Last

Revision:
14:664870b5d153
Parent:
13:83e3672b24ee
Child:
15:b76b8cff4d8f
--- a/main.cpp	Thu Sep 21 09:29:19 2017 +0000
+++ b/main.cpp	Thu Sep 21 10:02:29 2017 +0000
@@ -6,8 +6,14 @@
 QEI Encoder(D12,D13,NC,64, QEI::X4_ENCODING);
 MODSERIAL pc(USBTX, USBRX);
 
+// Defining outputs
 DigitalOut motor1_direction(D4);
 PwmOut motor1_pwm(D5);
+
+// Defining inputs
+InterruptIn sw2(SW2);
+
+
 float pwmPeriod = 1.0/5000.0;
 
 Ticker encoderTicker;
@@ -20,26 +26,30 @@
     pc.printf("%i pulses \r\n", counts);
     pc.printf("%f revolutions \r\n", revs);
     }
+    
+void killSwitch(){
+    motor1_pwm.write(0.0);
+    }
+    
+void M1switchDirection(){
+    motor1_direction = !motor1_direction;
+    }
 
 int frequency_pwm = 10000; //10kHz PWM
 
 
 int main()
     {
-    motor1_direction = true;
+    motor1_direction = false;
     motor1_pwm.period(pwmPeriod);//T=1/f 
+    sw2.fall(&killSwitch);
 
     pc.baud(115200);
     encoderTicker.attach(readEncoder, 1.0);    
     pc.printf("Encoder ticker attached and baudrate set");
     
-
-    while(true){
-        for(int i = 0 ; i<=30 ; i= i+10)
-        {
-            motor1_pwm.write(i/100.0);//write Duty Cycle
-        }
-    }
-
+    motor1_pwm.write(100.0/100.0);//write Duty Cycle
+        
+    sw2.fall(&killSwitch);
     }