Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
GY80.h
00001 #ifndef SENSORS_H 00002 #define SENSORS_H 00003 00004 #include "mbed.h" 00005 #define I2C_FREQ 400000 00006 #define SCL PB_6 00007 #define SDA PB_7 00008 00009 #define ACCEL_ADDRESS (0xA6) // 0x53 = 0xA6 / 2 00010 #define MAGN_ADDRESS (0x3C) // 0x1E = 0x3C / 2 00011 #define GYRO_ADDRESS (0xD2) // 0x68 = 0xD0 / 2 00012 00013 // SENSOR CALIBRATION 00014 /*****************************************************************/ 00015 // How to calibrate? Read the tutorial at http://dev.qu.tu-berlin.de/projects/sf-razor-9dof-ahrs 00016 // Put MIN/MAX and OFFSET readings for your board here! 00017 // Accelerometer 00018 // "accel x,y,z (min/max) = X_MIN/X_MAX Y_MIN/Y_MAX Z_MIN/Z_MAX" 00019 #define ACCEL_X_MIN (-255.0f) 00020 #define ACCEL_X_MAX (260.0f) 00021 #define ACCEL_Y_MIN (-267.0f) 00022 #define ACCEL_Y_MAX (255.0f) 00023 #define ACCEL_Z_MIN (-278.0f) 00024 #define ACCEL_Z_MAX (238.0f) 00025 00026 // Magnetometer 00027 // "magn x,y,z (min/max) = X_MIN/X_MAX Y_MIN/Y_MAX Z_MIN/Z_MAX" 00028 #define MAGN_X_MIN (-520.0f) 00029 #define MAGN_X_MAX (850.0f) 00030 #define MAGN_Y_MIN (-640.0f) 00031 #define MAGN_Y_MAX (684.0f) 00032 #define MAGN_Z_MIN (-213.0f) 00033 #define MAGN_Z_MAX (850.0f) 00034 00035 // Gyroscope 00036 // "gyro x,y,z (current/average) = .../OFFSET_X .../OFFSET_Y .../OFFSET_Z 00037 #define GYRO_X_OFFSET (-20.5f) 00038 #define GYRO_Y_OFFSET (0.5f) 00039 #define GYRO_Z_OFFSET (10.5f) 00040 00041 //*****************************************************************************/ 00042 00043 #define GRAVITY 255.0f //this equivalent to 1G in the raw data coming from the accelerometer 00044 00045 #define ACCEL_X_OFFSET ((ACCEL_X_MIN + ACCEL_X_MAX) / 2.0f) 00046 #define ACCEL_Y_OFFSET ((ACCEL_Y_MIN + ACCEL_Y_MAX) / 2.0f) 00047 #define ACCEL_Z_OFFSET ((ACCEL_Z_MIN + ACCEL_Z_MAX) / 2.0f) 00048 #define ACCEL_X_SCALE (GRAVITY / (ACCEL_X_MAX - ACCEL_X_OFFSET)) 00049 #define ACCEL_Y_SCALE (GRAVITY / (ACCEL_Y_MAX - ACCEL_Y_OFFSET)) 00050 #define ACCEL_Z_SCALE (GRAVITY / (ACCEL_Z_MAX - ACCEL_Z_OFFSET)) 00051 00052 #define MAGN_X_OFFSET ((MAGN_X_MIN + MAGN_X_MAX) / 2.0f) 00053 #define MAGN_Y_OFFSET ((MAGN_Y_MIN + MAGN_Y_MAX) / 2.0f) 00054 #define MAGN_Z_OFFSET ((MAGN_Z_MIN + MAGN_Z_MAX) / 2.0f) 00055 #define MAGN_X_SCALE (100.0f / (MAGN_X_MAX - MAGN_X_OFFSET)) 00056 #define MAGN_Y_SCALE (100.0f / (MAGN_Y_MAX - MAGN_Y_OFFSET)) 00057 #define MAGN_Z_SCALE (100.0f / (MAGN_Z_MAX - MAGN_Z_OFFSET)) 00058 00059 // Gyro gain (conversion from raw to degree per seconds) 00060 #define GYRO_GAIN 0.061035156f 00061 #define GYRO_GAIN_X 0.061035156f //X axis Gyro gain 00062 #define GYRO_GAIN_Y 0.061035156f //Y axis Gyro gain 00063 #define GYRO_GAIN_Z 0.061035156f //Z axis Gyro gain 00064 00065 #define DEG2RAD(x) (x * 0.01745329252) // *pi/180 00066 #define RAD2DEG(x) (x * 57.2957795131) // *180/pi 00067 00068 typedef char byte; 00069 00070 class GY80 00071 { 00072 public: 00073 I2C Wire; 00074 GY80(); 00075 ~GY80(); 00076 void Read_Accel(float* accel_v); 00077 void Read_Gyro(float* ); 00078 void Read_Magn(float* ); 00079 00080 private: 00081 short accel[3]; 00082 short gyro[3]; 00083 short mag[3]; 00084 void Accel_Init(); 00085 void Gyro_Init(); 00086 void Magn_Init(); 00087 00088 }; 00089 00090 #endif
Generated on Sun Aug 7 2022 00:00:09 by
1.7.2