Corrected header file include guards.
Fork of IMUdriver by
Embed:
(wiki syntax)
Show/hide line numbers
MPU6000.h
00001 /** CODED by Bruno Alfano on 07/03/2014 00002 * www.xene.it 00003 * 00004 * Example: 00005 * @code 00006 * #include "mbed.h" 00007 * #include "MPU6000.h" //Include library 00008 * SPI spi(p11, p12, p13); //define the SPI (mosi, miso, sclk) 00009 * mpu6000_spi imu(spi,p22); //define the mpu6000 object 00010 * int main(){ 00011 * if(imu.init(1,BITS_DLPF_CFG_5HZ)){ //INIT the mpu6000 00012 * printf("\nCouldn't initialize MPU6000 via SPI!"); 00013 * } 00014 * wait(0.1); 00015 * printf("\n\nWHOAMI=%u\n",imu.whoami()); //output the I2C address to know if SPI is working, it should be 104 00016 * wait(0.1); 00017 * printf("\nGyro_scale=%u\n",imu.set_gyro_scale(BITS_FS_2000DPS)); //Set full scale range for gyros 00018 * wait(1); 00019 * printf("\nAcc_scale=%u\n",imu.set_acc_scale(BITS_FS_16G)); //Set full scale range for accs 00020 * wait(0.1); 00021 * while(1) { 00022 * myled = 1; 00023 * wait(0.3); 00024 * myled = 0; 00025 * wait(0.3); 00026 * printf("\nT=%.3f",imu.read_temp()); 00027 * printf(" X=%.3f",imu.read_acc(0)); 00028 * printf(" Y=%.3f",imu.read_acc(1)); 00029 * printf(" Z=%.3f",imu.read_acc(2)); 00030 * printf(" rX=%.3f",imu.read_rot(0)); 00031 * printf(" rY=%.3f",imu.read_rot(1)); 00032 * printf(" rZ=%.3f",imu.read_rot(2)); 00033 * } 00034 * } 00035 * @endcode 00036 */ 00037 00038 #ifndef MPU6000_h 00039 #define MPU6000_h 00040 #include "mbed.h" 00041 00042 /** mpu6000_spi class. 00043 * Used as the driver for the MPU 6000 IMU. Documentation is provided for code written in HEL. 00044 */ 00045 class mpu6000_spi 00046 { 00047 SPI& spi; 00048 DigitalOut cs; 00049 00050 public: 00051 // The following were created as a part of the driver and are not documented 00052 mpu6000_spi(SPI& _spi, PinName _cs); 00053 bool init(int sample_rate_div,int low_pass_filter); 00054 float read_acc(int axis); 00055 float read_rot(int axis); 00056 00057 unsigned int set_gyro_scale(int scale); 00058 unsigned int set_acc_scale(int scale); 00059 int calib_acc(int axis); 00060 float read_temp(); 00061 void select(); 00062 void deselect(); 00063 unsigned int whoami(); 00064 float acc_divider; 00065 float gyro_divider; 00066 00067 /** Collects torso tilt from vertical using accelerometer only. 00068 * @returns Tilt angle relative to vertical 00069 */ 00070 float getAccTilt(); 00071 00072 /** Masks current whoami() value against expected value. 00073 * @returns 00074 * 0 is safe 00075 * 1 is unsafe 00076 */ 00077 int whoamiCheck(); 00078 00079 /** Combines gyro and accelerometer data to find acceleration 00080 * @returns Acceleration in y. 00081 */ 00082 float angle_y(); 00083 00084 /** Finds y acceleration without sampling IMU 00085 * @returns Acceleration in y. 00086 */ 00087 float rereadAngle_y(); 00088 00089 private: 00090 00091 // The following were created as a part of the driver and are not documented 00092 PinName _CS_pin; 00093 PinName _SO_pin; 00094 PinName _SCK_pin; 00095 00096 /** Accelerometer acceleration using a complementary filter. 00097 */ 00098 float accFilterCurrent; 00099 00100 /** Acceleration from accelerometer-only sample. 00101 */ 00102 float accFilterPre; 00103 00104 /** Gyro acceleration using a complementary filter. 00105 */ 00106 float gyroFilterCurrent; 00107 00108 /** Acceleration from accelerometer-only sample. 00109 */ 00110 float gyroFliterPre; 00111 }; 00112 00113 #define pi 3.1415926535898 /* Pi */ 00114 #define pio2 1.5707963267949 /* Pi/2 */ 00115 00116 // MPU6000 registers 00117 #define MPUREG_XG_OFFS_TC 0x00 00118 #define MPUREG_YG_OFFS_TC 0x01 00119 #define MPUREG_ZG_OFFS_TC 0x02 00120 #define MPUREG_X_FINE_GAIN 0x03 00121 #define MPUREG_Y_FINE_GAIN 0x04 00122 #define MPUREG_Z_FINE_GAIN 0x05 00123 #define MPUREG_XA_OFFS_H 0x06 00124 #define MPUREG_XA_OFFS_L 0x07 00125 #define MPUREG_YA_OFFS_H 0x08 00126 #define MPUREG_YA_OFFS_L 0x09 00127 #define MPUREG_ZA_OFFS_H 0x0A 00128 #define MPUREG_ZA_OFFS_L 0x0B 00129 #define MPUREG_PRODUCT_ID 0x0C 00130 #define MPUREG_SELF_TEST_X 0x0D 00131 #define MPUREG_SELF_TEST_Y 0x0E 00132 #define MPUREG_SELF_TEST_Z 0x0F 00133 #define MPUREG_SELF_TEST_A 0x10 00134 #define MPUREG_XG_OFFS_USRH 0x13 00135 #define MPUREG_XG_OFFS_USRL 0x14 00136 #define MPUREG_YG_OFFS_USRH 0x15 00137 #define MPUREG_YG_OFFS_USRL 0x16 00138 #define MPUREG_ZG_OFFS_USRH 0x17 00139 #define MPUREG_ZG_OFFS_USRL 0x18 00140 #define MPUREG_SMPLRT_DIV 0x19 00141 #define MPUREG_CONFIG 0x1A 00142 #define MPUREG_GYRO_CONFIG 0x1B 00143 #define MPUREG_ACCEL_CONFIG 0x1C 00144 #define MPUREG_INT_PIN_CFG 0x37 00145 #define MPUREG_INT_ENABLE 0x38 00146 #define MPUREG_ACCEL_XOUT_H 0x3B 00147 #define MPUREG_ACCEL_XOUT_L 0x3C 00148 #define MPUREG_ACCEL_YOUT_H 0x3D 00149 #define MPUREG_ACCEL_YOUT_L 0x3E 00150 #define MPUREG_ACCEL_ZOUT_H 0x3F 00151 #define MPUREG_ACCEL_ZOUT_L 0x40 00152 #define MPUREG_TEMP_OUT_H 0x41 00153 #define MPUREG_TEMP_OUT_L 0x42 00154 #define MPUREG_GYRO_XOUT_H 0x43 00155 #define MPUREG_GYRO_XOUT_L 0x44 00156 #define MPUREG_GYRO_YOUT_H 0x45 00157 #define MPUREG_GYRO_YOUT_L 0x46 00158 #define MPUREG_GYRO_ZOUT_H 0x47 00159 #define MPUREG_GYRO_ZOUT_L 0x48 00160 #define MPUREG_USER_CTRL 0x6A 00161 #define MPUREG_PWR_MGMT_1 0x6B 00162 #define MPUREG_PWR_MGMT_2 0x6C 00163 #define MPUREG_BANK_SEL 0x6D 00164 #define MPUREG_MEM_START_ADDR 0x6E 00165 #define MPUREG_MEM_R_W 0x6F 00166 #define MPUREG_DMP_CFG_1 0x70 00167 #define MPUREG_DMP_CFG_2 0x71 00168 #define MPUREG_FIFO_COUNTH 0x72 00169 #define MPUREG_FIFO_COUNTL 0x73 00170 #define MPUREG_FIFO_R_W 0x74 00171 #define MPUREG_WHOAMI 0x75 00172 00173 // Configuration bits MPU6000 00174 #define BIT_SLEEP 0x40 00175 #define BIT_H_RESET 0x80 00176 #define BITS_CLKSEL 0x07 00177 #define MPU_CLK_SEL_PLLGYROX 0x01 00178 #define MPU_CLK_SEL_PLLGYROZ 0x03 00179 #define MPU_EXT_SYNC_GYROX 0x02 00180 #define BITS_FS_250DPS 0x00 00181 #define BITS_FS_500DPS 0x08 00182 #define BITS_FS_1000DPS 0x10 00183 #define BITS_FS_2000DPS 0x18 00184 #define BITS_FS_2G 0x00 00185 #define BITS_FS_4G 0x08 00186 #define BITS_FS_8G 0x10 00187 #define BITS_FS_16G 0x18 00188 #define BITS_FS_MASK 0x18 00189 #define BITS_DLPF_CFG_256HZ_NOLPF2 0x00 00190 #define BITS_DLPF_CFG_188HZ 0x01 00191 #define BITS_DLPF_CFG_98HZ 0x02 00192 #define BITS_DLPF_CFG_42HZ 0x03 00193 #define BITS_DLPF_CFG_20HZ 0x04 00194 #define BITS_DLPF_CFG_10HZ 0x05 00195 #define BITS_DLPF_CFG_5HZ 0x06 00196 #define BITS_DLPF_CFG_2100HZ_NOLPF 0x07 00197 #define BITS_DLPF_CFG_MASK 0x07 00198 #define BIT_INT_ANYRD_2CLEAR 0x10 00199 #define BIT_RAW_RDY_EN 0x01 00200 #define BIT_I2C_IF_DIS 0x10 00201 00202 #define READ_FLAG 0x80 00203 00204 #endif
Generated on Tue Jul 19 2022 11:37:55 by 1.7.2