hah

Dependents:   Gimbal_ENSEA

Fork of MPU6050 by Baser Kandehir

Committer:
BaserK
Date:
Tue Jul 21 08:16:36 2015 +0000
Revision:
3:a173ad187e67
Parent:
2:3e0dfce73a58
Child:
5:5bff0edcdff8
MIT license is added

Who changed what in which revision?

UserRevisionLine numberNew contents of line
BaserK 3:a173ad187e67 1 /*
BaserK 3:a173ad187e67 2 * Copyright (c) 2015, Baser Kandehir, baser.kandehir@ieee.metu.edu.tr
BaserK 3:a173ad187e67 3 *
BaserK 3:a173ad187e67 4 * Permission is hereby granted, free of charge, to any person obtaining a copy
BaserK 3:a173ad187e67 5 * of this software and associated documentation files (the "Software"), to deal
BaserK 3:a173ad187e67 6 * in the Software without restriction, including without limitation the rights
BaserK 3:a173ad187e67 7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
BaserK 3:a173ad187e67 8 * copies of the Software, and to permit persons to whom the Software is
BaserK 3:a173ad187e67 9 * furnished to do so, subject to the following conditions:
BaserK 3:a173ad187e67 10 *
BaserK 3:a173ad187e67 11 * The above copyright notice and this permission notice shall be included in
BaserK 3:a173ad187e67 12 * all copies or substantial portions of the Software.
BaserK 3:a173ad187e67 13 *
BaserK 3:a173ad187e67 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
BaserK 3:a173ad187e67 15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
BaserK 3:a173ad187e67 16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
BaserK 3:a173ad187e67 17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
BaserK 3:a173ad187e67 18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
BaserK 3:a173ad187e67 19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
BaserK 3:a173ad187e67 20 * THE SOFTWARE.
BaserK 3:a173ad187e67 21 *
BaserK 3:a173ad187e67 22 */
BaserK 3:a173ad187e67 23
BaserK 0:954f15bd95f1 24 // Most of the code is adapted from Kris Winer's MPU6050 library
BaserK 0:954f15bd95f1 25
BaserK 0:954f15bd95f1 26 #ifndef MPU6050_H
BaserK 0:954f15bd95f1 27 #define MPU6050_H
BaserK 0:954f15bd95f1 28
BaserK 0:954f15bd95f1 29 #include "mbed.h"
BaserK 0:954f15bd95f1 30 #include "math.h"
BaserK 0:954f15bd95f1 31 #include "MPU6050RegDef.h"
BaserK 0:954f15bd95f1 32
BaserK 2:3e0dfce73a58 33 #define PI 3.14159265359 // This value will be used when calculating angles
BaserK 1:a248e65a25cc 34 #define dt 0.005 // 200 Hz sampling period
BaserK 1:a248e65a25cc 35
BaserK 0:954f15bd95f1 36 extern I2C i2c; // extern the i2c in order to able to use from other files
BaserK 0:954f15bd95f1 37 extern float aRes, gRes;
BaserK 0:954f15bd95f1 38
BaserK 0:954f15bd95f1 39 /* whoAmI func uses this func, variables etc */
BaserK 0:954f15bd95f1 40 extern Ticker toggler1;
BaserK 2:3e0dfce73a58 41 extern Serial pc;
BaserK 0:954f15bd95f1 42 extern DigitalOut led2;
BaserK 0:954f15bd95f1 43 extern void toggle_led1();
BaserK 0:954f15bd95f1 44
BaserK 2:3e0dfce73a58 45 /* Sensor datas to be used in program */
BaserK 0:954f15bd95f1 46 extern float ax,ay,az;
BaserK 0:954f15bd95f1 47 extern float gx,gy,gz;
BaserK 0:954f15bd95f1 48 extern int16_t accelData[3],gyroData[3],tempData;
BaserK 0:954f15bd95f1 49 extern float accelBias[3], gyroBias[3];
BaserK 0:954f15bd95f1 50
BaserK 0:954f15bd95f1 51 /* Function Prototypes */
BaserK 0:954f15bd95f1 52 class MPU6050
BaserK 0:954f15bd95f1 53 {
BaserK 0:954f15bd95f1 54 protected:
BaserK 0:954f15bd95f1 55 public:
BaserK 0:954f15bd95f1 56 void getAres();
BaserK 0:954f15bd95f1 57 void getGres();
BaserK 0:954f15bd95f1 58 void writeByte(uint8_t address, uint8_t subAddress, uint8_t data);
BaserK 0:954f15bd95f1 59 char readByte(uint8_t address, uint8_t subAddress);
BaserK 0:954f15bd95f1 60 void readBytes(uint8_t address, uint8_t subAddress, uint8_t byteNum, uint8_t* dest);
BaserK 0:954f15bd95f1 61 void whoAmI();
BaserK 0:954f15bd95f1 62 void init();
BaserK 0:954f15bd95f1 63 void reset();
BaserK 0:954f15bd95f1 64 void readAccelData(int16_t* dest);
BaserK 0:954f15bd95f1 65 void readGyroData(int16_t* dest);
BaserK 0:954f15bd95f1 66 int16_t readTempData();
BaserK 0:954f15bd95f1 67 void calibrate(float* dest1, float* dest2);
BaserK 2:3e0dfce73a58 68 void complementaryFilter(float* pitch, float* roll);
BaserK 0:954f15bd95f1 69 };
BaserK 0:954f15bd95f1 70
BaserK 0:954f15bd95f1 71 #endif