Working, Clean

Dependents:   ShowItv2 ShowIt_robot_control

Fork of SignalNumber by Dustin Berendsen

Revision:
7:893503895342
Parent:
6:7f6e2d293154
Child:
8:9098c6b1897b
--- a/signalnumber.cpp	Thu Nov 02 10:17:26 2017 +0000
+++ b/signalnumber.cpp	Thu Nov 02 15:08:55 2017 +0000
@@ -2,17 +2,18 @@
 #include "mbed.h"
 
 
+//------------------------------------------------------------------------------
 //Constants for mean value
-const int n = 500;                   //Window size for the mean value
-float emg0_filtered[n] = {}, emg2_filtered[n] = {}, emg4_filtered[n]={}; 
-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
+const int n = 500;                               //Window size for the mean value
+float emg0_filtered[n] = {}, emg2_filtered[n] = {}; 
+int count1 = 0, count2 = 0;  //Counters for the mean values
+int countx = 0, county = 0.0;     //Counters for the signalnumbers
+float meanL = 0.0, meanR = 0.0;    //Internal function calculation variables
 
 //Constants EMG switch
-const float LeftMin = 0.20;
-const float LeftMax = 0.50;
-int NumberL = 0, NumberR =0;
+const float MinTreshold = 0.20;
+const float MaxTreshold = 0.50;
+int SpeedL = 0, SpeedR =0;
 
 
 SignalNumber::SignalNumber(void)
@@ -20,6 +21,7 @@
 
 }
 
+//------------------------------------------------------------------------------
 //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)
@@ -37,6 +39,7 @@
     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)
@@ -54,151 +57,134 @@
     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++;
-    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;
-}
-*/
-
+//------------------------------------------------------------------------------
 // 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){
+//------------------------------------------------------------------------------
+//
+int SignalNumber::getspeedLeft(const int n, const int action, float input){
     meanL = getmeanLeft(n, input);
     //Check first case, standstill
-    if( meanL < LeftMin ) {
+    if( meanL < MinTreshold ) {
         if (county < action){
             meanL = getmeanLeft(n, input);
-            if(meanL < LeftMin){
+            if(meanL < MinTreshold){
                 county++;
             }
             else{
                 county = 0;
-                NumberL = 0;
+                SpeedL = 0;
             } 
         }
         else{
-            NumberL = 0;
+            SpeedL = 0;
             county = 0;
         }
     }
      //Check second case, move slow  
-     else if(meanL >= LeftMin and meanL < LeftMax){
+     else if(meanL >= MinTreshold and meanL < MaxTreshold){
         if (county <action){
             meanL= getmeanLeft(n, input);
-            if(meanL >= LeftMin and meanL < LeftMax){
+            if(meanL >= MinTreshold and meanL < MaxTreshold){
                 county++;
             }
             else{
                 county=0;
-                NumberL=0;
+                SpeedL=0;
             } 
         }
         else{
-            NumberL = 1;
+            SpeedL = 1;
             county=0;
         }
     }
     //Check third case, move fast
-     else if( meanL>=LeftMax) {
+     else if( meanL>=MaxTreshold) {
         if (county <action){
             meanL= getmeanLeft(n, input);
-            if(meanL>=LeftMax){
+            if(meanL>=MaxTreshold){
                 county++;
             }
             else{
                 county=0;
-                NumberL=0;
+                SpeedL=0;
             } 
         }
         else{
-            NumberL = 2;
+            SpeedL = 2;
             county=0;
         }
     }
     //If not working output zero
     else{
         county=0;
-        NumberL =0;
+        SpeedL =0;
     }
-    return NumberL;
+    return SpeedL;
 }       
 
-int SignalNumber::getnumberRight(const int n, const int action, float input){
+//------------------------------------------------------------------------------
+int SignalNumber::getspeedRight(const int n, const int action, float input){
     meanR= getmeanRight(n, input);
     //Check first case, standstill
-    if( meanR< LeftMin ) {
-        if (countx <action){
+    if( meanR< MinTreshold ) {
+        if (countx < action){
             meanR= getmeanRight(n, input);
-            if(meanR< LeftMin){
+            if(meanR< MinTreshold){
                 countx++;
             }
             else{
                 countx=0;
-                NumberR=0;
+                SpeedR=0;
             } 
         }
         else{
-            NumberR = 0;
+            SpeedR = 0;
             countx=0;
         }
     }
      //Check second case, move slow 
-     else if(meanR >= LeftMin and meanR < LeftMax){
+     else if(meanR >= MinTreshold and meanR < MaxTreshold){
         if (countx <action){
             meanR= getmeanRight(n, input);
-            if(meanR >= LeftMin and meanR < LeftMax){
+            if(meanR >= MinTreshold and meanR < MaxTreshold){
                 countx++;
             }
             else{
                 countx=0;
-                NumberR=0;
+                SpeedR=0;
             } 
         }
         else{
-            NumberR = 1;
+            SpeedR = 1;
             countx=0;
         }
     }
     //Check third case, move fast
-     else if( meanR >=LeftMax ) {
+     else if( meanR >=MaxTreshold ) {
         if (countx <action){
             meanR= getmeanRight(n, input);
-            if( meanR >=LeftMax ){
+            if( meanR >=MaxTreshold ){
                 countx++;
             }
             else{
                 countx=0;
-                NumberR=0;
+                SpeedR=0;
             } 
         }
         else{
-            NumberR = 2;
+            SpeedR = 2;
             countx=0;
         }
     }
     //If not working output zero
     else{
         countx=0;
-        NumberR =0;
+        SpeedR =0;
     }
-    return NumberR;
-}       
-
-
+    return SpeedR;
+}       
\ No newline at end of file