df

Dependents:   gimbalController_brushless_IMU

Fork of MPU6050 by Baser Kandehir

Committer:
alfaleader
Date:
Mon May 16 09:50:01 2016 +0000
Revision:
8:ae197c3fd843
Parent:
7:a8a0621e4732
d

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 float aRes, gRes;
BaserK 0:954f15bd95f1 37
BaserK 0:954f15bd95f1 38 /* whoAmI func uses this func, variables etc */
BaserK 2:3e0dfce73a58 39 extern Serial pc;
BaserK 0:954f15bd95f1 40
BaserK 2:3e0dfce73a58 41 /* Sensor datas to be used in program */
BaserK 0:954f15bd95f1 42 extern float ax,ay,az;
BaserK 0:954f15bd95f1 43 extern float gx,gy,gz;
BaserK 0:954f15bd95f1 44 extern int16_t accelData[3],gyroData[3],tempData;
BaserK 0:954f15bd95f1 45 extern float accelBias[3], gyroBias[3];
BaserK 0:954f15bd95f1 46
BaserK 0:954f15bd95f1 47 /* Function Prototypes */
BaserK 0:954f15bd95f1 48 class MPU6050
BaserK 0:954f15bd95f1 49 {
BaserK 0:954f15bd95f1 50 protected:
BaserK 0:954f15bd95f1 51 public:
BaserK 0:954f15bd95f1 52 void getAres();
BaserK 0:954f15bd95f1 53 void getGres();
BaserK 0:954f15bd95f1 54 void writeByte(uint8_t address, uint8_t subAddress, uint8_t data);
BaserK 0:954f15bd95f1 55 char readByte(uint8_t address, uint8_t subAddress);
BaserK 0:954f15bd95f1 56 void readBytes(uint8_t address, uint8_t subAddress, uint8_t byteNum, uint8_t* dest);
BaserK 0:954f15bd95f1 57 void whoAmI();
BaserK 0:954f15bd95f1 58 void init();
BaserK 0:954f15bd95f1 59 void reset();
BaserK 0:954f15bd95f1 60 void readAccelData(int16_t* dest);
BaserK 0:954f15bd95f1 61 void readGyroData(int16_t* dest);
BaserK 0:954f15bd95f1 62 int16_t readTempData();
BaserK 0:954f15bd95f1 63 void calibrate(float* dest1, float* dest2);
BaserK 2:3e0dfce73a58 64 void complementaryFilter(float* pitch, float* roll);
BaserK 0:954f15bd95f1 65 };
BaserK 0:954f15bd95f1 66
BaserK 0:954f15bd95f1 67 #endif