Opgeschoonde code voor verslag

Dependencies:   Encoder HIDScope MODSERIAL mbed

Fork of TotalCodegr13V2 by Rianne Bulthuis

Revision:
11:b2dec8f3e75c
Parent:
10:34ccb2fed2ef
Child:
12:146ba6f95fe0
--- a/main.cpp	Tue Oct 27 10:23:31 2015 +0000
+++ b/main.cpp	Tue Oct 27 11:42:19 2015 +0000
@@ -15,8 +15,8 @@
 AnalogIn    PotMeter2(A5);
 AnalogIn    EMG_bicepsright(A0);
 AnalogIn    EMG_bicepsleft(A1);
-AnalogIn    EMG_tricepsright(A2);
-AnalogIn    EMG_tricepsleft(A3);
+AnalogIn    EMG_legright(A2);
+AnalogIn    EMG_legleft(A3);
 Ticker      controller;
 Ticker      ticker_regelaar;
 Ticker      EMG_Filter;
@@ -153,6 +153,7 @@
 // script voor filters
 void Filters()
 {
+    // Biceps right 
     A = EMG_bicepsright.read();
     //Highpass
     y1 = biquad (A, ah1_v1, ah1_v2, fh1_a1, fh1_a2, fh1_b0*0.753507, fh1_b1*0.753507, fh1_b2*0.753507);
@@ -170,7 +171,7 @@
     y9 = biquad (y8, alp1_v1, alp1_v2, flp1_a1, flp1_a2, flp1_b0*0.065187, flp1_b1* 0.065187, flp1_b2* 0.065187);
     final_filter1 = biquad(y9, alp2_v1, alp2_v2, flp2_a1, flp2_a2, flp2_b0*0.004525, flp2_b1*0.004525, flp2_b2*0.004525);
 
-    //Biceps right
+    //Biceps left
     B = EMG_bicepsleft.read();
     //Highpass
     y10 = biquad (B, bh1_v1, bh1_v2, fh1_a1, fh1_a2, fh1_b0*0.753507, fh1_b1*0.753507, fh1_b2*0.753507);
@@ -188,8 +189,8 @@
     y18 = biquad (y17, blp1_v1, blp1_v2, flp1_a1, flp1_a2, flp1_b0*0.065187, flp1_b1*0.065187, flp1_b2*0.065187);
     final_filter2 = biquad(y18, blp2_v1, blp2_v2, flp2_a1, flp2_a2, flp2_b0*0.004525, flp2_b1*0.004525, flp2_b2*0.004525);
 
-    /// EMG Filter left leg
-    C = EMG_tricepsright.read();
+    /// EMG Filter right leg
+    C = EMG_legright.read();
     //Highpass
     y19 = biquad (C, ch1_v1, ch1_v2, fh1_a1, fh1_a2, fh1_b0*0.753507, fh1_b1*0.753507, fh1_b2*0.753507);
     y20 = biquad (y19, ch2_v1, ch2_v2, fh2_a1, fh2_a2, fh2_b0*0.697278, fh2_b1*0.697278, fh2_b2*0.697278);
@@ -206,8 +207,8 @@
     y27 = biquad (y26, clp1_v1, clp1_v2, flp1_a1, flp1_a2, flp1_b0*0.065187, flp1_b1*0.065187, flp1_b2*0.065187);
     final_filter3 = biquad(y27, clp2_v1, clp2_v2, flp2_a1, flp2_a2, flp2_b0*0.004525, flp2_b1*0.004525, flp2_b2*0.004525);
 
-    // EMG filter right leg
-    D = EMG_tricepsleft.read();
+    // EMG filter left leg
+    D = EMG_legleft.read();
     //Highpass
     y28 = biquad (D, dh1_v1, dh1_v2, fh1_a1, fh1_a2, fh1_b0*0.753507, fh1_b1*0.753507, fh1_b2*0.753507);
     y29 = biquad (y28, dh2_v1, dh2_v2, fh2_a1, fh2_a2, fh2_b0*0.697278, fh2_b1*0.697278, fh2_b2*0.697278);
@@ -236,11 +237,11 @@
 
 void move_motor1()
 {
-    if (final_filter1 > 0.06 || button_1 == pressed) {
+    if (final_filter1 > 0.04 || button_1 == pressed) {
         pc.printf("motor1 cw \n\r");
         motor1_direction = 0; //counterclockwise
         motor1_speed = 0.2;
-    } else if (final_filter3 > 0.07 || button_2 == pressed){
+    } else if (final_filter2 > 0.04 || button_2 == pressed){
         pc.printf("motor1 ccw \n\r");
         motor1_direction = 1; //clockwise
         motor1_speed = 0.2;
@@ -252,12 +253,12 @@
 
 void move_motor2()
 {
-    if (button_1 == pressed) {
+    if (final_filter3 > 0.05) {
         pc.printf("motor2 cw \n\r");
         motor2_direction = 1; //clockwise
         motor2_speed = 0.4;
-    } else if (button_2 == pressed) {
-        pc.printf("Moving  2 counterclockwise \n\r");
+    } else if (final_filter4 > 0.05) {
+        pc.printf("motor2 ccw \n\r");
         motor2_direction = 0; //counterclockwise
         motor2_speed = 0.4;
     } else {