For Josie

Dependencies:   MMA8451Q mbed nRF24L01P

Fork of Acclerometer_node by Sensor CDT

Files at this revision

API Documentation at this revision

Comitter:
oaa36
Date:
Thu Jul 23 11:00:23 2015 +0000
Parent:
5:9195756445e4
Child:
7:bade9a130c05
Commit message:
James's Edit

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Thu Jul 23 10:51:17 2015 +0000
+++ b/main.cpp	Thu Jul 23 11:00:23 2015 +0000
@@ -3,6 +3,7 @@
 #include "MMA8451Q.h"
 
 #define MMA8451_I2C_ADDRESS (0x1d<<1)
+#define TRANSFER_SIZE 24
 
 Serial pc(USBTX, USBRX); // tx, rx
 
@@ -19,13 +20,9 @@
 #include <iostream>
 
 
-int main()
-{
-
+int main() {
     MMA8451Q acc(SDA, SCL, MMA8451_I2C_ADDRESS);
 
-#define TRANSFER_SIZE   24
-
     char txData[TRANSFER_SIZE], rxData[TRANSFER_SIZE];
     int txDataCnt = 0;
     int rxDataCnt = 0;
@@ -70,12 +67,9 @@
     my_nrf24l01p.setReceiveMode();
     my_nrf24l01p.enable();*/
 
-
-
     printf("MMA8451 ID: %d\n", acc.getWhoAmI());
 
     while (1) {
-
         float x, y, z, sum, root;
         float average_x, average_y, average_z;
         float variance_x, variance_y, variance_z;
@@ -102,9 +96,6 @@
         float sum_sig1, sum_sig;
         float sigA, sigA1;
 
-
-
-
         x = abs(acc.getAccX());
         //printf("%f", x);
         y = abs(acc.getAccY());
@@ -127,9 +118,7 @@
         z_data.pop_back();
         sig.pop_back ();
 
-
         //printf ("x_data\n\r");
-
         //for (int p = 0; p != x_data.size(); ++p)
         //{
              //cout << x_data[p] << "\n\r" << endl;
@@ -144,17 +133,10 @@
         //thetavec_y.pop_back ();
         //thetavec_x.pop_back ();
 
-
-
         int  i, n = 20, m = 10;
-        //
-        for (i = 0; i < m; i++)
-
 
         /*  Compute  mean  */
-
-        for (i = 0; i < m; i++)
-        {
+        for (i = 0; i < m; i++) {
             total_x = total_x + x_data[i];
             total_y = total_y + y_data[i];
             total_z = total_z + z_data[i];
@@ -166,13 +148,11 @@
         average_z = total_z / (float)m;
         average_sig = total_sig / (float)m;
 
-         for (i = 10; i < n; i++)
-        {
+        for (i = 10; i < n; i++) {
             total_x1 = total_x1 + x_data[i];
             total_y1 = total_y1 + y_data[i];
             total_z1 = total_z1 + z_data[i];
             total_sig1 = total_sig1 + sig[i];
-
         }
 
         average_x1 = total_x1 / (float)m;
@@ -182,8 +162,7 @@
 
 
         /*  Compute  variance  and standard deviation  */
-        for (i = 0; i < m; i++)
-        {
+        for (i = 0; i < m; i++) {
             sum1_x = sum1_x + pow((x_data[i] - average_x), 2);
             sum1_y = sum1_y + pow((y_data[i] - average_y), 2);
             sum1_z = sum1_z + pow((z_data[i] - average_z), 2);
@@ -199,8 +178,7 @@
         std_deviation_z = sqrt(variance_z);
         sigA = sqrt(variance_sig);
 
-         for (i = 10; i < n; i++)
-        {
+        for (i = 10; i < n; i++) {
             sum1_x1 = sum1_x1 + pow((x_data[i] - average_x1), 2);
             sum1_y1 = sum1_y1 + pow((y_data[i] - average_y1), 2);
             sum1_z1 = sum1_z1 + pow((z_data[i] - average_z1), 2);
@@ -224,16 +202,15 @@
 
 
 
-        for (i = 0; i < m; i++)
-        {
+        for (i = 0; i < m; i++) {
             total_theta_z1 = total_theta_z1 + thetavec_z[i];
             //total_theta_y1 = total_theta_y1 + thetavec_y[i];
             //total_theta_x1 = total_theta_x1 + thetavec_x[i];
         }
 
-         theta_average_z = total_theta_z1 / (float)m;
-         //theta_average_y = total_theta_y1 / (float)m;
-         //theta_average_x = total_theta_x1 / (float)m;
+        theta_average_z = total_theta_z1 / (float)m;
+        //theta_average_y = total_theta_y1 / (float)m;
+        //theta_average_x = total_theta_x1 / (float)m;
 
 
         thetavec_av_z.push_back(theta_average_z);
@@ -256,26 +233,19 @@
 
         float ON;
 
-        if ((sig_ratio > threshold1) || (theta_ratio_z > threshold2))
-            {//have to add pressure sensor;
-            if (((theta_ratio_z > threshold3) || (dtheta_z > threshold4)) && ((sigA > threshold4) || (mag_sigXYZ > threshold5)))
-                {printf ("fall\n\r");
+        if ((sig_ratio > threshold1) || (theta_ratio_z > threshold2)) {
+            //have to add pressure sensor;
+            if (((theta_ratio_z > threshold3) || (dtheta_z > threshold4)) && ((sigA > threshold4) || (mag_sigXYZ > threshold5))) {
+                printf ("fall\n\r");
                 ON = 1;
-                }
-            else
-                {printf ("no fall\n\r");
+            } else {
+                printf ("no fall\n\r");
                 ON = 0;
-                }
-                }
-        else
-            {printf ("no fall\n\r");
+            }
+        } else {
+            printf ("no fall\n\r");
             ON = 0;
-            }
-
-
-
-
-
+        }
 
         //printf("X:%f,Y:%f,Z:%f\n", x, y, z);
 
@@ -285,4 +255,4 @@
 
         wait(0.05);
     }
-}
\ No newline at end of file
+}