General IMU Library
Dependencies: mbed LSM9DS1_Library
Revision 4:ab08a70e0d7d, committed 2017-02-16
- Comitter:
- simplyellow
- Date:
- Thu Feb 16 20:31:35 2017 +0000
- Parent:
- 3:3b572eec3f20
- Commit message:
- fixed compile issues.
Changed in this revision
diff -r 3b572eec3f20 -r ab08a70e0d7d IMU.cpp --- a/IMU.cpp Thu Feb 16 18:28:00 2017 +0000 +++ b/IMU.cpp Thu Feb 16 20:31:35 2017 +0000 @@ -1,30 +1,24 @@ -#include "mbed.h" -#include "LSM9DS1.h" #include "IMU.h" -#define PI 3.1514 +#define PI 3.14159 IMU::IMU() { - - LSM9DS1 I(p9, p10, 0xD6, 0x3C); - I.begin(); - if (!I.begin()) { + I = new LSM9DS1(p9, p10, 0xD6, 0x3C); + I->begin(); + if (!I->begin()) { printf("Failed to communicate with LSM9DS1.\n"); } - I.calibrate(1); - bool state; - float ax01 = I.calcAccel(I.ax); - float ay01 = I.calcAccel(I.ay); - float az01 = I.calcAccel(I.az); - float ax0 = ax01; - float ay0 = ay01; - float az0 = az01; - float ax; - float ay; - float az; - float theta; + I->calibrate(1); + //bool state; + //Do we want to give state a starting value? + ax01 = I->calcAccel(I->ax); + ay01 = I->calcAccel(I->ay); + az01 = I->calcAccel(I->az); + ax0 = ax01; + ay0 = ay01; + az0 = az01; } - + void IMU::trackBed() { if (state != 0) { @@ -32,20 +26,19 @@ } else { while(state == 0) { - - while(!I.accelAvailable()); - I.readAccel(); - - // current a = <ax,ay,az> - ax = I.calcAccel(I.ax); - ay = I.calcAccel(I.ay); - az = I.calcAccel(I.az); + while(!I->accelAvailable()); + I->readAccel(); + + // current a = <ax,ay,az> + ax = I->calcAccel(I->ax); + ay = I->calcAccel(I->ay); + az = I->calcAccel(I->az); // theta in degrees between a0 and a theta = acos((ax0*ax + ay0*ay + az0*az)/(sqrt(ax0*ax0+ay0*ay0+az0*az0)*sqrt(ax*ax+ay*ay+az*az)))*180/PI; } } } - + void IMU::trackHeading() { if (state != 1) { @@ -53,14 +46,13 @@ } else { while (state == 1) { - - while(!I.accelAvailable()); - - I.readAccel(); - ax0 = I.calcAccel(I.ax); - ay0 = I.calcAccel(I.ay); - az0 = I.calcAccel(I.az); + + while(!I->accelAvailable()); + + I->readAccel(); + ax0 = I->calcAccel(I->ax); + ay0 = I->calcAccel(I->ay); + az0 = I->calcAccel(I->az); } } } - \ No newline at end of file
diff -r 3b572eec3f20 -r ab08a70e0d7d IMU.h --- a/IMU.h Thu Feb 16 18:28:00 2017 +0000 +++ b/IMU.h Thu Feb 16 20:31:35 2017 +0000 @@ -9,7 +9,7 @@ #ifndef IMU_H #define IMU_H - + #include "mbed.h" #include "LSM9DS1.h" @@ -17,10 +17,8 @@ public: /** * Constructor for the IMU - * - * @param[in] _state */ - IMU() : _I(p9, p10, 0xD6, 0x3C){}; + IMU(); /** * Track the angle of the truck bed */ @@ -29,20 +27,20 @@ * Track the angle of the truck as it moves */ void trackHeading(); - + private: + LSM9DS1 *I; bool state; float ax01; float ay01; float az01; float ax0; float ay0; - float az0; + float az0; float ax; float ay; float az; float theta; - LSM9DS1 _I; }; #endif \ No newline at end of file
diff -r 3b572eec3f20 -r ab08a70e0d7d LSM9DS1_Library.lib --- a/LSM9DS1_Library.lib Thu Feb 16 18:28:00 2017 +0000 +++ b/LSM9DS1_Library.lib Thu Feb 16 20:31:35 2017 +0000 @@ -1,1 +1,1 @@ -http://developer.mbed.org/users/jmar7/code/LSM9DS1_Library/#93b89ce73b68 +http://developer.mbed.org/users/jmar7/code/LSM9DS1_Library/#17e3d44f490c