Arduino nano数据点缺失

时间:2016-07-24 08:03:35

标签: arduino reset

感谢您帮我解决以前的问题。 我现在能够使用带有FSR的腻子和检测压力将数据从arduino传送到PC。

我现在面临的唯一问题是它似乎偶尔会缺少脚后跟和脚趾的实例。(附图)Plot of data

蓝线表示来自脚跟FSR的数据和针对Toe FSR的红线 从图片中可以看出,arduino在蓝色3号峰值处缺少脚跟打击,在结束时红色峰值5处缺少脚趾关闭瞬间。

任何人都可以告诉我为什么会这种情况经常发生.. 我正在使用具有波特率9600和2 FSR的arduino nano。如果将波特率增加到38400以上,则损失似乎更频繁发生

/ **代码使用来自FSR的数据* /

查找脚趾关闭和脚后跟撞击的实例
    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 个答案:

答案 0 :(得分:2)

您定义String arr[2][2]={{""}};但稍后使用arr[SD_savr][3]="TO";arr[SD_savr][4]=Y[0];arr[SD_savr][3]="HS";访问它,这超出范围并导致未定义的行为,这可能是你重置的原因。

答案 1 :(得分:0)

当您删除SD使用时,您是否也可以删除#include 这会影响您的记忆要求吗? (甚至是不良行为?) 冻结而不是重置通常是相同的原因,只是点击其他地址。 ;)

我不能看到当前代码的任何数组越界问题,但那是我加倍/三重检查...

其他问题:

  • I2C(有线):您请求14个字节,但只能读取其中的2个字节? ...
  • 开始是一个浮动? dt应为0.0,我想