This is a repository for code relating to mbed Fitness Tracker

Dependencies:   mbed PulseSensor2 SCP1000 mbed-rtos 4DGL-uLCD-SE LSM9DS1_Library_cal PinDetect FatFileSystemCpp GP-20U7

Files at this revision

API Documentation at this revision

Comitter:
memig3
Date:
Tue Mar 31 14:58:23 2020 +0000
Parent:
16:b5bae4fa476e
Child:
18:9617bd66bdae
Commit message:
filtered data collection;

Changed in this revision

data_collection.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/data_collection.cpp	Sun Mar 29 21:56:45 2020 +0000
+++ b/data_collection.cpp	Tue Mar 31 14:58:23 2020 +0000
@@ -11,21 +11,39 @@
 
 int main() {
     myled = 0;
-    set_time(1256729737);
-    time_t seconds;
+    float time = 0;
     IMU.begin();
     IMU.calibrate(1);
+    float ax;
+    float ay;
+    float az;
+    //float prevMag = 0;
+    float mag = 0;
+    //float lpValue;
+    //float alpha = 0.5;
+    float buffer[2] = {0};
+    float avg;
     mkdir("/sd/mydir", 0777);
     FILE *fp = fopen("/sd/mydir/data.txt", "w");
     if(fp == NULL) {
         error("Could not open file for write\n");
     }
-    fprintf(fp, "time, pressure (Pa), ax (Gs), ay (Gs), az (Gs)\n");
+    fprintf(fp, "time, pressure (Pa), ax (Gs), ay (Gs), az (Gs), lowpassed magnitude (Gs)\n");
     while(1) {
-        seconds = time(NULL);
         IMU.readAccel();
-        fprintf(fp, "0, %d, %f, %f, %f\n", scp1000.readPressure(), IMU.calcAccel(IMU.ax), IMU.calcAccel(IMU.ay), IMU.calcAccel(IMU.az)); 
+        ax = IMU.calcAccel(IMU.ax);
+        ay = IMU.calcAccel(IMU.ay);
+        az = IMU.calcAccel(IMU.az);
+        //prevMag = lpValue;
+        mag = sqrt((ax*ax) + (ay*ay) + (az*az));
+        //lpValue = (alpha * prevMag) + (1 - alpha) * mag;
+        avg = (buffer[0] + buffer[1] + mag) / 3;
+        buffer[0] = buffer[1];
+        buffer[1] = mag;
+        fprintf(fp, "%f, %d, %f, %f, %f, %f\n", time, scp1000.readPressure(), ax, ay, az, avg); 
+        pc.printf("%f, %d, %f, %f, %f, %f\r\n", time, scp1000.readPressure(), ax, ay, az, avg); 
+        time = time + .005;
         myled = 1;
-        wait(0.01);
+        wait(0.005);
     }
 }