rrr

Dependencies:   mbed MX28

Committer:
ChengHan
Date:
Wed Dec 19 12:35:03 2018 +0000
Revision:
12:a197e7eed8ab
Parent:
0:c23e915f255b
rrr

Who changed what in which revision?

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