Library for setting and reading the Pololu minIMU 9 v2 sensor

Committer:
Euler
Date:
Sat Oct 26 11:52:29 2013 +0000
Revision:
0:7b70a3ed96c1
Library for setting and reading the Pololu MinIMU 9 v2 sensor.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Euler 0:7b70a3ed96c1 1 #ifndef IMU_H
Euler 0:7b70a3ed96c1 2 #define IMU_H
Euler 0:7b70a3ed96c1 3
Euler 0:7b70a3ed96c1 4 #include "mbed.h"
Euler 0:7b70a3ed96c1 5
Euler 0:7b70a3ed96c1 6 // definitions for the gyro sensor
Euler 0:7b70a3ed96c1 7 #define L3GD20_ADDR 0xD6
Euler 0:7b70a3ed96c1 8 #define L3GD20_CTRL_REG1 0x20
Euler 0:7b70a3ed96c1 9 #define L3GD20_CTRL_REG4 0x23
Euler 0:7b70a3ed96c1 10 #define L3GD20_STATUS_REG 0x27
Euler 0:7b70a3ed96c1 11 #define L3GD20_OUT_X_L 0x28
Euler 0:7b70a3ed96c1 12 #define L3GD20_RANGE_250DPS 0x00 // Measurement range selected by CTRL_REG4
Euler 0:7b70a3ed96c1 13 #define L3GD20_RANGE_500DPS 0x01 // Default range = 250 Degree-per-Second = 0.7 rev/second
Euler 0:7b70a3ed96c1 14 #define L3GD20_RANGE_2000DPS 0x02 // Range determines Sensitivity
Euler 0:7b70a3ed96c1 15 #define L3GD20_SENSITIVITY_250DPS 0.00875 // Roughly 22/256 for fixed point match
Euler 0:7b70a3ed96c1 16 #define L3GD20_SENSITIVITY_500DPS 0.0175 // Roughly 45/256
Euler 0:7b70a3ed96c1 17 #define L3GD20_SENSITIVITY_2000DPS 0.070 // Roughly 18/256
Euler 0:7b70a3ed96c1 18 #define L3GD20_DPS_TO_RADS 0.017453293 // = pi/180 degrees/s to rad/s multiplier
Euler 0:7b70a3ed96c1 19
Euler 0:7b70a3ed96c1 20
Euler 0:7b70a3ed96c1 21 // definitions for the accelerometer
Euler 0:7b70a3ed96c1 22 #define LSM303_A_ADDR 0x32 // address for writing. +1 for reading, see manual p. 20/42.
Euler 0:7b70a3ed96c1 23 #define LSM303_A_CTRL_REG1 0x20
Euler 0:7b70a3ed96c1 24 #define LSM303_A_CTRL_REG4 0x23
Euler 0:7b70a3ed96c1 25 #define LSM303_A_OUT_X_L 0x28
Euler 0:7b70a3ed96c1 26 #define LSM303_A_FS_2G 0x00 // Full Scale measuremetn range - selected by CTRL_REG4
Euler 0:7b70a3ed96c1 27 #define LSM303_A_Sensitivity 0.001 // Linear acceleration sensitivity
Euler 0:7b70a3ed96c1 28 #define LSM303_A_GRAVITY_EARTH 9.80665 // Earth's gravity in m/s^2 upon calibration of sensor
Euler 0:7b70a3ed96c1 29
Euler 0:7b70a3ed96c1 30 // definitions for the magnetic sensor
Euler 0:7b70a3ed96c1 31 #define LSM303_M_ADDR 0x3C // address for writing. +1 for reading, see datasheet p. 21/42.
Euler 0:7b70a3ed96c1 32 #define LSM303_M_CRA_REG 0x00
Euler 0:7b70a3ed96c1 33 #define LSM303_M_CRB_REG 0x01
Euler 0:7b70a3ed96c1 34 #define LSM303_M_MR_REG 0x02
Euler 0:7b70a3ed96c1 35 #define LSM303_M_OUT_X_H 0x03 // Watch out: order of H and L reversed
Euler 0:7b70a3ed96c1 36 #define LSM303_M_FS_13G 0x01 // Full Scale measuremetn range - selected by CRB_REG
Euler 0:7b70a3ed96c1 37 #define LSM303_M_Sensitivity 1100 // Corresponding sensitivity = 1100 Bits/Gauss
Euler 0:7b70a3ed96c1 38
Euler 0:7b70a3ed96c1 39
Euler 0:7b70a3ed96c1 40 class IMU
Euler 0:7b70a3ed96c1 41 {
Euler 0:7b70a3ed96c1 42 public:
Euler 0:7b70a3ed96c1 43 /* constructor */
Euler 0:7b70a3ed96c1 44 IMU(PinName sda, PinName scl);
Euler 0:7b70a3ed96c1 45
Euler 0:7b70a3ed96c1 46 /* accessible functions */
Euler 0:7b70a3ed96c1 47 char init(void);
Euler 0:7b70a3ed96c1 48 char readData(float *);
Euler 0:7b70a3ed96c1 49 void filterData(float *, double *);
Euler 0:7b70a3ed96c1 50
Euler 0:7b70a3ed96c1 51 private:
Euler 0:7b70a3ed96c1 52 I2C _i2c;
Euler 0:7b70a3ed96c1 53 char address;
Euler 0:7b70a3ed96c1 54 int16_t L3GD20_biasX; /* digit counts */
Euler 0:7b70a3ed96c1 55 int16_t L3GD20_biasY;
Euler 0:7b70a3ed96c1 56 int16_t L3GD20_biasZ;
Euler 0:7b70a3ed96c1 57 double g_0;
Euler 0:7b70a3ed96c1 58 double FF[3];
Euler 0:7b70a3ed96c1 59 double FD[6][9];
Euler 0:7b70a3ed96c1 60 };
Euler 0:7b70a3ed96c1 61
Euler 0:7b70a3ed96c1 62 #endif