k

Dependencies:   mbed

Revision:
0:238df339023b
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SendAcceloroY.cpp	Mon Dec 07 12:20:46 2015 +0000
@@ -0,0 +1,85 @@
+
+//Function 4 SenAcceloroY
+
+/*int SenAcceloroY()
+{
+         // If intPin goes high, all data registers have new data
+        if(mpu9250.readByte(MPU9250_ADDRESS, INT_STATUS) & 0x01) {  // On interrupt, check if data ready interrupt   
+            mpu9250.readAccelData(accelCount);  // Read the x/y/z adc values   
+            // Now we'll calculate the accleration value into actual g's
+            if (I2Cstate != 0) //error on I2C
+                pc.printf("I2C error ocurred while reading accelerometer data. I2Cstate = %d \n\r", I2Cstate);
+            else{ // I2C read or write ok
+                I2Cstate = 1;
+                ax = (float)accelCount[0]*aRes - accelBias[0];  // get actual g value, this depends on scale being set
+                ay = (float)accelCount[1]*aRes - accelBias[1];
+                az = (float)accelCount[2]*aRes - accelBias[2];
+            }   
+            
+            mpu9250.readGyroData(gyroCount);  // Read the x/y/z adc values
+            // Calculate the gyro value into actual degrees per second
+            if (I2Cstate != 0) //error on I2C
+                pc.printf("I2C error ocurred while reading gyrometer data. I2Cstate = %d \n\r", I2Cstate);
+            else{ // I2C read or write ok
+                I2Cstate = 1;
+                gx = (float)gyroCount[0]*gRes - gyroBias[0];  // get actual gyro value, this depends on scale being set
+                gy = (float)gyroCount[1]*gRes - gyroBias[1]; 
+                gz = (float)gyroCount[2]*gRes - gyroBias[2];
+            }
+            
+            mpu9250.readMagData(magCount);  // Read the x/y/z adc values   
+            // Calculate the magnetometer values in milliGauss
+            // Include factory calibration per data sheet and user environmental corrections
+            if (I2Cstate != 0) //error on I2C
+                pc.printf("I2C error ocurred while reading magnetometer data. I2Cstate = %d \n\r", I2Cstate);
+            else{ // I2C read or write ok
+                I2Cstate = 1;
+                mx = (float)magCount[0]*mRes*magCalibration[0] - magbias[0];  // get actual magnetometer value, this depends on scale being set
+                my = (float)magCount[1]*mRes*magCalibration[1] - magbias[1];  
+                mz = (float)magCount[2]*mRes*magCalibration[2] - magbias[2];
+            }
+                       
+            mpu9250.getCompassOrientation(orientation);
+        }
+   
+        Now = t.read_us();
+        deltat = (float)((Now - lastUpdate)/1000000.0f) ; // set integration time by time elapsed since last filter update
+        lastUpdate = Now;    
+        sum += deltat;
+        sumCount++;
+    
+        // Pass gyro rate as rad/s
+        // mpu9250.MadgwickQuaternionUpdate(ax, ay, az, gx*PI/180.0f, gy*PI/180.0f, gz*PI/180.0f,  my,  mx, mz);
+         mpu9250.MahonyQuaternionUpdate(ax, ay, az, gx*PI/180.0f, gy*PI/180.0f, gz*PI/180.0f, my, mx, mz);
+
+        // Serial print and/or display at 1.5 s rate independent of data rates
+        delt_t = t.read_ms() - count;
+        if (delt_t > 500) { // update LCD once per half-second independent of read rate
+            mpu9250.MadgwickQuaternionUpdate(ax,ay,az,gx,gy,gz,mx,my,mz);  
+
+            pc.printf(" ay = %.2f\n", 1000*ay);
+
+            tempCount = mpu9250.readTempData();  // Read the adc values
+            if (I2Cstate != 0) //error on I2C
+                pc.printf("I2C error ocurred while reading sensor temp. I2Cstate = %d \n\r", I2Cstate);
+            else{ // I2C read or write ok                
+                I2Cstate = 1;
+                temperature = ((float) tempCount) / 333.87f + 21.0f; // Temperature in degrees Centigrade
+                //pc.printf(" temperature = %f  C\n\r", temperature);
+            }
+
+
+            myled= !myled;
+            count = t.read_ms(); 
+
+            if(count > 1<<21) {
+                t.start(); // start the timer over again if ~30 minutes has passed
+                count = 0;
+                deltat= 0;
+                lastUpdate = t.read_us();
+            }
+        sum = 0;
+        sumCount = 0; 
+        }
+        return ay*1000;
+}*/
\ No newline at end of file