Corrected header file include guards.
Fork of IMUdriver by
Diff: MPU6000.h
- Revision:
- 5:db1da6bc9dce
- Parent:
- 4:492c7470dbfb
- Child:
- 6:d9198ff2dcf9
--- a/MPU6000.h Mon Apr 13 17:43:19 2015 +0000 +++ b/MPU6000.h Wed Jun 03 17:32:43 2015 +0000 @@ -1,49 +1,52 @@ -/*CODED by Bruno Alfano on 07/03/2014 -www.xene.it - -USAGE (example program): -#include "mbed.h" -#include "MPU6000.h" //Include library -SPI spi(p11, p12, p13); //define the SPI (mosi, miso, sclk) -mpu6000_spi imu(spi,p22); //define the mpu6000 object -int main(){ - if(imu.init(1,BITS_DLPF_CFG_5HZ)){ //INIT the mpu6000 - printf("\nCouldn't initialize MPU6000 via SPI!"); - } - wait(0.1); - printf("\n\nWHOAMI=%u\n",imu.whoami()); //output the I2C address to know if SPI is working, it should be 104 - wait(0.1); - printf("\nGyro_scale=%u\n",imu.set_gyro_scale(BITS_FS_2000DPS)); //Set full scale range for gyros - wait(1); - printf("\nAcc_scale=%u\n",imu.set_acc_scale(BITS_FS_16G)); //Set full scale range for accs - wait(0.1); - while(1) { - myled = 1; - wait(0.3); - myled = 0; - wait(0.3); - printf("\nT=%.3f",imu.read_temp()); - printf(" X=%.3f",imu.read_acc(0)); - printf(" Y=%.3f",imu.read_acc(1)); - printf(" Z=%.3f",imu.read_acc(2)); - printf(" rX=%.3f",imu.read_rot(0)); - printf(" rY=%.3f",imu.read_rot(1)); - printf(" rZ=%.3f",imu.read_rot(2)); - } -} +/** CODED by Bruno Alfano on 07/03/2014 +* www.xene.it +* +* Example: +* @code +* #include "mbed.h" +* #include "MPU6000.h" //Include library +* SPI spi(p11, p12, p13); //define the SPI (mosi, miso, sclk) +* mpu6000_spi imu(spi,p22); //define the mpu6000 object +* int main(){ +* if(imu.init(1,BITS_DLPF_CFG_5HZ)){ //INIT the mpu6000 + * printf("\nCouldn't initialize MPU6000 via SPI!"); +* } +* wait(0.1); +* printf("\n\nWHOAMI=%u\n",imu.whoami()); //output the I2C address to know if SPI is working, it should be 104 +* wait(0.1); +* printf("\nGyro_scale=%u\n",imu.set_gyro_scale(BITS_FS_2000DPS)); //Set full scale range for gyros +* wait(1); +* printf("\nAcc_scale=%u\n",imu.set_acc_scale(BITS_FS_16G)); //Set full scale range for accs +* wait(0.1); +* while(1) { +* myled = 1; +* wait(0.3); +* myled = 0; +* wait(0.3); +* printf("\nT=%.3f",imu.read_temp()); +* printf(" X=%.3f",imu.read_acc(0)); +* printf(" Y=%.3f",imu.read_acc(1)); +* printf(" Z=%.3f",imu.read_acc(2)); +* printf(" rX=%.3f",imu.read_rot(0)); +* printf(" rY=%.3f",imu.read_rot(1)); + * printf(" rZ=%.3f",imu.read_rot(2)); +* } +* } +* @endcode */ - + #ifndef MPU6000_h #define MPU6000_h #include "mbed.h" - - + +/** class +*/ class mpu6000_spi { SPI& spi; DigitalOut cs; - - public: + +public: mpu6000_spi(SPI& _spi, PinName _cs); bool init(int sample_rate_div,int low_pass_filter); float read_acc(int axis); @@ -57,7 +60,7 @@ void select(); void deselect(); unsigned int whoami(); - + /** Create whoami_check() instance. * whoami_check() masks current whoami() value against expected value. * @returns @@ -65,31 +68,35 @@ * 1 is unsafe */ int whoami_check(); - - // not used, need to remove HMC 2/25/15 - int who_error; - + float acc_divider; float gyro_divider; + //added float angle_y(); + //added float read_angle_y(); - - private: + +private: PinName _CS_pin; PinName _SO_pin; PinName _SCK_pin; + //added float _error; + //added float accFilterCurrent; + //added float accFilterPre; + //added float gyroFilterCurrent; + //added float gyroFliterPre; }; - + #endif #define pi 3.1415926535898 /* Pi */ #define pio2 1.5707963267949 /* Pi/2 */ - + // MPU6000 registers #define MPUREG_XG_OFFS_TC 0x00 #define MPUREG_YG_OFFS_TC 0x01 @@ -146,7 +153,7 @@ #define MPUREG_FIFO_COUNTL 0x73 #define MPUREG_FIFO_R_W 0x74 #define MPUREG_WHOAMI 0x75 - + // Configuration bits MPU6000 #define BIT_SLEEP 0x40 #define BIT_H_RESET 0x80 @@ -175,5 +182,5 @@ #define BIT_INT_ANYRD_2CLEAR 0x10 #define BIT_RAW_RDY_EN 0x01 #define BIT_I2C_IF_DIS 0x10 - + #define READ_FLAG 0x80 \ No newline at end of file