Arthur de Lange
/
Filter_check
12-okt
Fork of Filter_check by
Diff: main.cpp
- Revision:
- 2:7e0279519cbf
- Parent:
- 0:5c4ee2c81f02
- Child:
- 3:3e5d899a3c8a
diff -r 5c4ee2c81f02 -r 7e0279519cbf main.cpp --- a/main.cpp Thu Oct 12 10:19:08 2017 +0000 +++ b/main.cpp Thu Oct 12 13:11:30 2017 +0000 @@ -16,20 +16,22 @@ double emgb = emg1.read(); //EMG2 //Aanmaken filter variabelen -float ah[3]={1, 0, 0.1716}; -float bh[3]={0.2929, -0.5858, 0.2929}; +double ah[3]={1, 0, 0.1716}; +double bh[3]={0.2929, -0.5858, 0.2929}; //innitial conditions high pass filter -float emg_hpf[3]={0, 0, 0}; -float emg_in[3]={0, 0, 0}; +double emg_hpf[3]={0, 0, 0}; +double emg_in[3]={0, 0, 0}; // coëfficienten high pass filter -float al[3]={1, -1.7347, 0.7660}; -float bl[3]={0.0078, 0.0156, 0.0078}; +double al[3]={1, -1.7347, 0.7660}; +double bl[3]={0.0078, 0.0156, 0.0078}; //innitial conditions low pass filter -float emg_lpf[3]={0, 0, 0}; -float emg_abs[3]={0, 0, 0}; +double emg_lpf[3]={0, 0, 0}; +double emg_abs[3]={0, 0, 0}; + +double emg_lpfg; //Aanmaken van de verschillende tickers Ticker tick_sample; @@ -41,7 +43,7 @@ emga = emg0.read(); emgb = emg1.read(); - emg_in[0]=emga; + emg_in[0]=emga-emgb; //Filter // high pass filter @@ -64,10 +66,11 @@ emg_abs[1]=emg_abs[0]; emg_lpf[2]=emg_lpf[1]; emg_lpf[1]=emg_lpf[0]; + emg_lpfg = 5* emg_lpf[1]; if (emg_lpf[1]>0.05) { - motor1MagnitudePin = emg_lpf[1]; + motor1MagnitudePin = emg_lpfg; motor1DirectionPin = 0; } else @@ -75,13 +78,12 @@ motor1MagnitudePin = 0; motor1DirectionPin = 0; } - scope.set(0, emg0.read()); - scope.send(); - scope.set(1, emg_lpf[1]); + scope.set(0, emg_in[0]); + scope.set(1, emg_lpfg); scope.send(); timer.stop(); - pc.printf("time taken was %f milliseconds\n\r", timer.read_ms()); + pc.printf("time taken was %f milliseconds\n\r", timer.read_us()); } @@ -89,6 +91,6 @@ int main() { //Deze tickers roepen de verschillende voids aan - pc.baud(9600); + pc.baud(115200); tick_sample.attach_us(&aansturing, 5000); //Deze ticker roept de potmeter aan }