now with PID controler XXXD

Dependencies:   HIDScope MODSERIAL QEI biquadFilter mbed

Fork of another_try_from_scratch_on_emg by Daniqe Kottelenberg

Revision:
52:0135deb3b07f
Parent:
51:b344a92b6a5f
Child:
53:6b91f69fa2dc
--- a/main.cpp	Thu Nov 03 10:37:29 2016 +0000
+++ b/main.cpp	Thu Nov 03 11:18:10 2016 +0000
@@ -48,8 +48,8 @@
 
 //thresholds
 double treshold_biceps_right = 0.04;                 //common values that work.
-double treshold_biceps_left = -0.04;                  // tested on multiple persons 
-double treshold_triceps = -0.04;                      //triceps and left biceps is specified negative, thus negative treshold
+double treshold_biceps_left = -0.04;                 // tested on multiple persons 
+double treshold_triceps = -0.04;                     //triceps and left biceps is specified negative, thus negative treshold
 
 //on/off and switch signals
 int switch_signal = 0; //start of counter, switch made by even and odd numbers
@@ -193,7 +193,7 @@
                 }
                 
 void reference(){
-    if (onoffsignal_biceps==1){                     //right biceps contracted{
+    if (onoffsignal_biceps==-1 && switch_signal%2==0){ //switch even       //right biceps contracted{
          d_ref = d_ref + w_ref * Ts;
     }
          if (d_ref > 21.36 ){
@@ -204,7 +204,7 @@
         d_ref = d_ref;
     }
     
-    if (onoffsignal_biceps==-1){                    //left biceps contracted{
+    if (onoffsignal_biceps==1 && switch_signal%2==0){ //switch even    //left biceps contracted{
         d_ref = d_ref - w_ref * Ts;
     }
         if (d_ref < -21.36){
@@ -270,9 +270,9 @@
 counts_encoder1 = Encoder1.getPulses();
 rev_counts_motor1=(float)counts_encoder1/(gearboxratio*rev_rond); 
 rev_counts_motor1_rad=rev_counts_motor1*6.28318530718; 
-pc.printf("%f", pwm_motor1.read());
-pc.printf("   %f", d_ref);
-pc.printf("   %f \r\n", rev_counts_motor1_rad);
+
+pc.printf("%f \r\n", d_ref);
+pc.printf("%f ", rev_counts_motor1_rad);
 
     if (onoffsignal_biceps==-1)  //left biceps contracted                        
     {
@@ -282,12 +282,13 @@
             //richting_motor1 = ccw;    //motor 1, left
             //pwm_motor1 = speedmotor1; //speed of motor 1
             if (speedmotor1<0){
-                richting_motor1 = 0;
+                richting_motor1 = cw;
                 }
             else   {
-                richting_motor1 = 1;
+                richting_motor1 = ccw;
                 }
                 pwm_motor1 = fabs(speedmotor1);      //speed of motor 1
+               // pc.printf("%f\r\n", pwm_motor1.read());
          } 
             
          
@@ -299,7 +300,7 @@
          }      
               
     }
-    else if (onoffsignal_biceps==1)                     //right biceps contracted
+    else if (onoffsignal_biceps==1)                  //right biceps contracted
     {
          if (switch_signal%2==0)                     //switch signal even
          {
@@ -307,13 +308,13 @@
             //richting_motor1 = ccw;    //motor 1, left
             //pwm_motor1 = speedmotor1; //speed of motor 1
             if (speedmotor1<0){
-                richting_motor1 = 0;
+                richting_motor1 = cw;
                 }
             else   {
-                richting_motor1 = 1;
+                richting_motor1 = ccw;
                 }
                 pwm_motor1 = fabs(speedmotor1);      //speed of motor 1
-           
+          // pc.printf("%f\r\n", pwm_motor1.read());
         } 
          else                         //switch signal odd
          {