First Last
/
BMT-K9-Groep7
Initial version
Diff: main.cpp
- Revision:
- 2:60fc72e8ff66
- Parent:
- 1:3687c7cb0648
- Child:
- 3:57c5633df1ca
--- a/main.cpp Thu Oct 17 09:23:51 2013 +0000 +++ b/main.cpp Thu Oct 17 09:27:44 2013 +0000 @@ -10,8 +10,8 @@ Ticker timer; MODSERIAL pc(USBTX,USBRX,64,1024); -#define gain_biceps 1 -#define maxcount 50 +#define GAIN_BICEPS 1 +#define MAXCOUNT 50 #define NUM0 0.8841 // constante #define NUM1 -3.53647 // z^-1 @@ -33,13 +33,14 @@ /*value0 is huidig, 1 is t-1, 2 is t-2 etc. Gebruik later aanduidingen ABCD. */ char startup = 0; float mean; float sig_out_biceps; - float in0; float in1; float in2; float in3; float in4; - float out0; float out1; float out2; float out3; float out4; - + float in0,in1,in2,in3,in4; + float out0,out1,out2,out3,out4; + float emg_abs; // square, mean en count eerder gedefinieerd if (startup != 1) - {in0 = 0; in1 = 0; in2 = 0; in3 = 0; in4 = 0; - out0 = 0; out1 = 0; out2 = 0; out3 = 0; out4 = 0; - count = 0; square_biceps = 0; sum_biceps = 0; mean_biceps = 0.2; startup = 1;} + {in0 = in1 = in2 = in3 = in4 = 0; + out0 = out1 = out2 = out3 = out4 = 0; + count = 0; square_biceps = 0; sum_biceps = 0; mean_biceps = 0.2; startup = 1; + } in4 = in3; in3 = in4; in3 = in2; in2 = in1; in1 = in0; in0 = emg_biceps.read(); red = in0; @@ -53,14 +54,14 @@ /**When not using the LED, the above could also have been done this way: * pc.printf("%.6\n", emg0.read()); */ - float emg_abs; // square, mean en count eerder gedefinieerd + emg_abs = fabs(out0); mean = mean_biceps; sum_biceps += out0; square_biceps += (emg_abs - mean)*(emg_abs - mean); //neem absolute waarde, kwadrateer, voeg toe aan vorige square // voeg rest EMG's toe, variabelen alleen _spier geven als het nodig is. count += 1; // hou bij hoeveel squares er zijn opgeteld - if (count >= maxcount) + if (count >= MAXCOUNT) { sig_out_biceps = sqrt(square_biceps/count); mean_biceps = sum_biceps/count; count= 0; square_biceps = 0; sum_biceps = 0; // en neem de RMS als er genoeg zijn geteld, stuur die door, en reset sqaure en count