Algoritmo funcionando com a biblioteca de inatividade utilizando dos dados do acelerômetro e a biblioteca de PeakSearch se utilizando dos dados filtrados pelo filtro Kalman.

Dependencies:   mbed MatrixMath Matrix nrf51_rtc BMP180 MPU9250

Revision:
2:5d0d7997e461
Parent:
1:d1002dc109b9
Child:
3:db3f7831bcea
diff -r d1002dc109b9 -r 5d0d7997e461 main.cpp
--- a/main.cpp	Sat Mar 09 12:06:30 2019 +0000
+++ b/main.cpp	Wed Apr 03 22:52:28 2019 +0000
@@ -14,7 +14,6 @@
 #include "MPL3115A2.h"  // Barometer
 #include "MPU9250.h" //IMU
 
-
 #define ON 0
 #define OFF 1
 
@@ -35,7 +34,7 @@
 char day1[10],day2[10]; //Store the day, to check if the day changed
 int frame=0; //store the frames
 int BaudRate=115200; //OpenLog's BaudRate
-float TimeInterrupt=50000; //Interruption time in [us]   1/20000[us] =50[Hz]
+float TimeInterrupt=20000; //Interruption time in [us]   1/20000[us] =50[Hz] ESTÁ EM 50HZ
 float t1,t2; //time values
 double aa, ta; //altimeter and temperature values
 double ti; // temperature values - IMU
@@ -44,10 +43,21 @@
 bool flagPrint = true;
 
 //Teste DTW
-float AcceABS; //Valor absoluto aceleração
-float AcceABSF; //Valor absoluto aceleração filtrado
+float AcceABS=0; //Valor absoluto aceleração
+float AcceABSF=0; //Valor absoluto aceleração filtrado
 float alfa=0.8;
 
+//variaveis DTW global
+int TBS=0;
+int steps=0;
+float Calibration=33;
+bool flagStep=false;
+int iiDTW=0;
+int kkDTW=0;
+#define StepSize 73
+float Signal[StepSize+1];
+
+
 /////////////////Day and Time Configuration//////////////////////////////
 // TODO : Update through BLE
 char paciente[20]="TesteDTW";
@@ -81,7 +91,6 @@
     
     if (!flagNewCapture)
     {     
-        Open.printf("Get_Values \r\n");
         ////////////////////////////Getting MPU Values///////////////////////// 
         mpu9250.readAccelData(accelCount);  // Read the x/y/z adc values   
         
@@ -184,6 +193,7 @@
              uart->writeString("Steps: ");
              uart->writeString(alc);
              uart->writeString("\n");
+             Open.printf("Quantidade total de passos: %d",steps);
              return 0;
         }        
         if (flagNewCapture)
@@ -214,11 +224,33 @@
             mpu9250.MahonyQuaternionUpdate(ax, ay, az, gx, gy, gz, my, mx, mz);    
             aa=Sensor1.Altitude_m();
             ta=Sensor1.Temp_C();  
+            wait_us(1);
             //////////////////////////// Is there a new step? //////////////////
-            SubDTW();
+            if (iiDTW>StepSize)
+            {
+                Open.printf("iiDTW>StepSize \r\n");
+                int jjDTW;
+                for (jjDTW=0;jjDTW<=(StepSize-1);jjDTW=jjDTW+1)
+               {
+                    Signal[jjDTW]=Signal[jjDTW+1];
+               }
+                Signal[StepSize]=AcceABSF;
+                kkDTW=kkDTW+1;
+                
+               if (kkDTW>=50);
+                {
+                    kkDTW=0;
+                    SubDTW();
+                }
+            }
+            else
+            {
+                Signal[iiDTW]=AcceABSF;
+                iiDTW=iiDTW+1;
+                kkDTW=kkDTW+1;
+            }  
 
             
-
             if (flagPrint==true)
             {
         ////////////////////////////Printing Values/////////////////////////  
@@ -234,11 +266,11 @@
                     new_file(); //cria novo arquivo
                     ask_day(day1);
                 } // end if     
-                //////////////////////////////////////////////////////////////////////////////////////////////     
+        //////////////////////////////////////////////////////////////////////////////////////////////     
                 if (flagStep==true)
                 {
-                    Open.printf(buff);      //Printing values on the SD card      
-                } //end if flag step 
+                    Open.printf(buff);      //Printing values on the SD card   
+                } //end if flag step
                 
                 flagNewCapture = false; 
                 t2=t.read_us();
@@ -250,7 +282,6 @@
                 led=ON;
                 flagPrint=false;
             } //end if flag print        
-            
             else
             {
                 flagPrint=true;