2016-07-24 16 views
0

danke für die Hilfe mit meinem vorherigen Problem. Ich bin jetzt in der Lage, die Daten aus dem Arduino zu PC mit Kitt mit dem FSR an einer Sohle und Erkennung von Drücken zu bekommen.Arduino Nano Datenpunkte fehlen

Das einzige Problem, das ich jetzt bin vor ist, dass es Fälle von Heel Streichen und Toe zu sein scheint ab und zu Off fehlt. (Bild angehängt) Plot of data

blaue Linie stellt Daten von Heel FSR und Roter Linie für Toe FSR Es ist aus dem Bild zu sehen, dass das Arduino einen Heel Strike bei blau gefärbter Spitze Nr. 3 und einen Zehe OFF Moment bei roter Spitze 5 vom Ende fehlt.

Kann jemand mir sagen, warum dies regelmäßig geschieht .. Ich bin mit Arduino Nano mit Baudraten 9600 und 2 FSR ..auf die Baudrate über 38400 Erhöhung der Verlust häufiger

/aufzutreten scheint ** Code findet Instanzen Zehe ab und Fersenauftreffposition Daten von FSR mit */

void setup() 
    { 

     /*************************************************SERIAL**************************************************/ 
     Serial.begin(9600); 


    } 

    /*Variables for FSRS*/ 
    //A0= Toe,A1=Heel 
    int sum_toe_max = 0,sum_toe_min = 0, sum_heel_max = 0, sum_heel_min = 0 ,toe, heel, temp,diff_toe,diff_heel,data_heel=0, data_toe=0,    data_toe2, data_heel2 ; 
    int heel_max[5] = {0, 0, 0, 0, 0}, toe_max[5] = {0, 0, 0, 0, 0}; /*These arrays holds the top 5 maximas upto the time of calibration*/ 
    int heel_min[5]= {100,100,100,100,100}, toe_min[5]={100,100,100,100,100};/*These arrays holds the top 5 maximas upto the time of   calibration*/ 
    float avg_heel_max,avg_heel_min,avg_toe_max,avg_toe_min;/*variables to hold the averages of the valus of max and min arrays*/ 
    float UL=0.80,LL=0.05;/* Setting the Limiters*/ 
    int counter_toe_max = 0, counter_heel_max = 0,counter_toe_min = 0, counter_heel_min = 0;//counter for the number of H and T occured 
    int cal_limit = 10;/*time for which calibration should go on*/ 
    int timer = 0;/*stores the time elapsed*/ 

    void loop() 
    { 

     read_FSR();//Call The FSR function 
     //read_acc(); 


    } 


    /*********************************************FSR_TOE***********************************************/ 
         /*Function to read the FSR_TOE data and save to SD*/ 
         void read_FSR() 
         { 


          data_toe = analogRead(A0); 
          data_heel = analogRead(A1); 
          timer = millis()/1000; 

          Serial.print(millis()); 
          Serial.print(" ");        
          Serial.print(data_toe); 
          Serial.print(" "); 
          Serial.println(data_heel);  






          /*Calibration and finding the maxima uptil cal_limit seconds.*/ 
          if (timer < cal_limit) 
          { 


          /*TOE calibration*/ 

          /*To find the top 5 max pressures*/ 
          if (data_toe > toe_max[counter_toe_max]) 
          { 
           toe_max[counter_toe_max] =data_toe;                         
           counter_toe_max = counter_toe_max + 1; 


          } 
          if (counter_toe_max >= 5) 
          { 
           counter_toe_max = 0; 
          } 



          /*To find the top 5 min pressures*/ 
          if (data_toe < toe_max[counter_toe_min]) 
          { 
           toe_min[counter_toe_min] = data_toe;         
           counter_toe_min = counter_toe_min + 1; 

          } 
          if (counter_toe_min >= 5) 
          { 
           counter_toe_min = 0; 
          } 

          /*HEEL FSR calibration*/ 
          /*To find the top 5 max pressures*/ 

          if (data_heel > heel_max[counter_heel_max]) 
          { 
           heel_max[counter_heel_max] =data_heel;                           
           counter_heel_max = counter_heel_max + 1; 

          } 
          if (counter_heel_max >= 5) 
          { 
           counter_heel_max = 0; 
          } 


          /*To find the top 5 min pressures*/ 
          if (data_heel < heel_min[counter_heel_min]) 
          { 
           heel_min[counter_heel_min]=data_heel; =                   
           counter_heel_min = counter_heel_min + 1; 

          } 
          if (counter_heel_min >= 5) 
          { 
           counter_heel_min = 0; 
          } 


          } 




          /*Displaying the maximum and minimum valus array and finding the averages for both the FSR's*/ 
          if (timer == cal_limit && temp == 0) 
          { 


          /*Finding sum of the array elements*/ 
          for (int i = 0; i < 5; i++) 
          { 
           sum_toe_max = sum_toe_max + toe_max[i]; 
           sum_toe_min = sum_toe_min + toe_min[i]; 


          } 

          for (int i = 0; i < 5; i++) 
          { 
           sum_heel_max = sum_heel_max + heel_max[i]; 
           sum_heel_min = sum_heel_min + heel_min[i]; 


          } 

          avg_toe_max = sum_toe_max/5;/*dividing by 5 to get the avg of the 5 values*/ 
          avg_toe_min = sum_toe_min/5; 


          avg_heel_max = sum_heel_max/5; 
          avg_heel_min = sum_heel_min/5; 

          diff_toe = avg_toe_max-avg_toe_min;/*difference between maximas and minimas*/ 
          diff_heel = avg_heel_max-avg_heel_min ; 




          Serial.println(); 
          Serial.print(F("Avg ToePress max ")); 
          Serial.println(avg_toe_max); 
          Serial.print(F("Avg ToePress min ")); 
          Serial.println(avg_toe_min); 
          Serial.print(F("Avg HeelPress max ")); 
          Serial.println(avg_heel_max); 
          Serial.print(F("Avg HeelPress min ")); 
          Serial.println(avg_heel_min); 
          Serial.print(F("Diff in avg toe press:")); 
          Serial.println(diff_toe); 
          Serial.print(F("Diff in avg heel press:")); 
          Serial.println(diff_heel); 
          Serial.print(F("Target HeelPress ")); 
          Serial.println(UL*(avg_heel_max-avg_heel_min)); 
          Serial.print(F("Target ToePress ")); 
          Serial.println(LL*(avg_toe_max-avg_toe_min)); 


          temp = temp + 1; 
          } 
          /*Done with calibration(when timer =10s)*/ 




          /*Checking the oncoming data for a condition of Toe Off 
          Consider it as a toe off if the normalised value of data_toe i.e (data_toe-avg_toe_min)/diff_toe 
          at the previous instant is greater than LL(Lower Limit) i.e 0.2 times the differnce between the       averages of max and min of toe FSR 
          and the normalised value of data_toe2 at the current instant is lesser than the same*/ 

          if (timer > cal_limit && (data_toe-avg_toe_min)/diff_toe > LL) 
          { 
          data_toe2 = analogRead(A0);/*Data toe at the current instant*/ 

          if ((data_toe2-avg_toe_min)/diff_toe < LL) 
          { 

    //          
            Serial.print(timer*1000); 
            Serial.print(" "); 
            Serial.print(("f t T ")); 
            Serial.print(data_toe); 
            Serial.print("Avg min "); 
            Serial.print(avg_toe_min); 
            Serial.print("Diff "); 
            Serial.print(diff_toe); 
            Serial.println(" TOE"); 




          } 


          } 

          /*Checking the oncoming data for a condition of Heel Stike 
          Consider it as a Heel Strike if the normalised value of data_heel i.e (data_heel2-avg_heel_max)/diff_heel 
          at the previous instant is lesser than UL(Lower Limit) i.e 0.8 times the differnce between the       averages of max and min of heel FSR 
          and the normalised value of data_heel2 at the current instant is greater than the same*/ 

         if(timer>cal_limit && (data_heel-avg_heel_min)/diff_heel<=UL) 
          { 

          data_heel2=analogRead(A1);/*Data heel at the current instant*/ 
          if((data_heel2-avg_heel_min)/diff_heel>=UL) 
          { 


           Serial.print(timer*1000); 
           Serial.print(" "); 
           Serial.print(("f t H ")); 
           Serial.print(data_heel); 
           Serial.print(" HEEL"); 
           Serial.println(UL); 
           Serial.flush(); 





          } 

          } 





         } 
+2

dropping 100s Zeilen Code ist nicht wahrscheinlich, um Ihnen eine Antwort zu erhalten. Bitte bemühen Sie sich um eine [mcve] – Julien

Antwort

0

Wie Sie die SD-Nutzung entfernt haben, könnten Sie auch die #include entfernen Hat das Einfluss auf Ihre Speicheranforderungen? (Oder sogar das schlechte Verhalten?) Freezing statt Reset ist in der Regel die gleiche Ursache, nur einige andere Adresse zu treffen. ;)

ich nicht keinen Array außerhalb der Grenzen Problems mit dem aktuellen Code sehen, aber das ist, wo ich/triple-Check ...

Andere Fragen

verdoppeln würde:

  • I2C (Wire): Sie fordern 14 Bytes an, lesen aber nur 2 davon? ...
  • Start ist ein float? dt sollte 0.0 sein, ich denke
+0

Danke @datafiddler Ihr Vorschlag funktioniert. Funktioniert wie Charme jetzt – Aniket

+0

Welches? ;) Entfernen der #include Ich nehme an? – datafiddler

+0

Ja .. Genau ... – Aniket

2

Sie definieren String arr[2][2]={{""}}; aber die späteren Zugriff mit arr[SD_savr][3]="TO";, arr[SD_savr][4]=Y[0]; und arr[SD_savr][3]="HS";, die außerhalb der Grenzen und verursachen undefiniertes Verhalten, was die mögliche Ursache für das Zurücksetzen ist.

+0

Danke für die Mühe Laurenz und @Julien. Ich habe den Code wie in Ihrem Vorschlag geändert und versucht, ihn leserlicher zu machen, indem Sie die unnecessären Teile entfernen. Es bleibt mit luk ein bisschen lng. Aber wenn ich etwas entferne, wird es nicht wie gewünscht funktionieren. Ich stehe vor einem neuen Problem mit meinem Code. Whenvr Ich nenne Bot die Methds jetzt, die serielle Monitr frezes nach einigen Iteratons.Dieses Problem tritt auf, wenn ich eine der Methoden auskommentieren..Nie Art von Hilfe wird geschätzt. Ich schließe den neuen Code oben anstelle der alten ein ein. – Aniket