A quadcopter control Software (Still in development). achieved single axis stability!!!!! released for others benefit. if you'd like to help co-develop this code, then please let me know
Dependencies: MovingAverageFilter MyI2C PID RC mbed-rtos mbed
Currently on hold, due to the fact that i don't own a RX/TX system
MPU/MPU6050.h@1:e08a4f517989, 2013-08-27 (annotated)
- Committer:
- KarimAzzouz
- Date:
- Tue Aug 27 09:38:49 2013 +0000
- Revision:
- 1:e08a4f517989
initial commit, achieved single axis stability
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
KarimAzzouz | 1:e08a4f517989 | 1 | #ifndef MPU6050_H |
KarimAzzouz | 1:e08a4f517989 | 2 | #define MPU6050_H |
KarimAzzouz | 1:e08a4f517989 | 3 | |
KarimAzzouz | 1:e08a4f517989 | 4 | #include "mbed.h" |
KarimAzzouz | 1:e08a4f517989 | 5 | #include "MyI2C.h" |
KarimAzzouz | 1:e08a4f517989 | 6 | #include "MAF.h" |
KarimAzzouz | 1:e08a4f517989 | 7 | |
KarimAzzouz | 1:e08a4f517989 | 8 | #define MPU_ADDRESS 0x68 |
KarimAzzouz | 1:e08a4f517989 | 9 | #define GyroScale 16.4f |
KarimAzzouz | 1:e08a4f517989 | 10 | #define AccScale 4096 |
KarimAzzouz | 1:e08a4f517989 | 11 | #define ToRad(x) (x*0.01745329252) // *pi/180 |
KarimAzzouz | 1:e08a4f517989 | 12 | #define ToDeg(x) (x*57.2957795131) // *180/pi |
KarimAzzouz | 1:e08a4f517989 | 13 | |
KarimAzzouz | 1:e08a4f517989 | 14 | extern MyI2C I2C0; |
KarimAzzouz | 1:e08a4f517989 | 15 | |
KarimAzzouz | 1:e08a4f517989 | 16 | class MPU6050 |
KarimAzzouz | 1:e08a4f517989 | 17 | { |
KarimAzzouz | 1:e08a4f517989 | 18 | |
KarimAzzouz | 1:e08a4f517989 | 19 | public: |
KarimAzzouz | 1:e08a4f517989 | 20 | |
KarimAzzouz | 1:e08a4f517989 | 21 | MPU6050(void); |
KarimAzzouz | 1:e08a4f517989 | 22 | float filtered_Gyro[3],filtered_Acc[3]; |
KarimAzzouz | 1:e08a4f517989 | 23 | float Scaled_GyroX,Scaled_GyroY,Scaled_GyroZ; |
KarimAzzouz | 1:e08a4f517989 | 24 | float Scaled_AccX,Scaled_AccY,Scaled_AccZ; |
KarimAzzouz | 1:e08a4f517989 | 25 | int Raw_AccX,Raw_AccY,Raw_AccZ; |
KarimAzzouz | 1:e08a4f517989 | 26 | float GyroOffset[3],AccOffset[3]; |
KarimAzzouz | 1:e08a4f517989 | 27 | float accangle[2]; |
KarimAzzouz | 1:e08a4f517989 | 28 | float Acceleration_Magnitude; |
KarimAzzouz | 1:e08a4f517989 | 29 | bool Panic; |
KarimAzzouz | 1:e08a4f517989 | 30 | |
KarimAzzouz | 1:e08a4f517989 | 31 | |
KarimAzzouz | 1:e08a4f517989 | 32 | bool CheckConnection(void); |
KarimAzzouz | 1:e08a4f517989 | 33 | |
KarimAzzouz | 1:e08a4f517989 | 34 | void MPU_Setup(void); |
KarimAzzouz | 1:e08a4f517989 | 35 | |
KarimAzzouz | 1:e08a4f517989 | 36 | void ScaledGyro(void); |
KarimAzzouz | 1:e08a4f517989 | 37 | |
KarimAzzouz | 1:e08a4f517989 | 38 | void ScaledAcc(void); |
KarimAzzouz | 1:e08a4f517989 | 39 | |
KarimAzzouz | 1:e08a4f517989 | 40 | void RawAcc(void); |
KarimAzzouz | 1:e08a4f517989 | 41 | |
KarimAzzouz | 1:e08a4f517989 | 42 | void CalibrateGyro(void); |
KarimAzzouz | 1:e08a4f517989 | 43 | |
KarimAzzouz | 1:e08a4f517989 | 44 | void CalibrateAcc(void); |
KarimAzzouz | 1:e08a4f517989 | 45 | |
KarimAzzouz | 1:e08a4f517989 | 46 | void GyroRate(void); |
KarimAzzouz | 1:e08a4f517989 | 47 | |
KarimAzzouz | 1:e08a4f517989 | 48 | void Acc(void); |
KarimAzzouz | 1:e08a4f517989 | 49 | |
KarimAzzouz | 1:e08a4f517989 | 50 | void filterGyro(void); |
KarimAzzouz | 1:e08a4f517989 | 51 | |
KarimAzzouz | 1:e08a4f517989 | 52 | void filterAcc(void); |
KarimAzzouz | 1:e08a4f517989 | 53 | |
KarimAzzouz | 1:e08a4f517989 | 54 | void AccAngle(void); |
KarimAzzouz | 1:e08a4f517989 | 55 | |
KarimAzzouz | 1:e08a4f517989 | 56 | private: |
KarimAzzouz | 1:e08a4f517989 | 57 | |
KarimAzzouz | 1:e08a4f517989 | 58 | MAF filter_AccX,filter_AccY,filter_AccZ; // Moving Average Filter Initiallization |
KarimAzzouz | 1:e08a4f517989 | 59 | |
KarimAzzouz | 1:e08a4f517989 | 60 | MAF filter_GyroX,filter_GyroY,filter_GyroZ; |
KarimAzzouz | 1:e08a4f517989 | 61 | |
KarimAzzouz | 1:e08a4f517989 | 62 | void write(char reg,char data); |
KarimAzzouz | 1:e08a4f517989 | 63 | |
KarimAzzouz | 1:e08a4f517989 | 64 | int read (char reg); |
KarimAzzouz | 1:e08a4f517989 | 65 | |
KarimAzzouz | 1:e08a4f517989 | 66 | }; |
KarimAzzouz | 1:e08a4f517989 | 67 | |
KarimAzzouz | 1:e08a4f517989 | 68 | #endif |