read EMG, IMU, encoder

Dependencies:   mbed

Fork of LSM9DS1_project by 曾 宗圓

Committer:
JJting
Date:
Wed Aug 01 01:01:13 2018 +0000
Revision:
3:567765d3bcd1
original 20180801

Who changed what in which revision?

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