ksf
Dependents: kinematics_controlv2 kinematics_controlv4 kinematics_control_copyfds Robot_control
Revision 4:a79f9f3a9e40, committed 2017-11-01
- Comitter:
- peterknoben
- Date:
- Wed Nov 01 22:23:10 2017 +0000
- Parent:
- 3:f8d57796d69b
- Child:
- 5:f3ddc3a7b292
- Commit message:
- working
Changed in this revision
signalnumber.cpp | Show annotated file Show diff for this revision Revisions of this file |
signalnumber.h | Show annotated file Show diff for this revision Revisions of this file |
--- a/signalnumber.cpp Wed Nov 01 14:11:14 2017 +0000 +++ b/signalnumber.cpp Wed Nov 01 22:23:10 2017 +0000 @@ -3,15 +3,20 @@ //Constants for mean value -const int n = 400; //Window size for the mean value -float emg_filtered[n] = {}; -int count = 0; -int count2 = 0; -float mean = 0.0; +const int n = 1500; //Window size for the mean value +float emg0_filtered[n] = {}, emg2_filtered[n] = {}, emg4_filtered[n]={}; +int count1 = 0, count2 = 0, count3 = 0; +int countx = 0, county = 0.0, countz = 0.0; +float meanL = 0.0, meanR = 0.0, meanM = 0.0; float sum = 0.0; //Constants EMG switch +const float LeftMin = 0.20; +const float LeftMax = 0.50; +/* + + const float LeftFastmin=0.075; const float LeftFastmax=0.15; const float LeftSlowmin=0.2; @@ -19,8 +24,8 @@ const float RightSlowmin=0.4; const float RightSlowmax=0.65; const float RightFastmin=0.7; -const float RightFastmax=10.5; -int Number = 0; +const float RightFastmax=10.5;*/ +int NumberL = 0, NumberR =0; //const int action =50; @@ -30,18 +35,7 @@ } - -//Determine the sum of the last "n" amount of numbers. -float SignalNumber::getsum(float array[], const int n){ - float sum_math = 0.0; - for (int m=0 ; m<n ; m++ ){ - sum_math = sum_math + array[m]; - } - return sum_math; -} - - - +/* // Determine the mean value of the last "n" amount of numbers. float SignalNumber::getmean(const int n, float input){ emg_filtered[count] = input; @@ -49,21 +43,190 @@ if (count == n){ count = 0; } - float mean_math = getsum(emg_filtered,n)/n; + float sum_math = 0.0; + for (int m=0 ; m<n ; m++ ){ + sum_math = sum_math + emg_filtered[m]; + } + float mean_math = sum_math/n; + return mean_math; +}*/ + + +float SignalNumber::getmeanLeft(const int n, float input){ + emg0_filtered[count1] = input; + count1++; + if (count1 == n){ + count1 = 0; + } + float sum_math = 0.0; + for (int m=0 ; m<n ; m++ ){ + sum_math = sum_math + emg0_filtered[m]; + } + float mean_math = sum_math/n; + return mean_math; +} +float SignalNumber::getmeanRight(const int n, float input){ + emg2_filtered[count2] = input; + count2++; + if (count2 == n){ + count2 = 0; + } + float sum_math = 0.0; + for (int m=0 ; m<n ; m++ ){ + sum_math = sum_math + emg2_filtered[m]; + } + float mean_math = sum_math/n; + return mean_math; +} +float SignalNumber::getmeanMode(const int n, float input){ + emg4_filtered[count3] = input; + count3++; + if (count3 == n){ + count3 = 0; + } + float sum_math = 0.0; + for (int m=0 ; m<n ; m++ ){ + sum_math = sum_math + emg4_filtered[m]; + } + float mean_math = sum_math/n; return mean_math; } -/* -float SignalNumber::getmean(float array[], const int n, float input){ - float sum_math = 0; - - -} -*/ float SignalNumber::calibrate(const int n, float input){ - float offset = getmean(n, input); + float offset = getmeanLeft(n, input); return offset; } + + + + +int SignalNumber::getnumberLeft(const int n, const int action, float input){ + meanL= getmeanLeft(n, input); + //Check first case + if( meanL< LeftMin ) { + if (county <action){ + meanL= getmeanLeft(n, input); + if(meanL< LeftMin){ + county++; + } + else{ + county=0; + NumberL=0; + } + } + else{ + NumberL = 0; + county=0; + } + } + //Check second case + else if(meanL >= LeftMin and meanL < LeftMax){ + if (county <action){ + meanL= getmeanLeft(n, input); + if(meanL >= LeftMin and meanL < LeftMax){ + county++; + } + else{ + county=0; + NumberL=0; + } + } + else{ + NumberL = 1; + county=0; + } + } + else if( meanL>=LeftMax) { + if (county <action){ + meanL= getmeanLeft(n, input); + if(meanL>=LeftMax){ + county++; + } + else{ + county=0; + NumberL=0; + } + } + else{ + NumberL = 2; + county=0; + } + } + else{ + county=0; + NumberL =0; + } + return NumberL; +} + +int SignalNumber::getnumberRight(const int n, const int action, float input){ + meanR= getmeanRight(n, input); + //Check first case + if( meanR< LeftMin ) { + if (countx <action){ + meanR= getmeanRight(n, input); + if(meanR< LeftMin){ + countx++; + } + else{ + countx=0; + NumberR=0; + } + } + else{ + NumberR = 0; + countx=0; + } + } + //Check second case + else if(meanR >= LeftMin and meanR < LeftMax){ + if (countx <action){ + meanR= getmeanRight(n, input); + if(meanR >= LeftMin and meanR < LeftMax){ + countx++; + } + else{ + countx=0; + NumberR=0; + } + } + else{ + NumberR = 1; + countx=0; + } + } + else if( meanR >=LeftMax ) { + if (countx <action){ + meanR= getmeanRight(n, input); + if( meanR >=LeftMax ){ + countx++; + } + else{ + countx=0; + NumberR=0; + } + } + else{ + NumberR = 2; + countx=0; + } + } + else{ + countx=0; + NumberR =0; + } + return NumberR; +} + + + + + + + + + + //Determine the right signal number /* There will be checked in which range the mean value lies. If the value lies @@ -73,120 +236,120 @@ n is the amount of samples in the window action is the amount of same mean values */ -int SignalNumber::getnumber(const int n, const int action, float input){ +/*int SignalNumber::getnumber(const int n, const int action, float input){ mean = getmean(n, input); //Check first case if( mean < LeftFastmin ) { - if (count2 <action){ + if (countx <action){ mean = getmean(n, input); if(mean < LeftFastmin){ - count2++; + countx++; } else{ - count2=0; + countx=0; Number=0; } } else{ Number = 0; - count2=0; + countx=0; } } //Check second case else if(mean <= LeftFastmax and mean > LeftFastmin){ - if (count2 <action){ + if (countx <action){ mean = getmean(n, input); if(mean <=LeftFastmax and mean>LeftFastmin){ - count2++; + countx++; } else{ - count2=0; + countx=0; Number=0; } } else{ Number = 1; - count2=0; + countx=0; } } else if( mean <=LeftSlowmax and mean>LeftSlowmin) { - if (count2 <action){ + if (countx <action){ mean = getmean(n, input); if(mean <=LeftSlowmax and mean>LeftSlowmin){ - count2++; + countx++; } else{ - count2=0; + countx=0; Number=0; } } else{ Number = 2; - count2=0; + countx=0; } } else if( mean <=RightSlowmax and mean>RightSlowmin) { - if (count2 <action){ + if (countx <action){ mean = getmean(n, input); if(mean <=RightSlowmax and mean>RightSlowmin){ - count2++; + countx++; } else{ - count2=0; + countx=0; Number=0; } } else{ Number = 3; - count2=0; + countx=0; } } else if( mean <=RightFastmax and mean>RightFastmin ) { - if (count2 <action){ + if (countx <action){ mean = getmean(n, input); if(mean <=RightFastmax and mean>RightFastmin){ - count2++; + countx++; } else{ - count2=0; + countx=0; Number=0; } } else{ Number = 4; - count2=0; + countx=0; } } else{ - count2=0; + countx=0; Number =0; } return Number; -} +} */ // In progress -int SignalNumber::getmode(const int n, const int action, float input){ +/*int SignalNumber::getmode(const int n, const int action, float input){ int mode; mean = getmean(n, input); //Check first case if( mean < LeftFastmin ) { - if (count2 <action){ + if (countx <action){ mean = getmean(n, input); if(mean < LeftFastmin){ - count2++; + countx++; } else{ - count2=0; + countx=0; Number=0; } } else{ Number = 0; - count2=0; + countx=0; } } return mode; -} +}*/
--- a/signalnumber.h Wed Nov 01 14:11:14 2017 +0000 +++ b/signalnumber.h Wed Nov 01 22:23:10 2017 +0000 @@ -13,12 +13,16 @@ float calibrate(const int n, float input); - float getsum(float array[], const int n); + float getmeanLeft(const int n, float input); + + float getmeanRight(const int n, float input); + + float getmeanMode(const int n, float input); + + int getnumberLeft(const int n, const int action, float input); - float getmean(const int n, float input); + int getnumberRight(const int n, const int action, float input); - int getnumber(const int n, const int action, float input); - int getmode(const int n, const int action, float input); // In progress