Credit for code left in comments

Committer:
ahdyer
Date:
Sun May 08 16:32:45 2022 +0000
Revision:
1:8f364d5295d8
Parent:
0:ffb90bdc9bb5
Working Alex

Who changed what in which revision?

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