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.
IMU.h
00001 #ifndef IMU_H 00002 #define IMU_H 00003 00004 #include "mbed.h" 00005 00006 // definitions for the gyro sensor 00007 #define L3GD20_ADDR 0xD6 00008 #define L3GD20_CTRL_REG1 0x20 00009 #define L3GD20_CTRL_REG4 0x23 00010 #define L3GD20_STATUS_REG 0x27 00011 #define L3GD20_OUT_X_L 0x28 00012 #define L3GD20_RANGE_250DPS 0x00 // Measurement range selected by CTRL_REG4 00013 #define L3GD20_RANGE_500DPS 0x01 // Default range = 250 Degree-per-Second = 0.7 rev/second 00014 #define L3GD20_RANGE_2000DPS 0x02 // Range determines Sensitivity 00015 #define L3GD20_SENSITIVITY_250DPS 0.00875 // Roughly 22/256 for fixed point match 00016 #define L3GD20_SENSITIVITY_500DPS 0.0175 // Roughly 45/256 00017 #define L3GD20_SENSITIVITY_2000DPS 0.070 // Roughly 18/256 00018 #define L3GD20_DPS_TO_RADS 0.017453293 // = pi/180 degrees/s to rad/s multiplier 00019 00020 00021 // definitions for the accelerometer 00022 #define LSM303_A_ADDR 0x32 // address for writing. +1 for reading, see manual p. 20/42. 00023 #define LSM303_A_CTRL_REG1 0x20 00024 #define LSM303_A_CTRL_REG4 0x23 00025 #define LSM303_A_OUT_X_L 0x28 00026 #define LSM303_A_FS_2G 0x00 // Full Scale measuremetn range - selected by CTRL_REG4 00027 #define LSM303_A_Sensitivity 0.001 // Linear acceleration sensitivity 00028 #define LSM303_A_GRAVITY_EARTH 9.80665 // Earth's gravity in m/s^2 upon calibration of sensor 00029 00030 // definitions for the magnetic sensor 00031 #define LSM303_M_ADDR 0x3C // address for writing. +1 for reading, see datasheet p. 21/42. 00032 #define LSM303_M_CRA_REG 0x00 00033 #define LSM303_M_CRB_REG 0x01 00034 #define LSM303_M_MR_REG 0x02 00035 #define LSM303_M_OUT_X_H 0x03 // Watch out: order of H and L reversed 00036 #define LSM303_M_FS_13G 0x01 // Full Scale measuremetn range - selected by CRB_REG 00037 #define LSM303_M_Sensitivity 1100 // Corresponding sensitivity = 1100 Bits/Gauss 00038 00039 00040 class IMU 00041 { 00042 public: 00043 /* constructor */ 00044 IMU(PinName sda, PinName scl); 00045 00046 /* accessible functions */ 00047 char init(void); 00048 char readData(float *); 00049 void filterData(float *, double *); 00050 00051 private: 00052 I2C _i2c; 00053 char address; 00054 int16_t L3GD20_biasX; /* digit counts */ 00055 int16_t L3GD20_biasY; 00056 int16_t L3GD20_biasZ; 00057 double g_0; 00058 double FF[3]; 00059 double FD[6][9]; 00060 }; 00061 00062 #endif
Generated on Wed Jul 13 2022 22:54:55 by
1.7.2