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

Dependencies:   Encoder mbed HIDScope Servo MODSERIAL

Fork of chessRobot by a steenbeek

Files at this revision

API Documentation at this revision

Comitter:
bjornnijhuis
Date:
Mon Oct 19 14:16:30 2015 +0000
Parent:
71:a79a88ca4b48
Child:
73:05cd0e692b74
Commit message:
Removed ECG.cpp standalone functions

Changed in this revision

EMG.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/EMG.cpp	Mon Oct 19 12:34:11 2015 +0000
+++ b/EMG.cpp	Mon Oct 19 14:16:30 2015 +0000
@@ -1,10 +1,10 @@
 #include "mbed.h"
 #include "HIDScope.h"
-#include "MODSERIAL.h"
+
 
 // Define objects
-AnalogIn    emg1(A0);                   // Analog input 1
-AnalogIn    emg2(A1);                   // Analog input 2
+AnalogIn    emg1(EMG1in);                   // Analog input 1
+AnalogIn    emg2(EMG2in);                   // Analog input 2
 DigitalOut  ledred(LED_RED);            // Red led
 DigitalOut  ledgreen(LED_GREEN);        // Green led
 DigitalOut  ledblue(LED_BLUE);          // Blue led
@@ -13,15 +13,13 @@
 HIDScope    scope(6);                   // Number of scopes
 Timer       normalizing_timer;          // Timer for normalizing
 Timer       EMG_timer;                  // Timer for switch statement
-MODSERIAL   pc(USBTX, USBRX);           // Ports for communication to pc
+
 
 // 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
-volatile bool emg_go = false;
-const int baudrate = 115200;            // Baudrate for serial connection
 
 
 //**********************************************************************************************
@@ -29,7 +27,6 @@
 //**********************************************************************************************
 
 // Define sampling constants
-const double sample_frequency = 200;         // Sample frequency [Hz]
 double emg_val1 = 0, emg_val2 = 0, emg_filt_val1 = 0, emg_filt_val2 = 0;
 
 // Define normalizing parameters
@@ -252,31 +249,16 @@
 }
 
 
-// Go_flag for EMG_sampling
-void emg_activate()
-{
-    emg_go=true;
-}
-
-int main()
+void readEMG()
 {
-    ledgreen.write(off);
-    ledblue.write(off);
-    ledred.write(on);
-    wait_ms(5000);
-    sample_tick.attach(&emg_activate, 1/sample_frequency);      // Call sample function with ticker
-    pc.baud(baudrate);                                          // Connect to pc for debugging output
-
-    if(mode==normalize) {                                       // Start normalizing timer
+    while(1) {
+    
+    if(mode==normalize && normalizing_timer.read_ms() != 0) {   // Start normalizing timer if not started alreade
         normalizing_timer.reset();
         normalizing_timer.start();
     }
 
-    while(1) {
-
-        if(emg_go && mode ==normalize) {
-            emg_go = false;
-
+        if(mode ==normalize) {
             emg_val1 = emg1.read();               // Sample EMG value 1 from AnalogIn
             emg_val2 = emg2.read();               // Sample EMG value 2 from AnalogIn
 
@@ -324,9 +306,7 @@
         }
 
 
-        if(emg_go && mode ==sample) {
-            emg_go = false;
-
+        if(mode ==sample) {
             emg_val1 = emg1.read();                             // Sample EMG value 1 from AnalogIn
             emg_val2 = emg2.read();                             // Sample EMG value 2 from AnalogIn
 
@@ -360,13 +340,13 @@
         }
 
         // Graphical output to HIDScope for debugging/ program check
-        scope.set(0,emg_filt_val2);
-        scope.set(1,x_velocity);
-        scope.set(2,y_velocity);
-        scope.set(3,pump);
-        scope.set(4,DOF);
-        scope.set(5,DOF);
-        scope.send();
+       // scope.set(0,emg_filt_val2);
+       // scope.set(1,x_velocity);
+       // scope.set(2,y_velocity);
+       // scope.set(3,pump);
+       // scope.set(4,DOF);
+       // scope.set(5,DOF);
+       // scope.send();
         //pc.printf("EMG timer: %i, EMG1 %.4f, EMG2 %.4f, DOF: %i, pump: %i \n", EMG_timer.read_ms(),emg_filt_val1,emg_filt_val2,DOF,pump);
         //pc.printf("Normalizing timer: %i, max_vol_cont1 = %.4f,max_vol_cont2 = %.4f \n",normalizing_timer.read_ms(),max_vol_cont1,max_vol_cont2);
     }