Dan August
/
EMGStdevV2
Werkt. (hopelijk)
Diff: main.cpp
- Revision:
- 2:e609cd999fd2
- Parent:
- 1:1ffb9e3ae00f
- Child:
- 3:117c0bb09513
diff -r 1ffb9e3ae00f -r e609cd999fd2 main.cpp --- a/main.cpp Mon Nov 04 13:26:18 2013 +0000 +++ b/main.cpp Mon Nov 04 20:09:22 2013 +0000 @@ -91,18 +91,18 @@ sig_out=sqrt(sum/size); sum=0; break; - /*case 3: + case 3: keeper_flexoren[count_flexoren]=input; count_flexoren++; if(count_flexoren==size) count_flexoren=0; - size=sizeof(keeper_flexoren)/sizeof(float); - for(int i; i < size; i++){ + //size=sizeof(keeper_flexoren)/sizeof(float); + for(int i=0; i < size; i++){ sum+=keeper_flexoren[i]; } mean=sum/size; sum=0; - for(int i; i < size; i++){ + for(int i=0; i < size; i++){ sum+=(keeper_flexoren[i]-mean)*(keeper_flexoren[i]-mean); } sig_out=sqrt(sum/size); @@ -113,18 +113,18 @@ count_extensoren++; if(count_extensoren==size) count_extensoren=0; - size=sizeof(keeper_extensoren)/sizeof(float); - for(int i; i < size; i++){ + //size=sizeof(keeper_extensoren)/sizeof(float); + for(int i=0; i < size; i++){ sum+=keeper_extensoren[i]; } mean=sum/size; sum=0; - for(int i; i < size; i++){ + for(int i=0; i < size; i++){ sum+=(keeper_extensoren[i]-mean)*(keeper_extensoren[i]-mean); } sig_out=sqrt(sum/size); sum=0; - break;*/ + break; } // einde switch return sig_out; } // einde if startcount ... @@ -140,9 +140,21 @@ case 2: keeper_triceps[count_triceps]=input; count_triceps++; - if(count_triceps>=size) + if(count_triceps >= size) count_triceps=0; break; + case 3: + keeper_flexoren[count_flexoren]=input; + count_flexoren++; + if(count_flexoren >= size) + count_flexoren=0; + break; + case 4: + keeper_extensoren[count_extensoren]=input; + count_extensoren++; + if(count_extensoren >= size) + count_extensoren=0; + break; } // einde switch } // einde else } // einde std_dev @@ -282,27 +294,36 @@ float dy; //static int sig_count = 1; emg_value_biceps=std_dev(filter(1),1); -emg_value_triceps=std_dev(filter(2),2); -dy = emg_value_biceps-emg_value_triceps; - +emg_value_triceps=std_dev(filter(2),2); +/*emg_value_flexoren = (100*filter(3)-44); +emg_value_extensoren = (100*filter(4)-44);*/ + + if(emg_value_biceps < 4.5) + emg_value_biceps=0; + else if (emg_value_biceps > 13) + emg_value_biceps = 13; + //emg_value_biceps = emg_value_biceps; - /*emg_value_flexoren = (100*filter(3)-44); - emg_value_extensoren = (100*filter(4)-44);*/ - - /*if(emg_value_biceps < 0.10){ + if(emg_value_triceps < 2.5) emg_value_biceps=0; - } - else { - emg_value_biceps = emg_value_biceps; - } - if(emg_value_triceps < 0.10){ - emg_value_triceps=0; - } - else { - emg_value_triceps=emg_value_triceps; - } - */ - //dy = emg_value_biceps-emg_value_triceps; + else if (emg_value_biceps > 10) + emg_value_biceps = 10; + //emg_value_triceps = emg_value_triceps; + + if(emg_value_flexoren < 2) + emg_value_flexoren=0; + else if (emg_value_flexoren > 8) + emg_value_flexoren = 8; + emg_value_flexoren = 2*emg_value_flexoren; + + 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 = 2*(emg_value_flexoren - emg_value_extensoren); + if(pc.rxBufferGetSize(0)-pc.rxBufferGetCount() > 30) pc.printf("%.6f, %.6f, %.6f\n",emg_value_biceps, emg_value_triceps, dy); /**When not using the LED, the above could also have been done this way: