hah
Fork of MPU6050 by
MPU6050.h@7:5bd970507896, 2016-06-03 (annotated)
- Committer:
- ThomasGS
- Date:
- Fri Jun 03 13:50:47 2016 +0000
- Revision:
- 7:5bd970507896
- Parent:
- 5:5bff0edcdff8
pour simone;
Who changed what in which revision?
User | Revision | Line number | New 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 | 0:954f15bd95f1 | 39 | extern Ticker toggler1; |
BaserK | 2:3e0dfce73a58 | 40 | extern Serial pc; |
BaserK | 0:954f15bd95f1 | 41 | extern DigitalOut led2; |
BaserK | 0:954f15bd95f1 | 42 | extern void toggle_led1(); |
BaserK | 0:954f15bd95f1 | 43 | |
BaserK | 2:3e0dfce73a58 | 44 | /* Sensor datas to be used in program */ |
BaserK | 0:954f15bd95f1 | 45 | extern float ax,ay,az; |
BaserK | 0:954f15bd95f1 | 46 | extern float gx,gy,gz; |
BaserK | 0:954f15bd95f1 | 47 | extern int16_t accelData[3],gyroData[3],tempData; |
BaserK | 0:954f15bd95f1 | 48 | extern float accelBias[3], gyroBias[3]; |
BaserK | 0:954f15bd95f1 | 49 | |
BaserK | 0:954f15bd95f1 | 50 | /* Function Prototypes */ |
BaserK | 0:954f15bd95f1 | 51 | class MPU6050 |
BaserK | 0:954f15bd95f1 | 52 | { |
BaserK | 0:954f15bd95f1 | 53 | protected: |
BaserK | 0:954f15bd95f1 | 54 | public: |
BaserK | 0:954f15bd95f1 | 55 | void getAres(); |
BaserK | 0:954f15bd95f1 | 56 | void getGres(); |
BaserK | 0:954f15bd95f1 | 57 | void writeByte(uint8_t address, uint8_t subAddress, uint8_t data); |
BaserK | 0:954f15bd95f1 | 58 | char readByte(uint8_t address, uint8_t subAddress); |
BaserK | 0:954f15bd95f1 | 59 | void readBytes(uint8_t address, uint8_t subAddress, uint8_t byteNum, uint8_t* dest); |
BaserK | 0:954f15bd95f1 | 60 | void whoAmI(); |
BaserK | 0:954f15bd95f1 | 61 | void init(); |
BaserK | 0:954f15bd95f1 | 62 | void reset(); |
BaserK | 0:954f15bd95f1 | 63 | void readAccelData(int16_t* dest); |
BaserK | 0:954f15bd95f1 | 64 | void readGyroData(int16_t* dest); |
BaserK | 0:954f15bd95f1 | 65 | int16_t readTempData(); |
BaserK | 0:954f15bd95f1 | 66 | void calibrate(float* dest1, float* dest2); |
BaserK | 2:3e0dfce73a58 | 67 | void complementaryFilter(float* pitch, float* roll); |
BaserK | 0:954f15bd95f1 | 68 | }; |
BaserK | 0:954f15bd95f1 | 69 | |
BaserK | 0:954f15bd95f1 | 70 | #endif |