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