inertia sensor
Fork of LSM9DS0 by
Diff: LSM9DS0.cpp
- Revision:
- 4:29f3711f5f59
- Parent:
- 3:bc0db184f092
- Child:
- 5:472542e91734
--- a/LSM9DS0.cpp Thu Apr 28 09:06:50 2016 +0000 +++ b/LSM9DS0.cpp Sat Jul 23 13:40:51 2016 +0000 @@ -26,7 +26,7 @@ #include "mbed.h" //I2C i2c(D14,D15); -//SPI spi(D4,D5,D3); +//SPI spi(D4,D5,D8); //****************************************************************************// // // LSM9DS0 functions. @@ -94,7 +94,7 @@ setMagScale(mScale); // Set the magnetometer's range. setGyroOffset(0,0,0); - setAccelOffset(0,0,0); + setAccelOffset(-936,-491,265); setMagOffset(0,0,0); // Once everything is initialized, return the WHO_AM_I registers we read: @@ -858,23 +858,4 @@ // { // dest[i++] = Wire.read(); // Put read results in the Rx buffer // } -} - -void LSM9DS0::complementaryFilter(float * data, float dt) -{ - - float pitchAcc, rollAcc; - - /* Integrate the gyro data(deg/s) over time to get angle */ - pitch += data[5] * dt; // Angle around the Z-axis - roll += data[3] * dt; // Angle around the X-axis - - /* Turning around the X-axis results in a vector on the Y-axis - whereas turning around the Y-axis results in a vector on the X-axis. */ - pitchAcc = (float)atan2f(-data[0], -data[1])*180.0f/PI; - rollAcc = (float)atan2f(data[2], -data[1])*180.0f/PI; - - /* Apply Complementary Filter */ - pitch = pitch * 0.999 + pitchAcc * 0.001; - roll = roll * 0.999 + rollAcc * 0.001; } \ No newline at end of file