emg eind code

Dependencies:   MODSERIAL mbed

Fork of EMGStdevV3 by Dan August

Revision:
7:2d98f94eda27
Parent:
6:33f0741dbb5b
--- a/main.cpp	Tue Nov 05 09:51:59 2013 +0000
+++ b/main.cpp	Wed Nov 06 12:26:17 2013 +0000
@@ -6,7 +6,8 @@
 AnalogIn    emg_triceps(PTB1);
 AnalogIn    emg_flexoren(PTB2);
 AnalogIn    emg_extensoren(PTB3); //Analog input
-PwmOut      red(LED_RED); //PWM output
+PwmOut      dy(PTA12); //PWM output
+PwmOut      dx(PTA4);
 Ticker timer;
 MODSERIAL pc(USBTX,USBRX,64,1024);
 
@@ -276,8 +277,8 @@
     float emg_value_triceps;
     float emg_value_flexoren;
     float emg_value_extensoren;
-    float dy;
-    float dx;
+//    float dy;
+//    float dx;
     //static int sig_count = 1;
 
     emg_value_biceps = std_dev(filter(1),1);
@@ -290,7 +291,7 @@
         emg_value_biceps=0;
     else if (emg_value_biceps > 13)
          emg_value_biceps = 13;
-    emg_value_biceps = 1.5 * emg_value_biceps;
+    emg_value_biceps = emg_value_biceps;
 
     if(emg_value_triceps < 5)
         emg_value_triceps=0;
@@ -302,21 +303,21 @@
         emg_value_flexoren=0;
     else if (emg_value_flexoren > 8)
          emg_value_flexoren = 8;
-    emg_value_flexoren = 1.5*emg_value_flexoren; // was 2, wordt 1.5
+    emg_value_flexoren = 1.5 * emg_value_flexoren; // was 2, wordt 1.5
         
     if(emg_value_extensoren < 5)
         emg_value_extensoren=0;
     else if (emg_value_extensoren > 13)
          emg_value_extensoren = 13;
 
-    dy = emg_value_biceps - emg_value_triceps;
-    dx = (emg_value_flexoren - emg_value_extensoren); // was gain 2, wordt 1
+    dy = (emg_value_biceps - emg_value_triceps)/30+0.5;
+    dx = (emg_value_flexoren - emg_value_extensoren)/30+0.5; // was gain 2, wordt 1
  
     if(pc.rxBufferGetSize(0)-pc.rxBufferGetCount() > 30)
-        pc.printf("%.6f\n",dx);
+        pc.printf("%.6f,%.6f\n",dx, dy);
     /**When not using the LED, the above could also have been done this way:
-    * pc.printf("%.6\n", emg0.read());
-    */
+    /* pc.printf("%.6\n", emg0.read());*/
+   
 }
 
 int main()
@@ -324,6 +325,8 @@
 {
     /*setup baudrate. Choose the same in your program on PC side*/
     pc.baud(115200);
+    dy.period_ms(1);
+    dx.period_ms(1);
     /*set the period for the PWM to the red LED*/
     //red.period_ms(2);
     /**Here you attach the 'void looper(void)' function to the Ticker object