Nieuwe kinematica + potmeter
Dependencies: HIDScope MODSERIAL QEI biquadFilter mbed
Fork of Project_script_union_potmeter by
Diff: main.cpp
- Revision:
- 21:1da43fdbd254
- Parent:
- 20:bd9495b31f50
- Child:
- 22:5d956c93b3ae
--- a/main.cpp Mon Oct 22 13:00:11 2018 +0000 +++ b/main.cpp Mon Oct 22 13:44:40 2018 +0000 @@ -27,7 +27,7 @@ //HIDscope Ticker sample_timer; -HIDScope scope( 2 ); +HIDScope scope( 3 ); //Global variables int encoder = 0; //Starting point encoder @@ -41,7 +41,7 @@ double movAg0,movAg1,movAg2; //outcome of MovAg //calibration -static int x = -1; +int x = -1; int emg_cal = 0; const int sizeCal = 2000; double StoreCal0[sizeCal], StoreCal1[sizeCal], StoreCal2[sizeCal]; @@ -80,6 +80,7 @@ /* Set the sampled emg values in channel 0 (the first channel) and 1 (the second channel) in the 'HIDScope' instance named 'scope' */ scope.set(0, emg0_in.read() ); scope.set(1, emg1_in.read() ); + scope.set(2, emg2_in.read() ); /* Repeat the step above if required for more channels of required (channel 0 up to 5 = 6 channels) * Ensure that enough channels are available (HIDScope scope( 2 )) * Finally, send all channels to the PC at once */ @@ -92,7 +93,7 @@ double emg0 = emg0_in.read(); double bandpass0 = emg0band.step(emg0); double absolute0 = fabs(bandpass0); - double notch0 = notch1.step(absolute0); + double emgfilter0 = notch1.step(absolute0); } void EMGFilter1() @@ -100,7 +101,7 @@ double emg1 = emg1_in.read(); double bandpass1 = emg1band.step(emg1); double absolute1 = fabs(bandpass1); - double notch1 = notch2.step(absolute1); + double emgfilter1 = notch2.step(absolute1); } void EMGFilter2() @@ -108,7 +109,7 @@ double emg2 = emg2_in.read(); double bandpass2 = emg2band.step(emg2); double absolute2 = fabs(bandpass2); - double notch2 = notch3.step(absolute2); + double emgfilter2 = notch3.step(absolute2); } void MovAg() //Calculate moving average (MovAg) @@ -195,7 +196,7 @@ { StoreCal0[j] = emgfilter0; sum+=StoreCal0[j]; - //wait(0.001f); + wait(0.001f); } Mean0 = sum/sizeCal; Threshold0 = Mean0/2; @@ -208,7 +209,7 @@ { StoreCal1[j] = emgfilter1; sum+=StoreCal1[j]; - //wait(0.001f); + wait(0.001f); } Mean1 = sum/sizeCal; Threshold1 = Mean1/2; @@ -221,7 +222,7 @@ { StoreCal1[j] = emgfilter2; sum+=StoreCal2[j]; - //wait(0.001f); + wait(0.001f); } Mean2 = sum/sizeCal; Threshold2 = Mean2/2; @@ -230,7 +231,7 @@ case 3: //EMG is calibrated, robot can be set to Home position. { emg_cal = 1; - //wait(0.001f); + wait(0.001f); break; } default: //Ensures nothing happens if x is not 0,1 or 2. @@ -295,18 +296,19 @@ { //pc.baud(115200); //pc.printf("hello\n\r"); - sample_timer.attach(&sample, 0.002); ledr = 0; //Begin led = red, first state of calibration ledb = 1; ledg = 1; + sample_timer.attach(&sample, 0.002); //HIDscope + filter_tick.attach(&emg_filtered,T); //EMG signals filtered + moving average every T sec. button1.rise(switch_to_calibrate); //Switch state of calibration (which muscle) wait(0.2f); button2.rise(calibrate); //calibrate threshold for 3 muscles wait(0.2f); - + pwmpin1.period_us(60); //60 microseconds PWM period, 16.7 kHz encoderA.rise(&encoderA_rise); @@ -370,5 +372,4 @@ } } - while(1) {} }