Dydaktyka

Dependencies:   FastPWM mbed-src

Fork of 2015_04_17_quadro_bez_sterowania by Quadrocopter

Committer:
Michu90
Date:
Fri Apr 17 14:25:25 2015 +0000
Revision:
12:e955cc086c42
Parent:
8:dc48ce79ad59
Dydaktyka

Who changed what in which revision?

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