Thanks Erik Olieman for his beta library, that saved me a huge amount of time when getting Raw data from MPU6050 module! I was able to update this library by adding additional functions, which would allow a fast angle calculation by using complementary filter. I will probably be updating this library more soon to add additional functionality or make some changes that would look sensible.
Dependents: QuadcopterProgram 3DTracking ControlYokutan2017 Gyro ... more
Fork of MPU6050 by
Revision 4:268d3fcb92ba, committed 2015-02-12
- Comitter:
- moklumbys
- Date:
- Thu Feb 12 20:36:53 2015 +0000
- Parent:
- 3:187152513f8d
- Child:
- 5:5873df1e58be
- Commit message:
- Modified library to get angle from accelerometer.
Changed in this revision
MPU6050.cpp | Show annotated file Show diff for this revision Revisions of this file |
MPU6050.h | Show annotated file Show diff for this revision Revisions of this file |
--- a/MPU6050.cpp Thu Feb 12 10:26:56 2015 +0000 +++ b/MPU6050.cpp Thu Feb 12 20:36:53 2015 +0000 @@ -148,6 +148,16 @@ #endif } +//function for getting angles from accelerometer +void MPU6050::getAcceleroAngle( float *data ) { + int temp[3]; + this->getAccelero(temp); + + data[X_AXIS] = -1*atan (-1*temp[Y_AXIS]/sqrt(pow(temp[X_AXIS], 2) + pow(temp[Z_AXIS], 2))) * RADIANS_TO_DEGREES; //calculate angle x(pitch/roll?) from accellerometer reading + data[Y_AXIS] = -1*atan (temp[X_AXIS]/sqrt(pow(temp[Y_AXIS], 2) + pow(temp[Z_AXIS], 2))) * RADIANS_TO_DEGREES; //calculate angle x(pitch/roll?) from accellerometer reading + data[Z_AXIS] = atan (sqrt(pow(temp[X_AXIS], 2) + pow(temp[Y_AXIS], 2))/temp[Z_AXIS]) * RADIANS_TO_DEGREES; //not sure what is this one :D + +} //-------------------------------------------------- //------------------Gyroscope----------------------- //--------------------------------------------------
--- a/MPU6050.h Thu Feb 12 10:26:56 2015 +0000 +++ b/MPU6050.h Thu Feb 12 20:36:53 2015 +0000 @@ -73,6 +73,10 @@ #define MPU6050_GYRO_RANGE_1000 2 #define MPU6050_GYRO_RANGE_2000 3 +//define how the accelerometer is placed on surface +#define X_AXIS 1 +#define Y_AXIS 2 +#define Z_AXIS 0 /** MPU6050 IMU library. *