Used to control two motors
Fork of MPU6050 by
MPU6050.h@2:3e0dfce73a58, 2015-07-16 (annotated)
- Committer:
- BaserK
- Date:
- Thu Jul 16 13:56:09 2015 +0000
- Revision:
- 2:3e0dfce73a58
- Parent:
- 1:a248e65a25cc
- Child:
- 3:a173ad187e67
complementary filter is added to the library as a function
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
BaserK | 0:954f15bd95f1 | 1 | // Most of the code is adapted from Kris Winer's MPU6050 library |
BaserK | 0:954f15bd95f1 | 2 | |
BaserK | 0:954f15bd95f1 | 3 | #ifndef MPU6050_H |
BaserK | 0:954f15bd95f1 | 4 | #define MPU6050_H |
BaserK | 0:954f15bd95f1 | 5 | |
BaserK | 0:954f15bd95f1 | 6 | #include "mbed.h" |
BaserK | 0:954f15bd95f1 | 7 | #include "math.h" |
BaserK | 0:954f15bd95f1 | 8 | #include "MPU6050RegDef.h" |
BaserK | 0:954f15bd95f1 | 9 | |
BaserK | 2:3e0dfce73a58 | 10 | #define PI 3.14159265359 // This value will be used when calculating angles |
BaserK | 1:a248e65a25cc | 11 | #define dt 0.005 // 200 Hz sampling period |
BaserK | 1:a248e65a25cc | 12 | |
BaserK | 0:954f15bd95f1 | 13 | extern I2C i2c; // extern the i2c in order to able to use from other files |
BaserK | 0:954f15bd95f1 | 14 | extern float aRes, gRes; |
BaserK | 0:954f15bd95f1 | 15 | |
BaserK | 0:954f15bd95f1 | 16 | /* whoAmI func uses this func, variables etc */ |
BaserK | 0:954f15bd95f1 | 17 | extern Ticker toggler1; |
BaserK | 2:3e0dfce73a58 | 18 | extern Serial pc; |
BaserK | 0:954f15bd95f1 | 19 | extern DigitalOut led2; |
BaserK | 0:954f15bd95f1 | 20 | extern void toggle_led1(); |
BaserK | 0:954f15bd95f1 | 21 | |
BaserK | 2:3e0dfce73a58 | 22 | /* Sensor datas to be used in program */ |
BaserK | 0:954f15bd95f1 | 23 | extern float ax,ay,az; |
BaserK | 0:954f15bd95f1 | 24 | extern float gx,gy,gz; |
BaserK | 0:954f15bd95f1 | 25 | extern int16_t accelData[3],gyroData[3],tempData; |
BaserK | 0:954f15bd95f1 | 26 | extern float accelBias[3], gyroBias[3]; |
BaserK | 0:954f15bd95f1 | 27 | |
BaserK | 0:954f15bd95f1 | 28 | /* Function Prototypes */ |
BaserK | 0:954f15bd95f1 | 29 | class MPU6050 |
BaserK | 0:954f15bd95f1 | 30 | { |
BaserK | 0:954f15bd95f1 | 31 | protected: |
BaserK | 0:954f15bd95f1 | 32 | public: |
BaserK | 0:954f15bd95f1 | 33 | void getAres(); |
BaserK | 0:954f15bd95f1 | 34 | void getGres(); |
BaserK | 0:954f15bd95f1 | 35 | void writeByte(uint8_t address, uint8_t subAddress, uint8_t data); |
BaserK | 0:954f15bd95f1 | 36 | char readByte(uint8_t address, uint8_t subAddress); |
BaserK | 0:954f15bd95f1 | 37 | void readBytes(uint8_t address, uint8_t subAddress, uint8_t byteNum, uint8_t* dest); |
BaserK | 0:954f15bd95f1 | 38 | void whoAmI(); |
BaserK | 0:954f15bd95f1 | 39 | void init(); |
BaserK | 0:954f15bd95f1 | 40 | void reset(); |
BaserK | 0:954f15bd95f1 | 41 | void readAccelData(int16_t* dest); |
BaserK | 0:954f15bd95f1 | 42 | void readGyroData(int16_t* dest); |
BaserK | 0:954f15bd95f1 | 43 | int16_t readTempData(); |
BaserK | 0:954f15bd95f1 | 44 | void calibrate(float* dest1, float* dest2); |
BaserK | 2:3e0dfce73a58 | 45 | void complementaryFilter(float* pitch, float* roll); |
BaserK | 0:954f15bd95f1 | 46 | }; |
BaserK | 0:954f15bd95f1 | 47 | |
BaserK | 0:954f15bd95f1 | 48 | #endif |