2nd draft
Dependencies: HIDScope MODSERIAL QEI biquadFilter mbed Servo
Fork of robot_mockup by
Diff: main.cpp
- Revision:
- 44:145827f5b091
- Parent:
- 42:b9d26b1218b0
- Child:
- 45:198654304238
--- a/main.cpp Fri Oct 23 09:34:49 2015 +0000 +++ b/main.cpp Fri Oct 23 10:12:47 2015 +0000 @@ -94,7 +94,14 @@ double xdir, ydir; //EMG reference position directions double xpower, ypower; //EMG reference magnitude double dx, dy; //integration of EMG (velocity) to position - +//Threshold moving average +const int window=100; //00 samples +int i=0; //buffer index +double movavg1[window]; //moving average arrays +double movavg2[window]; +double movavg3[window]; +double movavg4[window]; + int muscle; //Muscle selector for MVC measurement, 1 = first emg etc. double calibrate_time; //Elapsed time for each MVC measurement @@ -491,26 +498,7 @@ //scope.set(2,flexor_power); //scope.set(3,extens_power); scope.send(); - - // on - offset. If above a value it is on. - - - /* alternative for lowpass filter: moving average - window=30; //30 samples - int i=0; //buffer index - bicepsbuffer[i]=biceps_power //fill array - - i++; - if(i==window){ - i=0; - } - - for(int x = 0; x < window; x++){ - avg1 += bicepsbuffer[x]; - } - avg1 = avg1/window; - */ - + } @@ -558,10 +546,10 @@ shoulder_limit.rise(&shoulder); elbow_limit.rise(&elbow); while(!done1){ - pwm_motor1.write(0.2); //move upper arm slowly cw + pwm_motor1.write(0.1); //move upper arm slowly cw } if(done1==true){ - pwm_motor2.write(0.2); //move forearm slowly cw + pwm_motor2.write(0.1); //move forearm slowly cw } if(done1 && done2){ @@ -834,9 +822,26 @@ scope.set(3,triceps); scope.send(); + //threshold detection! buffer or two thresholds? If average of 100 samples > threshold, then muscle considered on. + /* - //threshold detection! buffer or two thresholds? - //TODO + movavg1[i]=biceps; //fill array with 100 normalized samples + movavg2[i]=triceps; + movavg3[i]=flexor; + movavg4[i]=extens; + i++; + if(i==window){ //if array full,set i to 0 + i=0; + } + + for(int j = 0; j < window; j++){ // sum all values in the array + th1 += movavg1[j]; + th2 += movavg2[j]; + th3 += movavg3[j]; + th4 += movavg4[j]; + } + th1 = th1/window; //divide sum by number of samples -> average + */ //analyze emg (= velocity) if (biceps>triceps && biceps > 0.2){