ksf
Dependents: kinematics_controlv2 kinematics_controlv4 kinematics_control_copyfds Robot_control
Revision 5:f3ddc3a7b292, committed 2017-11-01
- Comitter:
- peterknoben
- Date:
- Wed Nov 01 22:46:29 2017 +0000
- Parent:
- 4:a79f9f3a9e40
- 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 |
diff -r a79f9f3a9e40 -r f3ddc3a7b292 signalnumber.cpp --- a/signalnumber.cpp Wed Nov 01 22:23:10 2017 +0000 +++ b/signalnumber.cpp Wed Nov 01 22:46:29 2017 +0000 @@ -5,28 +5,14 @@ //Constants for mean value 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; - +int count1 = 0, count2 = 0, count3 = 0; //Counters for the mean values +int countx = 0, county = 0.0, countz = 0.0; //Counters for the signalnumbers +float meanL = 0.0, meanR = 0.0, meanM = 0.0; //Internal function calculation variables //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; -const float LeftSlowmax=0.35; -const float RightSlowmin=0.4; -const float RightSlowmax=0.65; -const float RightFastmin=0.7; -const float RightFastmax=10.5;*/ int NumberL = 0, NumberR =0; -//const int action =50; SignalNumber::SignalNumber(void) @@ -34,24 +20,9 @@ } - -/* -// Determine the mean value of the last "n" amount of numbers. -float SignalNumber::getmean(const int n, float input){ - emg_filtered[count] = input; - count++; - if (count == n){ - count = 0; - } - 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; -}*/ - - +//Determine the Left mean value +//"n" is the amount off samples over which the mean value is calculated +//"ipnut" is the inputsignal (filtered analog in) float SignalNumber::getmeanLeft(const int n, float input){ emg0_filtered[count1] = input; count1++; @@ -65,6 +36,10 @@ float mean_math = sum_math/n; return mean_math; } + +//Determine the Right mean value +//"n" is the amount off samples over which the mean value is calculated +//"ipnut" is the inputsignal (filtered analog in) float SignalNumber::getmeanRight(const int n, float input){ emg2_filtered[count2] = input; count2++; @@ -78,6 +53,11 @@ float mean_math = sum_math/n; return mean_math; } + +/* +//Determine the Mode mean value +//"n" is the amount off samples over which the mean value is calculated +//"ipnut" is the inputsignal (filtered analog in) float SignalNumber::getmeanMode(const int n, float input){ emg4_filtered[count3] = input; count3++; @@ -91,35 +71,34 @@ float mean_math = sum_math/n; return mean_math; } +*/ + +// Determine the offset by calculating the mean value for "n" samples float SignalNumber::calibrate(const int n, float 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){ + meanL = getmeanLeft(n, input); + //Check first case, standstill + if( meanL < LeftMin ) { + if (county < action){ + meanL = getmeanLeft(n, input); + if(meanL < LeftMin){ county++; } else{ - county=0; - NumberL=0; + county = 0; + NumberL = 0; } } else{ NumberL = 0; - county=0; + county = 0; } } - //Check second case + //Check second case, move slow else if(meanL >= LeftMin and meanL < LeftMax){ if (county <action){ meanL= getmeanLeft(n, input); @@ -136,6 +115,7 @@ county=0; } } + //Check third case, move fast else if( meanL>=LeftMax) { if (county <action){ meanL= getmeanLeft(n, input); @@ -152,6 +132,7 @@ county=0; } } + //If not working output zero else{ county=0; NumberL =0; @@ -161,7 +142,7 @@ int SignalNumber::getnumberRight(const int n, const int action, float input){ meanR= getmeanRight(n, input); - //Check first case + //Check first case, standstill if( meanR< LeftMin ) { if (countx <action){ meanR= getmeanRight(n, input); @@ -178,7 +159,7 @@ countx=0; } } - //Check second case + //Check second case, move slow else if(meanR >= LeftMin and meanR < LeftMax){ if (countx <action){ meanR= getmeanRight(n, input); @@ -195,6 +176,7 @@ countx=0; } } + //Check third case, move fast else if( meanR >=LeftMax ) { if (countx <action){ meanR= getmeanRight(n, input); @@ -211,6 +193,7 @@ countx=0; } } + //If not working output zero else{ countx=0; NumberR =0; @@ -219,137 +202,3 @@ } - - - - - - - - -//Determine the right signal number -/* -There will be checked in which range the mean value lies. If the value lies -within this range for "action" samples the switch will be changed to the right -mode. If the mean value changes outside of the region the switch will be set to -0, this is the resting state. Also the counter will be reset. -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){ - mean = getmean(n, input); - //Check first case - if( mean < LeftFastmin ) { - if (countx <action){ - mean = getmean(n, input); - if(mean < LeftFastmin){ - countx++; - } - else{ - countx=0; - Number=0; - } - } - else{ - Number = 0; - countx=0; - } - } - //Check second case - else if(mean <= LeftFastmax and mean > LeftFastmin){ - if (countx <action){ - mean = getmean(n, input); - if(mean <=LeftFastmax and mean>LeftFastmin){ - countx++; - } - else{ - countx=0; - Number=0; - } - } - else{ - Number = 1; - countx=0; - } - } - else if( mean <=LeftSlowmax and mean>LeftSlowmin) { - if (countx <action){ - mean = getmean(n, input); - if(mean <=LeftSlowmax and mean>LeftSlowmin){ - countx++; - } - else{ - countx=0; - Number=0; - } - } - else{ - Number = 2; - countx=0; - } - } - else if( mean <=RightSlowmax and mean>RightSlowmin) { - if (countx <action){ - mean = getmean(n, input); - if(mean <=RightSlowmax and mean>RightSlowmin){ - countx++; - } - else{ - countx=0; - Number=0; - } - } - else{ - Number = 3; - countx=0; - } - } - else if( mean <=RightFastmax and mean>RightFastmin ) { - if (countx <action){ - mean = getmean(n, input); - if(mean <=RightFastmax and mean>RightFastmin){ - countx++; - } - else{ - countx=0; - Number=0; - } - } - else{ - Number = 4; - countx=0; - } - } - else{ - countx=0; - Number =0; - } - return Number; -} */ - - -// In progress -/*int SignalNumber::getmode(const int n, const int action, float input){ - int mode; - mean = getmean(n, input); - //Check first case - if( mean < LeftFastmin ) { - if (countx <action){ - mean = getmean(n, input); - if(mean < LeftFastmin){ - countx++; - } - else{ - countx=0; - Number=0; - } - } - else{ - Number = 0; - countx=0; - } - } - return mode; -}*/ - -
diff -r a79f9f3a9e40 -r f3ddc3a7b292 signalnumber.h --- a/signalnumber.h Wed Nov 01 22:23:10 2017 +0000 +++ b/signalnumber.h Wed Nov 01 22:46:29 2017 +0000 @@ -17,13 +17,13 @@ float getmeanRight(const int n, float input); - float getmeanMode(const int n, float input); +// float getmeanMode(const int n, float input); // In progess int getnumberLeft(const int n, const int action, float input); int getnumberRight(const int n, const int action, float input); - int getmode(const int n, const int action, float input); // In progress +// int getmode(const int n, const int action, float input); // In progress private: