Combination code of movement and emg code with small changes for 2 motors.
Dependencies: HIDScope MODSERIAL QEI biquadFilter mbed
Fork of EMG_converter_code by
Diff: main.cpp
- Revision:
- 11:8196434745b4
- Parent:
- 10:4af887af3a47
- Child:
- 12:86b3885a6308
diff -r 4af887af3a47 -r 8196434745b4 main.cpp --- a/main.cpp Wed Oct 28 11:02:52 2015 +0000 +++ b/main.cpp Wed Oct 28 11:46:55 2015 +0000 @@ -26,10 +26,10 @@ PwmOut speed2(D5);//speed input for motor 2 /*The biquad filters required to transform the EMG signal into an usable signal*/ -biquadFilter filterhigh1(-1.1430, 0.4128, 0.6389, -1.2779, 0.6389); -biquadFilter filterlow1(1.9556, 0.9565, 0.9780, 1.9561, 0.9780); -biquadFilter notch(-1.1978e-16, 0.9561, 0.9780, -1.1978e-16, 0.9780); -biquadFilter filterlow2(-1.9645, 0.9651, 1.5515e-4, 3.1030e-4, 1.5515e-4); +biquadFilter filterhigh1(-1.4542, 0.5741, 0.7571, -1.5142, 0.7571); +biquadFilter filterlow1(0.4395, 0.2059, 0.4114, 0.8227, 0.4114); +biquadFilter notch(-1.0958, 0.9723, 0.9862, -1.0958, 0.9862); +biquadFilter filterlow2(-1.4542, 0.5741, 0.0300, 0.0599, 0.0300); double emg_value1; double signalpart11; double signalpart12; @@ -76,14 +76,26 @@ signalpart14 = filterlow1.step(signalpart13);//notch filter to remove 50Hz signal signalfinal1 = filterlow2.step(signalpart14);//2nd low pass filter to envelope the emg onoffsignal1=signalfinal1/maxcal;//divide the emg signal by the max EMG to calibrate the signal per person + //pc.printf("the emg 1 signal is: %f \n",onoffsignal1); + emg_value2 = emg2.read();//read the emg value from the elektrodes + signalpart21 = notch.step(emg_value2);//Highpass filter for removing offset and artifacts + signalpart22 = filterhigh1.step(signalpart21);//rectify the filtered signal + signalpart23 = abs(signalpart22);//low pass filter to envelope the emg + signalpart24 = filterlow1.step(signalpart23);//notch filter to remove 50Hz signal + signalfinal2 = filterlow2.step(signalpart24);//2nd low pass filter to envelope the emg + onoffsignal2=signalfinal2/maxcal;//divide the emg signal by the max EMG to calibrate the signal per person + scope.set(0,emg_value1);//set emg signal to scope in channel 1 scope.set(1,onoffsignal1);//set filtered signal to scope in channel 2 - pc.printf("the emg 1 signal is: %f \n",onoffsignal1); - scope.send();//send the signals to the scope + scope.set(2,emg_value2);//set emg signal to scope in channel 1 + scope.set(3,onoffsignal2);//set filtered signal to scope in channel 2 + scope.send();//send the signals to the scope + //pc.printf("the emg 2 signal is: %f \n",onoffsignal2); + //pc.printf("emg signal %f, filtered signal %f \n",emg_value,onoffsignal); } } - +/* void filter2(){ if(calyes==1){ emg_value2 = emg2.read();//read the emg value from the elektrodes @@ -99,7 +111,8 @@ scope.send();//send the signals to the scope //pc.printf("emg signal %f, filtered signal %f \n",emg_value,onoffsignal); } -} +}*/ + /* void checkmotor1(){//check the normalized signal and set actions if a threshold is passed not needed in ticker move to main function if(calyes==1){ @@ -179,7 +192,7 @@ led3.write(1); speed1.write(0); speed2.write(0); - sample_timer1.attach(&filter1, 0.005);//continously execute the EMG reader and filter + sample_timer1.attach(filter1, 0.003125);//continously execute the EMG reader and filter // sample_timer2.attach(&filter2, 0.005);//continously execute the EMG reader and filter //motor_timer1.attach(&checkmotor1, 0.002);//continously execute the motor controller //motor_timer2.attach(&checkmotor2, 0.002);//continously execute the motor controller