control for robotic arm that can play chess using a granular gripper

Dependencies:   Encoder mbed HIDScope Servo MODSERIAL

Fork of chessRobot by a steenbeek

Revision:
92:12e2e57e900a
Parent:
80:8f030bd5dd15
diff -r 1d0c96a5bc5f -r 12e2e57e900a emg.cpp
--- a/emg.cpp	Wed Oct 21 11:13:10 2015 +0200
+++ b/emg.cpp	Wed Oct 21 10:28:42 2015 +0000
@@ -14,13 +14,7 @@
 // Define program constants
 const int     on = 0;                   // On-constant for LEDs for program readability
 const int     off = 1;                  // Off-constant for LEDs for program readability
-const int     sample = 0;               // Constant for mode switching for program readability
-const int     normalize = 1;            // Constant for mode switching for program readability
-
 bool ledsEnable = false;
-//**********************************************************************************************
-bool mode               = normalize;         // Set program mode
-//**********************************************************************************************
 
 // Initialize sampling constants
 double emg_val1 = 0, emg_val2 = 0, emg_filt_val1 = 0, emg_filt_val2 = 0;
@@ -214,13 +208,14 @@
 }
 
 
-void readEMG(){
-    if(mode==normalize && normalizing_timer.read_ms() == 0) {   // Start normalizing timer
+void readEMG()
+{
+    if(emg_mode==normalize && normalizing_timer.read_ms() == 0) {   // Start normalizing timer
         normalizing_timer.reset();
         normalizing_timer.start();
     }
 
-    if(mode ==normalize) {
+    if(emg_mode ==normalize) {
         emg_val1 = emg1.read();               // Sample EMG value 1 from AnalogIn
         emg_val2 = emg2.read();               // Sample EMG value 2 from AnalogIn
 
@@ -239,7 +234,7 @@
 
         // First normalizing step: channel 1
         if (normalizing_timer.read_ms() <= normalize_time && channel == 1) {
-            if (ledsEnable){
+            if (ledsEnable) {
                 redLed.write(off);
                 greenLed.write(on);
             }
@@ -249,13 +244,13 @@
             // Second normalizing step: wait time, switch channel
         } else if (normalizing_timer.read_ms() > normalize_time && channel == 1) {
             channel = 2;
-            if (ledsEnable){
+            if (ledsEnable) {
                 greenLed.write(off);
                 redLed.write(on);
             }
             // Third normalizing step: channel 2
         } else if (normalizing_timer.read_ms() >= (normalize_time + normalize_wait) && normalizing_timer.read_ms() <= (2*normalize_time + normalize_wait) && channel == 2) {
-            if (ledsEnable){
+            if (ledsEnable) {
                 redLed.write(off);
                 greenLed.write(on);
             }
@@ -266,17 +261,17 @@
         } else if (normalizing_timer.read_ms() > (2*normalize_time + normalize_wait)) {
             normalizing_timer.stop();
             normalizing_timer.reset();
-            if (ledsEnable){
+            if (ledsEnable) {
                 greenLed.write(off);
                 redLed.write(off);
                 blueLed.write(on);
             }
-            mode = sample;
+            emg_mode = sample;
         }
     }
 
 
-    if(mode ==sample) {
+    if(emg_mode ==sample) {
         emg_val1 = emg1.read();                             // Sample EMG value 1 from AnalogIn
         emg_val2 = emg2.read();                             // Sample EMG value 2 from AnalogIn
 
@@ -303,7 +298,7 @@
             EMG_check(thr_pass1, thr_pass2, x_velocity, y_velocity, z_velocity, emg_filt_val1, emg_filt_val2, EMG_timer.read_ms());
 
         } else {
-            if (ledsEnable){
+            if (ledsEnable) {
                 greenLed.write(off);
                 redLed.write(on);
                 blueLed.write(off);
@@ -312,8 +307,5 @@
     }
 
     // Graphical output to HIDScope for debugging/ program check
-
-
-
 }