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