EMG filtering; highpass, notch, abs, moving average
Dependencies: HIDScope MODSERIAL- mbed-dsp mbed
Revision 38:277ba1c0693c, committed 2014-10-08
- Comitter:
- Hooglugt
- Date:
- Wed Oct 08 11:41:43 2014 +0000
- Parent:
- 37:2d248e64b745
- Child:
- 39:0328b1f16a5a
- Commit message:
- floats for emg_bi/trifloat instead of pin outputs to "create" floats
Changed in this revision
Project_main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/Project_main.cpp Tue Oct 07 14:01:51 2014 +0000 +++ b/Project_main.cpp Wed Oct 08 11:41:43 2014 +0000 @@ -2,15 +2,21 @@ #include "MODSERIAL.h" #include "HIDScope.h" -#define TIMEB4NEXTCHOICE 5 // 1s keuzelampje blijft aan -#define TIMEBETWEENBLINK 50 // 1s voor volgende blink +#define TIMEB4NEXTCHOICE 2 // 1s keuzelampje blijft aan +#define TIMEBETWEENBLINK 20 // 1s voor volgende blink //Define objects AnalogIn emg0(PTB1); //Analog input biceps +float emg_bifloat; //Float voor EMG-waarde biceps, VRAAG: waarom we hier een PwmOut voor gebruiken - kunnen we geen float gebruiken? + AnalogIn emg1(PTB2); //Analog input triceps +float emg_trifloat; //Float voor EMG-waarde triceps -PwmOut emg_bifloat(PTD4); //Float voor EMG-waarde biceps, VRAAG: waarom we hier een PwmOut voor gebruiken - kunnen we geen float gebruiken? -PwmOut emg_trifloat(PTA4); //Float voor EMG-waarde triceps +HIDScope scope(4); + +Ticker log_timer; +Ticker reset_timer; +MODSERIAL pc(USBTX,USBRX); PwmOut red(LED_RED); PwmOut green(LED_GREEN); @@ -19,20 +25,17 @@ int direction = 0; int force = 0; -Ticker log_timer; -Ticker reset_timer; -MODSERIAL pc(USBTX,USBRX); -HIDScope scope(4); + void looper() //nieuwe looper maken, die om een nog te bepalen tijdseenheid de emgtrifloat checked en anders nieuwe goto maakt naar vorige selectiekeuze { /*put raw emg value of biceps both in emg_bifloat and in emg_bivalue*/ - emg_bifloat.write(emg0.read()); // read float value (0..1 = 0..3.3V) biceps + emg_bifloat = emg0.read(); // read float value (0..1 = 0..3.3V) biceps uint16_t emg_bivalue; emg_bivalue = emg0.read_u16(); // read direct ADC result (0..4096 = 0..3.3V) biceps /*put raw emg value of triceps both in emg_trifloat and in emg_trivalue*/ - emg_trifloat.write(emg1.read()); // read float value (0..1 = 0..3.3V) triiceps + emg_trifloat = emg1.read(); // read float value (0..1 = 0..3.3V) triceps uint16_t emg_trivalue; emg_trivalue = emg1.read_u16(); // read direct ADC result (0..4096 = 0..3.3V) biceps @@ -44,9 +47,9 @@ /* EMG-singaal van biceps en triceps worden hier gefilterd*/ scope.set(0,emg_bivalue); - scope.set(1,emg_bifloat.read()); + scope.set(1,emg_bifloat); scope.set(2,emg_trivalue); - scope.set(3,emg_trifloat.read()); + scope.set(3,emg_trifloat); scope.send(); } @@ -64,8 +67,8 @@ int main() { pc.baud(115200); //baudrate instellen - emg_bifloat.period_ms(2); //sets period for the PWM to the emgfloat PTD4 - emg_trifloat.period_ms(2); +// emg_bifloat.period_ms(2); //sets period for the PWM to the emgfloat PTD4 +// emg_trifloat.period_ms(2); log_timer.attach(looper, 0.001); // The looper() function will be called every 0.001 seconds (with the ticker object) // reset_timer.attach(resetlooper, 0.1); // @@ -79,7 +82,7 @@ green=1; blue=1; for (int lag=0; lag<TIMEBETWEENBLINK; lag++) { - if(emg_bifloat.read()>0.8) { // 0.8 klopt niet als grenswaarde. #nofilter + if(emg_bifloat>0.8) { // 0.8 klopt niet als grenswaarde. #nofilter direction = 1; red=1; green = 0; @@ -97,7 +100,7 @@ green=0; blue=1; for (int lag=0; lag<TIMEBETWEENBLINK; lag++) { - if(emg_bifloat.read()>0.8) { //0.8 klopt niet als grenswaarde. #nofilter + if(emg_bifloat>0.8) { //0.8 klopt niet als grenswaarde. #nofilter direction = 2; red=0; green = 1; @@ -115,7 +118,7 @@ green=1; blue=0; for (int lag=0; lag<TIMEBETWEENBLINK; lag++) { - if(emg_bifloat.read()>0.8) { //0.8 klopt niet als grenswaarde. #nofilter + if(emg_bifloat>0.8) { //0.8 klopt niet als grenswaarde. #nofilter direction = 3; red=0; green = 0; @@ -141,7 +144,7 @@ goto directionchoice; } for (int lag=0; lag<TIMEBETWEENBLINK; lag++) { - if(emg_bifloat.read()>0.8) { // 0.8 klopt niet als grenswaarde. #nofilter + if(emg_bifloat>0.8) { // 0.8 klopt niet als grenswaarde. #nofilter force = 1; red=1; green = 0; @@ -162,7 +165,7 @@ goto directionchoice; } for (int lag=0; lag<TIMEBETWEENBLINK; lag++) { - if(emg_bifloat.read()>0.8) { //0.8 klopt niet als grenswaarde. #nofilter + if(emg_bifloat>0.8) { //0.8 klopt niet als grenswaarde. #nofilter force = 2; red=0; green = 1; @@ -183,7 +186,7 @@ goto directionchoice; } for (int lag=0; lag<TIMEBETWEENBLINK; lag++) { - if(emg_bifloat.read()>0.8) { //0.8 klopt niet als grenswaarde. #nofilter + if(emg_bifloat>0.8) { //0.8 klopt niet als grenswaarde. #nofilter force = 3; red=0; green = 0;