MPU6050 library using i2c interface on LPC1768 - Complementary filter is added. Now program can calculate pitch and roll angles.
Fork of MPU6050 by
Revision 7:e4e02c9c1381, committed 2016-11-03
- Comitter:
- kfforex
- Date:
- Thu Nov 03 17:14:54 2016 +0000
- Parent:
- 6:5b90f2b5e6d9
- Commit message:
- before publishing
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 Wed Aug 05 13:15:07 2015 +0000 +++ b/MPU6050.cpp Thu Nov 03 17:14:54 2016 +0000 @@ -3,38 +3,13 @@ * @author: Baser Kandehir * @date: July 16, 2015 * @license: MIT license -* -* Copyright (c) 2015, Baser Kandehir, baser.kandehir@ieee.metu.edu.tr -* -* Permission is hereby granted, free of charge, to any person obtaining a copy -* of this software and associated documentation files (the "Software"), to deal -* in the Software without restriction, including without limitation the rights -* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -* copies of the Software, and to permit persons to whom the Software is -* furnished to do so, subject to the following conditions: -* -* The above copyright notice and this permission notice shall be included in -* all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -* THE SOFTWARE. -* */ -// Most of the code is adapted from Kris Winer's MPU6050 library #include "MPU6050.h" -/* For LPC1768 board */ -//I2C i2c(p9,p10); // setup i2c (SDA,SCL) - /* For NUCLEO-F411RE board */ -static I2C i2c(D14,D15); // setup i2c (SDA,SCL) +static I2C i2c(D4,D5); // setup i2c (SDA,SCL) /* Set initial input parameters */ @@ -147,12 +122,10 @@ if(whoAmI==0x68) { pc.printf("MPU6050 is online... \r\n"); - led2=1; } else { pc.printf("Could not connect to MPU6050 \r\nCheck the connections... \r\n"); - toggler1.attach(&toggle_led1,0.1); // toggles led1 every 100 ms } } @@ -359,9 +332,9 @@ /* Get actual gyro value */ readGyroData(gyroData); getGres(); - gx = gyroData[0]*gRes; // - gyroBias[0]; // Results are better without extracting gyroBias[i] - gy = gyroData[1]*gRes; // - gyroBias[1]; - gz = gyroData[2]*gRes; // - gyroBias[2]; + gx = gyroData[0]*gRes; // Results are better without extracting gyroBias[i] + gy = gyroData[1]*gRes; + gz = gyroData[2]*gRes; float pitchAcc, rollAcc;
--- a/MPU6050.h Wed Aug 05 13:15:07 2015 +0000 +++ b/MPU6050.h Thu Nov 03 17:14:54 2016 +0000 @@ -30,8 +30,8 @@ #include "math.h" #include "MPU6050RegDef.h" -#define PI 3.14159265359 // This value will be used when calculating angles -#define dt 0.005 // 200 Hz sampling period +#define PI 3.141592 // This value will be used when calculating angles +#define dt 0.01 extern float aRes, gRes;