LSM9DS1 the other library

Fork of LSM9DS1 by Sherry Yang

Committer:
benson516
Date:
Mon Jun 19 02:25:48 2017 +0000
Revision:
8:16e88babd42a
Parent:
6:28c4b3c8b43d
Fix bugs in setting resolutions

Who changed what in which revision?

UserRevisionLine numberNew contents of line
beanmachine44 0:622e8874902e 1 // Most of the Credit goes to jimblom
beanmachine44 0:622e8874902e 2 // Modifications by Allen Wild
beanmachine44 0:622e8874902e 3 #ifndef _LSM9DS1_H__
beanmachine44 0:622e8874902e 4 #define _LSM9DS1_H__
beanmachine44 0:622e8874902e 5
beanmachine44 0:622e8874902e 6 #include "mbed.h"
beanmachine44 0:622e8874902e 7
beanmachine44 0:622e8874902e 8 /////////////////////////////////////////
beanmachine44 0:622e8874902e 9 // LSM9DS1 Accel/Gyro (XL/G) Registers //
beanmachine44 0:622e8874902e 10 /////////////////////////////////////////
beanmachine44 0:622e8874902e 11 #define ACT_THS 0x04
beanmachine44 0:622e8874902e 12 #define ACT_DUR 0x05
beanmachine44 0:622e8874902e 13 #define INT_GEN_CFG_XL 0x06
beanmachine44 0:622e8874902e 14 #define INT_GEN_THS_X_XL 0x07
beanmachine44 0:622e8874902e 15 #define INT_GEN_THS_Y_XL 0x08
beanmachine44 0:622e8874902e 16 #define INT_GEN_THS_Z_XL 0x09
beanmachine44 0:622e8874902e 17 #define INT_GEN_DUR_XL 0x0A
beanmachine44 0:622e8874902e 18 #define REFERENCE_G 0x0B
beanmachine44 0:622e8874902e 19 #define INT1_CTRL 0x0C
beanmachine44 0:622e8874902e 20 #define INT2_CTRL 0x0D
beanmachine44 0:622e8874902e 21 #define WHO_AM_I_XG 0x0F
beanmachine44 0:622e8874902e 22 #define CTRL_REG1_G 0x10
beanmachine44 0:622e8874902e 23 #define CTRL_REG2_G 0x11
beanmachine44 0:622e8874902e 24 #define CTRL_REG3_G 0x12
beanmachine44 0:622e8874902e 25 #define ORIENT_CFG_G 0x13
beanmachine44 0:622e8874902e 26 #define INT_GEN_SRC_G 0x14
beanmachine44 0:622e8874902e 27 #define OUT_TEMP_L 0x15
beanmachine44 0:622e8874902e 28 #define OUT_TEMP_H 0x16
beanmachine44 0:622e8874902e 29 #define STATUS_REG_0 0x17
beanmachine44 0:622e8874902e 30 #define OUT_X_L_G 0x18
beanmachine44 0:622e8874902e 31 #define OUT_X_H_G 0x19
beanmachine44 0:622e8874902e 32 #define OUT_Y_L_G 0x1A
beanmachine44 0:622e8874902e 33 #define OUT_Y_H_G 0x1B
beanmachine44 0:622e8874902e 34 #define OUT_Z_L_G 0x1C
beanmachine44 0:622e8874902e 35 #define OUT_Z_H_G 0x1D
beanmachine44 0:622e8874902e 36 #define CTRL_REG4 0x1E
beanmachine44 0:622e8874902e 37 #define CTRL_REG5_XL 0x1F
beanmachine44 0:622e8874902e 38 #define CTRL_REG6_XL 0x20
beanmachine44 0:622e8874902e 39 #define CTRL_REG7_XL 0x21
beanmachine44 0:622e8874902e 40 #define CTRL_REG8 0x22
beanmachine44 0:622e8874902e 41 #define CTRL_REG9 0x23
beanmachine44 0:622e8874902e 42 #define CTRL_REG10 0x24
beanmachine44 0:622e8874902e 43 #define INT_GEN_SRC_XL 0x26
beanmachine44 0:622e8874902e 44 #define STATUS_REG_1 0x27
beanmachine44 0:622e8874902e 45 #define OUT_X_L_XL 0x28
beanmachine44 0:622e8874902e 46 #define OUT_X_H_XL 0x29
beanmachine44 0:622e8874902e 47 #define OUT_Y_L_XL 0x2A
beanmachine44 0:622e8874902e 48 #define OUT_Y_H_XL 0x2B
beanmachine44 0:622e8874902e 49 #define OUT_Z_L_XL 0x2C
beanmachine44 0:622e8874902e 50 #define OUT_Z_H_XL 0x2D
beanmachine44 0:622e8874902e 51 #define FIFO_CTRL 0x2E
beanmachine44 0:622e8874902e 52 #define FIFO_SRC 0x2F
beanmachine44 0:622e8874902e 53 #define INT_GEN_CFG_G 0x30
beanmachine44 0:622e8874902e 54 #define INT_GEN_THS_XH_G 0x31
beanmachine44 0:622e8874902e 55 #define INT_GEN_THS_XL_G 0x32
beanmachine44 0:622e8874902e 56 #define INT_GEN_THS_YH_G 0x33
beanmachine44 0:622e8874902e 57 #define INT_GEN_THS_YL_G 0x34
beanmachine44 0:622e8874902e 58 #define INT_GEN_THS_ZH_G 0x35
beanmachine44 0:622e8874902e 59 #define INT_GEN_THS_ZL_G 0x36
beanmachine44 0:622e8874902e 60 #define INT_GEN_DUR_G 0x37
beanmachine44 0:622e8874902e 61
beanmachine44 0:622e8874902e 62 ///////////////////////////////
beanmachine44 0:622e8874902e 63 // LSM9DS1 Magneto Registers //
beanmachine44 0:622e8874902e 64 ///////////////////////////////
beanmachine44 0:622e8874902e 65 #define OFFSET_X_REG_L_M 0x05
beanmachine44 0:622e8874902e 66 #define OFFSET_X_REG_H_M 0x06
beanmachine44 0:622e8874902e 67 #define OFFSET_Y_REG_L_M 0x07
beanmachine44 0:622e8874902e 68 #define OFFSET_Y_REG_H_M 0x08
beanmachine44 0:622e8874902e 69 #define OFFSET_Z_REG_L_M 0x09
beanmachine44 0:622e8874902e 70 #define OFFSET_Z_REG_H_M 0x0A
beanmachine44 0:622e8874902e 71 #define WHO_AM_I_M 0x0F
beanmachine44 0:622e8874902e 72 #define CTRL_REG1_M 0x20
beanmachine44 0:622e8874902e 73 #define CTRL_REG2_M 0x21
beanmachine44 0:622e8874902e 74 #define CTRL_REG3_M 0x22
beanmachine44 0:622e8874902e 75 #define CTRL_REG4_M 0x23
beanmachine44 0:622e8874902e 76 #define CTRL_REG5_M 0x24
beanmachine44 0:622e8874902e 77 #define STATUS_REG_M 0x27
beanmachine44 0:622e8874902e 78 #define OUT_X_L_M 0x28
beanmachine44 0:622e8874902e 79 #define OUT_X_H_M 0x29
beanmachine44 0:622e8874902e 80 #define OUT_Y_L_M 0x2A
beanmachine44 0:622e8874902e 81 #define OUT_Y_H_M 0x2B
beanmachine44 0:622e8874902e 82 #define OUT_Z_L_M 0x2C
beanmachine44 0:622e8874902e 83 #define OUT_Z_H_M 0x2D
beanmachine44 0:622e8874902e 84 #define INT_CFG_M 0x30
beanmachine44 0:622e8874902e 85 #define INT_SRC_M 0x30
beanmachine44 0:622e8874902e 86 #define INT_THS_L_M 0x32
beanmachine44 0:622e8874902e 87 #define INT_THS_H_M 0x33
beanmachine44 0:622e8874902e 88
beanmachine44 0:622e8874902e 89 ////////////////////////////////
beanmachine44 0:622e8874902e 90 // LSM9DS1 WHO_AM_I Responses //
beanmachine44 0:622e8874902e 91 ////////////////////////////////
beanmachine44 0:622e8874902e 92 #define WHO_AM_I_AG_RSP 0x68
beanmachine44 0:622e8874902e 93 #define WHO_AM_I_M_RSP 0x3D
beanmachine44 0:622e8874902e 94
beanmachine44 0:622e8874902e 95 // Possible I2C addresses for the accel/gyro and mag
beanmachine44 0:622e8874902e 96 #define LSM9DS1_AG_I2C_ADDR(sa0) ((sa0) ? 0xD6 : 0xD4)
beanmachine44 0:622e8874902e 97 #define LSM9DS1_M_I2C_ADDR(sa1) ((sa1) ? 0x3C : 0x38)
beanmachine44 0:622e8874902e 98
beanmachine44 0:622e8874902e 99 /**
beanmachine44 0:622e8874902e 100 * LSM9DS1 Class - driver for the 9 DoF IMU
beanmachine44 0:622e8874902e 101 */
beanmachine44 0:622e8874902e 102 class LSM9DS1
beanmachine44 0:622e8874902e 103 {
beanmachine44 0:622e8874902e 104 public:
beanmachine44 0:622e8874902e 105
beanmachine44 0:622e8874902e 106 /// gyro_scale defines the possible full-scale ranges of the gyroscope:
benson516 8:16e88babd42a 107 /*
beanmachine44 0:622e8874902e 108 enum gyro_scale
beanmachine44 0:622e8874902e 109 {
beanmachine44 0:622e8874902e 110 G_SCALE_245DPS = 0x0 << 3, // 00 << 3: +/- 245 degrees per second
beanmachine44 0:622e8874902e 111 G_SCALE_500DPS = 0x1 << 3, // 01 << 3: +/- 500 dps
beanmachine44 0:622e8874902e 112 G_SCALE_2000DPS = 0x3 << 3 // 11 << 3: +/- 2000 dps
beanmachine44 0:622e8874902e 113 };
benson516 8:16e88babd42a 114 */
benson516 8:16e88babd42a 115 enum gyro_scale
benson516 8:16e88babd42a 116 {
benson516 8:16e88babd42a 117 G_SCALE_245DPS = 0x0, // 00: +/- 245 degrees per second
benson516 8:16e88babd42a 118 G_SCALE_500DPS = 0x1, // 01: +/- 500 dps
benson516 8:16e88babd42a 119 G_SCALE_2000DPS = 0x3 // 11: +/- 2000 dps
benson516 8:16e88babd42a 120 };
beanmachine44 0:622e8874902e 121
beanmachine44 0:622e8874902e 122 /// gyro_odr defines all possible data rate/bandwidth combos of the gyro:
beanmachine44 0:622e8874902e 123 enum gyro_odr
beanmachine44 0:622e8874902e 124 { // ODR (Hz) --- Cutoff
beanmachine44 0:622e8874902e 125 G_POWER_DOWN = 0x00, // 0 0
beanmachine44 0:622e8874902e 126 G_ODR_15_BW_0 = 0x20, // 14.9 0
beanmachine44 0:622e8874902e 127 G_ODR_60_BW_16 = 0x40, // 59.5 16
beanmachine44 0:622e8874902e 128 G_ODR_119_BW_14 = 0x60, // 119 14
beanmachine44 0:622e8874902e 129 G_ODR_119_BW_31 = 0x61, // 119 31
beanmachine44 0:622e8874902e 130 G_ODR_238_BW_14 = 0x80, // 238 14
beanmachine44 0:622e8874902e 131 G_ODR_238_BW_29 = 0x81, // 238 29
beanmachine44 0:622e8874902e 132 G_ODR_238_BW_63 = 0x82, // 238 63
beanmachine44 0:622e8874902e 133 G_ODR_238_BW_78 = 0x83, // 238 78
beanmachine44 0:622e8874902e 134 G_ODR_476_BW_21 = 0xA0, // 476 21
beanmachine44 0:622e8874902e 135 G_ODR_476_BW_28 = 0xA1, // 476 28
beanmachine44 0:622e8874902e 136 G_ODR_476_BW_57 = 0xA2, // 476 57
beanmachine44 0:622e8874902e 137 G_ODR_476_BW_100 = 0xA3, // 476 100
beanmachine44 0:622e8874902e 138 G_ODR_952_BW_33 = 0xC0, // 952 33
beanmachine44 0:622e8874902e 139 G_ODR_952_BW_40 = 0xC1, // 952 40
beanmachine44 0:622e8874902e 140 G_ODR_952_BW_58 = 0xC2, // 952 58
beanmachine44 0:622e8874902e 141 G_ODR_952_BW_100 = 0xC3 // 952 100
beanmachine44 0:622e8874902e 142 };
beanmachine44 0:622e8874902e 143
beanmachine44 0:622e8874902e 144 /// accel_scale defines all possible FSR's of the accelerometer:
beanmachine44 0:622e8874902e 145 enum accel_scale
beanmachine44 0:622e8874902e 146 {
beanmachine44 0:622e8874902e 147 A_SCALE_2G, // 00: +/- 2g
beanmachine44 0:622e8874902e 148 A_SCALE_16G,// 01: +/- 16g
beanmachine44 0:622e8874902e 149 A_SCALE_4G, // 10: +/- 4g
beanmachine44 0:622e8874902e 150 A_SCALE_8G // 11: +/- 8g
beanmachine44 0:622e8874902e 151 };
beanmachine44 0:622e8874902e 152
beanmachine44 0:622e8874902e 153 /// accel_oder defines all possible output data rates of the accelerometer:
beanmachine44 0:622e8874902e 154 enum accel_odr
beanmachine44 0:622e8874902e 155 {
beanmachine44 0:622e8874902e 156 A_POWER_DOWN, // Power-down mode (0x0)
beanmachine44 0:622e8874902e 157 A_ODR_10, // 10 Hz (0x1)
beanmachine44 0:622e8874902e 158 A_ODR_50, // 50 Hz (0x2)
beanmachine44 0:622e8874902e 159 A_ODR_119, // 119 Hz (0x3)
beanmachine44 0:622e8874902e 160 A_ODR_238, // 238 Hz (0x4)
beanmachine44 0:622e8874902e 161 A_ODR_476, // 476 Hz (0x5)
beanmachine44 0:622e8874902e 162 A_ODR_952 // 952 Hz (0x6)
beanmachine44 0:622e8874902e 163 };
beanmachine44 0:622e8874902e 164
beanmachine44 0:622e8874902e 165 // accel_bw defines all possible bandwiths for low-pass filter of the accelerometer:
beanmachine44 0:622e8874902e 166 enum accel_bw
beanmachine44 0:622e8874902e 167 {
beanmachine44 0:622e8874902e 168 A_BW_AUTO_SCALE = 0x0, // Automatic BW scaling (0x0)
beanmachine44 0:622e8874902e 169 A_BW_408 = 0x4, // 408 Hz (0x4)
beanmachine44 0:622e8874902e 170 A_BW_211 = 0x5, // 211 Hz (0x5)
beanmachine44 0:622e8874902e 171 A_BW_105 = 0x6, // 105 Hz (0x6)
beanmachine44 0:622e8874902e 172 A_BW_50 = 0x7 // 50 Hz (0x7)
beanmachine44 0:622e8874902e 173 };
beanmachine44 0:622e8874902e 174
beanmachine44 0:622e8874902e 175 /// mag_scale defines all possible FSR's of the magnetometer:
beanmachine44 0:622e8874902e 176 enum mag_scale
beanmachine44 0:622e8874902e 177 {
beanmachine44 0:622e8874902e 178 M_SCALE_4GS, // 00: +/- 4Gs
beanmachine44 0:622e8874902e 179 M_SCALE_8GS, // 01: +/- 8Gs
beanmachine44 0:622e8874902e 180 M_SCALE_12GS, // 10: +/- 12Gs
beanmachine44 0:622e8874902e 181 M_SCALE_16GS, // 11: +/- 16Gs
beanmachine44 0:622e8874902e 182 };
beanmachine44 0:622e8874902e 183
beanmachine44 0:622e8874902e 184 /// mag_odr defines all possible output data rates of the magnetometer:
beanmachine44 0:622e8874902e 185 enum mag_odr
beanmachine44 0:622e8874902e 186 {
beanmachine44 0:622e8874902e 187 M_ODR_0625, // 0.625 Hz (0x00)
beanmachine44 0:622e8874902e 188 M_ODR_125, // 1.25 Hz (0x01)
beanmachine44 0:622e8874902e 189 M_ODR_25, // 2.5 Hz (0x02)
beanmachine44 0:622e8874902e 190 M_ODR_5, // 5 Hz (0x03)
beanmachine44 0:622e8874902e 191 M_ODR_10, // 10 (0x04)
beanmachine44 0:622e8874902e 192 M_ODR_20, // 20 Hz (0x05)
beanmachine44 0:622e8874902e 193 M_ODR_40, // 40 Hz (0x06)
beanmachine44 0:622e8874902e 194 M_ODR_80 // 80 Hz (0x07)
beanmachine44 0:622e8874902e 195 };
beanmachine44 0:622e8874902e 196
beanmachine44 0:622e8874902e 197 // We'll store the gyro, accel, and magnetometer readings in a series of
beanmachine44 0:622e8874902e 198 // public class variables. Each sensor gets three variables -- one for each
beanmachine44 0:622e8874902e 199 // axis. Call readGyro(), readAccel(), and readMag() first, before using
beanmachine44 0:622e8874902e 200 // these variables!
beanmachine44 0:622e8874902e 201 // These values are the RAW signed 16-bit readings from the sensors.
beanmachine44 0:622e8874902e 202 int16_t gx_raw, gy_raw, gz_raw; // x, y, and z axis readings of the gyroscope
beanmachine44 0:622e8874902e 203 int16_t ax_raw, ay_raw, az_raw; // x, y, and z axis readings of the accelerometer
beanmachine44 0:622e8874902e 204 int16_t mx_raw, my_raw, mz_raw; // x, y, and z axis readings of the magnetometer
beanmachine44 0:622e8874902e 205 int16_t temperature_raw;
benson516 8:16e88babd42a 206 int16_t gBiasRaw[3], aBiasRaw[3];
beanmachine44 0:622e8874902e 207
beanmachine44 0:622e8874902e 208 // floating-point values of scaled data in real-world units
beanmachine44 0:622e8874902e 209 float gx, gy, gz;
beanmachine44 0:622e8874902e 210 float ax, ay, az;
beanmachine44 0:622e8874902e 211 float mx, my, mz;
beanmachine44 0:622e8874902e 212 float temperature_c, temperature_f; // temperature in celcius and fahrenheit
5hel2l2y 3:f96b287c0bf7 213 float intr;
ChangYuHsuan 6:28c4b3c8b43d 214 float gBias[3], aBias[3];
beanmachine44 0:622e8874902e 215
ChangYuHsuan 6:28c4b3c8b43d 216 bool autoCalib;
benson516 8:16e88babd42a 217
beanmachine44 0:622e8874902e 218 /** LSM9DS1 -- LSM9DS1 class constructor
beanmachine44 0:622e8874902e 219 * The constructor will set up a handful of private variables, and set the
beanmachine44 0:622e8874902e 220 * communication mode as well.
beanmachine44 0:622e8874902e 221 * Input:
beanmachine44 0:622e8874902e 222 * - interface = Either MODE_SPI or MODE_I2C, whichever you're using
beanmachine44 0:622e8874902e 223 * to talk to the IC.
beanmachine44 0:622e8874902e 224 * - xgAddr = If MODE_I2C, this is the I2C address of the accel/gyro.
beanmachine44 0:622e8874902e 225 * If MODE_SPI, this is the chip select pin of the accel/gyro (CS_A/G)
beanmachine44 0:622e8874902e 226 * - mAddr = If MODE_I2C, this is the I2C address of the mag.
beanmachine44 0:622e8874902e 227 * If MODE_SPI, this is the cs pin of the mag (CS_M)
beanmachine44 0:622e8874902e 228 */
beanmachine44 0:622e8874902e 229 LSM9DS1(PinName sda, PinName scl, uint8_t xgAddr = LSM9DS1_AG_I2C_ADDR(1), uint8_t mAddr = LSM9DS1_M_I2C_ADDR(1));
benson516 8:16e88babd42a 230
beanmachine44 0:622e8874902e 231 /** begin() -- Initialize the gyro, accelerometer, and magnetometer.
beanmachine44 0:622e8874902e 232 * This will set up the scale and output rate of each sensor. It'll also
beanmachine44 0:622e8874902e 233 * "turn on" every sensor and every axis of every sensor.
beanmachine44 0:622e8874902e 234 * Input:
beanmachine44 0:622e8874902e 235 * - gScl = The scale of the gyroscope. This should be a gyro_scale value.
beanmachine44 0:622e8874902e 236 * - aScl = The scale of the accelerometer. Should be a accel_scale value.
beanmachine44 0:622e8874902e 237 * - mScl = The scale of the magnetometer. Should be a mag_scale value.
beanmachine44 0:622e8874902e 238 * - gODR = Output data rate of the gyroscope. gyro_odr value.
beanmachine44 0:622e8874902e 239 * - aODR = Output data rate of the accelerometer. accel_odr value.
beanmachine44 0:622e8874902e 240 * - mODR = Output data rate of the magnetometer. mag_odr value.
beanmachine44 0:622e8874902e 241 * Output: The function will return an unsigned 16-bit value. The most-sig
beanmachine44 0:622e8874902e 242 * bytes of the output are the WHO_AM_I reading of the accel/gyro. The
beanmachine44 0:622e8874902e 243 * least significant two bytes are the WHO_AM_I reading of the mag.
beanmachine44 0:622e8874902e 244 * All parameters have a defaulted value, so you can call just "begin()".
benson516 8:16e88babd42a 245 * Default values are FSR's of: +/- 245DPS, 4g, 2Gs; ODRs of 119 Hz for
beanmachine44 0:622e8874902e 246 * gyro, 119 Hz for accelerometer, 80 Hz for magnetometer.
beanmachine44 0:622e8874902e 247 * Use the return value of this function to verify communication.
beanmachine44 0:622e8874902e 248 */
benson516 8:16e88babd42a 249 bool begin(gyro_scale gScl = G_SCALE_2000DPS,
benson516 8:16e88babd42a 250 accel_scale aScl = A_SCALE_8G, mag_scale mScl = M_SCALE_4GS,
benson516 8:16e88babd42a 251 gyro_odr gODR = G_ODR_119_BW_31, accel_odr aODR = A_ODR_119,
beanmachine44 0:622e8874902e 252 mag_odr mODR = M_ODR_80);
benson516 8:16e88babd42a 253
beanmachine44 0:622e8874902e 254 /** readGyro() -- Read the gyroscope output registers.
beanmachine44 0:622e8874902e 255 * This function will read all six gyroscope output registers.
beanmachine44 0:622e8874902e 256 * The readings are stored in the class' gx_raw, gy_raw, and gz_raw variables. Read
beanmachine44 0:622e8874902e 257 * those _after_ calling readGyro().
beanmachine44 0:622e8874902e 258 */
beanmachine44 0:622e8874902e 259 void readGyro();
benson516 8:16e88babd42a 260
beanmachine44 0:622e8874902e 261 /** readAccel() -- Read the accelerometer output registers.
beanmachine44 0:622e8874902e 262 * This function will read all six accelerometer output registers.
beanmachine44 0:622e8874902e 263 * The readings are stored in the class' ax_raw, ay_raw, and az_raw variables. Read
beanmachine44 0:622e8874902e 264 * those _after_ calling readAccel().
beanmachine44 0:622e8874902e 265 */
beanmachine44 0:622e8874902e 266 void readAccel();
benson516 8:16e88babd42a 267
beanmachine44 0:622e8874902e 268 /** readMag() -- Read the magnetometer output registers.
beanmachine44 0:622e8874902e 269 * This function will read all six magnetometer output registers.
beanmachine44 0:622e8874902e 270 * The readings are stored in the class' mx_raw, my_raw, and mz_raw variables. Read
beanmachine44 0:622e8874902e 271 * those _after_ calling readMag().
beanmachine44 0:622e8874902e 272 */
beanmachine44 0:622e8874902e 273 void readMag();
benson516 8:16e88babd42a 274
5hel2l2y 4:7ffcb378cfd4 275 /** Read Interrupt **/
5hel2l2y 3:f96b287c0bf7 276 void readIntr();
benson516 8:16e88babd42a 277
beanmachine44 0:622e8874902e 278 /** readTemp() -- Read the temperature output register.
beanmachine44 0:622e8874902e 279 * This function will read two temperature output registers.
beanmachine44 0:622e8874902e 280 * The combined readings are stored in the class' temperature variables. Read
beanmachine44 0:622e8874902e 281 * those _after_ calling readTemp().
beanmachine44 0:622e8874902e 282 */
beanmachine44 0:622e8874902e 283 void readTemp();
benson516 8:16e88babd42a 284
ChangYuHsuan 6:28c4b3c8b43d 285 /** calibration() -- Calibrate Accel and Gyro sensor
ChangYuHsuan 6:28c4b3c8b43d 286 */
ChangYuHsuan 6:28c4b3c8b43d 287 void calibration();
benson516 8:16e88babd42a 288
beanmachine44 0:622e8874902e 289 /** setGyroScale() -- Set the full-scale range of the gyroscope.
benson516 8:16e88babd42a 290 * This function can be called to set the scale of the gyroscope to
beanmachine44 1:0e76f237c23d 291 * 245, 500, or 2000 degrees per second.
beanmachine44 0:622e8874902e 292 * Input:
beanmachine44 0:622e8874902e 293 * - gScl = The desired gyroscope scale. Must be one of three possible
beanmachine44 0:622e8874902e 294 * values from the gyro_scale enum.
beanmachine44 0:622e8874902e 295 */
beanmachine44 0:622e8874902e 296 void setGyroScale(gyro_scale gScl);
benson516 8:16e88babd42a 297
beanmachine44 0:622e8874902e 298 /** setAccelScale() -- Set the full-scale range of the accelerometer.
beanmachine44 0:622e8874902e 299 * This function can be called to set the scale of the accelerometer to
beanmachine44 1:0e76f237c23d 300 * 2, 4, 8, or 16 g's.
beanmachine44 0:622e8874902e 301 * Input:
beanmachine44 0:622e8874902e 302 * - aScl = The desired accelerometer scale. Must be one of five possible
beanmachine44 0:622e8874902e 303 * values from the accel_scale enum.
beanmachine44 0:622e8874902e 304 */
beanmachine44 0:622e8874902e 305 void setAccelScale(accel_scale aScl);
benson516 8:16e88babd42a 306
beanmachine44 0:622e8874902e 307 /** setMagScale() -- Set the full-scale range of the magnetometer.
beanmachine44 0:622e8874902e 308 * This function can be called to set the scale of the magnetometer to
beanmachine44 1:0e76f237c23d 309 * 4, 8, 12, or 16 Gs.
beanmachine44 0:622e8874902e 310 * Input:
beanmachine44 0:622e8874902e 311 * - mScl = The desired magnetometer scale. Must be one of four possible
beanmachine44 0:622e8874902e 312 * values from the mag_scale enum.
beanmachine44 0:622e8874902e 313 */
beanmachine44 0:622e8874902e 314 void setMagScale(mag_scale mScl);
benson516 8:16e88babd42a 315
beanmachine44 0:622e8874902e 316 /** setGyroODR() -- Set the output data rate and bandwidth of the gyroscope
beanmachine44 0:622e8874902e 317 * Input:
beanmachine44 0:622e8874902e 318 * - gRate = The desired output rate and cutoff frequency of the gyro.
beanmachine44 1:0e76f237c23d 319 * Must be a value from the gyro_odr enum (check above).
beanmachine44 0:622e8874902e 320 */
beanmachine44 0:622e8874902e 321 void setGyroODR(gyro_odr gRate);
benson516 8:16e88babd42a 322
beanmachine44 0:622e8874902e 323 /** setAccelODR() -- Set the output data rate of the accelerometer
beanmachine44 0:622e8874902e 324 * Input:
beanmachine44 0:622e8874902e 325 * - aRate = The desired output rate of the accel.
beanmachine44 1:0e76f237c23d 326 * Must be a value from the accel_odr enum (check above).
beanmachine44 0:622e8874902e 327 */
beanmachine44 0:622e8874902e 328 void setAccelODR(accel_odr aRate);
benson516 8:16e88babd42a 329
beanmachine44 0:622e8874902e 330 /** setMagODR() -- Set the output data rate of the magnetometer
beanmachine44 0:622e8874902e 331 * Input:
beanmachine44 0:622e8874902e 332 * - mRate = The desired output rate of the mag.
beanmachine44 1:0e76f237c23d 333 * Must be a value from the mag_odr enum (check above).
beanmachine44 0:622e8874902e 334 */
beanmachine44 0:622e8874902e 335 void setMagODR(mag_odr mRate);
benson516 8:16e88babd42a 336
benson516 8:16e88babd42a 337
ChangYuHsuan 6:28c4b3c8b43d 338 /** enableFIFO() -- Turn on FIFO state (CTRL_REG9)
ChangYuHsuan 6:28c4b3c8b43d 339 * Input:
ChangYuHsuan 6:28c4b3c8b43d 340 * - enable = true - turn on FIFO
ChangYuHsuan 6:28c4b3c8b43d 341 * false - turn off FIFO
ChangYuHsuan 6:28c4b3c8b43d 342 */
ChangYuHsuan 6:28c4b3c8b43d 343 void enableXgFIFO(bool enable);
beanmachine44 0:622e8874902e 344
ChangYuHsuan 6:28c4b3c8b43d 345 /** setFIFO() -- Set FIFO mode and FIFO threshold(FIFO_CTRL)
ChangYuHsuan 6:28c4b3c8b43d 346 * Input:
ChangYuHsuan 6:28c4b3c8b43d 347 * - fifoMode = 0: Bypass mode. FIFO turned off
ChangYuHsuan 6:28c4b3c8b43d 348 * 1: FIFO mode. Stops collecting data when FIFO is full
ChangYuHsuan 6:28c4b3c8b43d 349 * - fifoThs = maximum threshold is 0x1F(31)
ChangYuHsuan 6:28c4b3c8b43d 350 */
ChangYuHsuan 6:28c4b3c8b43d 351 void setXgFIFO(uint8_t fifoMode, uint8_t fifoThs);
beanmachine44 0:622e8874902e 352
benson516 8:16e88babd42a 353 private:
beanmachine44 0:622e8874902e 354 /** xgAddress and mAddress store the I2C address
beanmachine44 0:622e8874902e 355 * for each sensor.
beanmachine44 0:622e8874902e 356 */
beanmachine44 0:622e8874902e 357 uint8_t xgAddress, mAddress;
benson516 8:16e88babd42a 358
beanmachine44 0:622e8874902e 359 // I2C bus
beanmachine44 0:622e8874902e 360 I2C i2c;
beanmachine44 0:622e8874902e 361
benson516 8:16e88babd42a 362 /** gScale, aScale, and mScale store the current scale range for each
beanmachine44 0:622e8874902e 363 * sensor. Should be updated whenever that value changes.
beanmachine44 0:622e8874902e 364 */
beanmachine44 0:622e8874902e 365 gyro_scale gScale;
beanmachine44 0:622e8874902e 366 accel_scale aScale;
beanmachine44 0:622e8874902e 367 mag_scale mScale;
benson516 8:16e88babd42a 368
benson516 8:16e88babd42a 369 /** gRes, aRes, and mRes store the current resolution for each sensor.
beanmachine44 0:622e8874902e 370 * Units of these values would be DPS (or g's or Gs's) per ADC tick.
beanmachine44 0:622e8874902e 371 * This value is calculated as (sensor scale) / (2^15).
beanmachine44 0:622e8874902e 372 */
beanmachine44 0:622e8874902e 373 float gRes, aRes, mRes;
benson516 8:16e88babd42a 374
beanmachine44 0:622e8874902e 375 /** initGyro() -- Sets up the gyroscope to begin reading.
beanmachine44 1:0e76f237c23d 376 * This function steps through all three gyroscope control registers.
beanmachine44 0:622e8874902e 377 */
beanmachine44 0:622e8874902e 378 void initGyro();
benson516 8:16e88babd42a 379
beanmachine44 0:622e8874902e 380 /** initAccel() -- Sets up the accelerometer to begin reading.
beanmachine44 0:622e8874902e 381 * This function steps through all accelerometer related control registers.
beanmachine44 0:622e8874902e 382 */
beanmachine44 0:622e8874902e 383 void initAccel();
benson516 8:16e88babd42a 384
5hel2l2y 4:7ffcb378cfd4 385 /** Initialize Interrupts **/
5hel2l2y 3:f96b287c0bf7 386 void initIntr();
benson516 8:16e88babd42a 387
beanmachine44 0:622e8874902e 388 /** initMag() -- Sets up the magnetometer to begin reading.
beanmachine44 0:622e8874902e 389 * This function steps through all magnetometer-related control registers.
beanmachine44 0:622e8874902e 390 */
beanmachine44 0:622e8874902e 391 void initMag();
benson516 8:16e88babd42a 392
beanmachine44 0:622e8874902e 393 /** calcgRes() -- Calculate the resolution of the gyroscope.
beanmachine44 0:622e8874902e 394 * This function will set the value of the gRes variable. gScale must
beanmachine44 0:622e8874902e 395 * be set prior to calling this function.
beanmachine44 0:622e8874902e 396 */
beanmachine44 0:622e8874902e 397 void calcgRes();
benson516 8:16e88babd42a 398
beanmachine44 0:622e8874902e 399 /** calcmRes() -- Calculate the resolution of the magnetometer.
beanmachine44 0:622e8874902e 400 * This function will set the value of the mRes variable. mScale must
beanmachine44 0:622e8874902e 401 * be set prior to calling this function.
beanmachine44 0:622e8874902e 402 */
beanmachine44 0:622e8874902e 403 void calcmRes();
benson516 8:16e88babd42a 404
beanmachine44 0:622e8874902e 405 /** calcaRes() -- Calculate the resolution of the accelerometer.
beanmachine44 0:622e8874902e 406 * This function will set the value of the aRes variable. aScale must
beanmachine44 0:622e8874902e 407 * be set prior to calling this function.
beanmachine44 0:622e8874902e 408 */
beanmachine44 0:622e8874902e 409 void calcaRes();
beanmachine44 0:622e8874902e 410 };
beanmachine44 0:622e8874902e 411
beanmachine44 0:622e8874902e 412 #endif // _LSM9DS1_H //