LSM6DS33 Library
Dependents: teensyIMU LSM6DS33 ALTIMU_v6
Fork of LSM6DS3 by
LSM6DS3.h@2:ed14e6196255, 2016-06-21 (annotated)
- Committer:
- 5hel2l2y
- Date:
- Tue Jun 21 20:51:25 2016 +0000
- Revision:
- 2:ed14e6196255
- Parent:
- 1:924c7dea286e
Adding interrupt.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
5hel2l2y | 0:46630122dec9 | 1 | // Based on Eugene Gonzalez's version of LSM9DS1_Demo |
5hel2l2y | 0:46630122dec9 | 2 | // Modified by Sherry Yang for LSM6DS3 sensor |
5hel2l2y | 0:46630122dec9 | 3 | #ifndef _LSM6DS3_H__ |
5hel2l2y | 0:46630122dec9 | 4 | #define _LSM6DS3_H__ |
5hel2l2y | 0:46630122dec9 | 5 | |
5hel2l2y | 0:46630122dec9 | 6 | #include "mbed.h" |
5hel2l2y | 0:46630122dec9 | 7 | |
5hel2l2y | 0:46630122dec9 | 8 | ///////////////////////////////////////// |
5hel2l2y | 0:46630122dec9 | 9 | // LSM6DS3 Accel/Gyro (XL/G) Registers // |
5hel2l2y | 0:46630122dec9 | 10 | ///////////////////////////////////////// |
5hel2l2y | 0:46630122dec9 | 11 | #define RAM_ACCESS 0x01 |
5hel2l2y | 0:46630122dec9 | 12 | #define SENSOR_SYNC_TIME 0x04 |
5hel2l2y | 0:46630122dec9 | 13 | #define SENSOR_SYNC_EN 0x05 |
5hel2l2y | 0:46630122dec9 | 14 | #define FIFO_CTRL1 0x06 |
5hel2l2y | 0:46630122dec9 | 15 | #define FIFO_CTRL2 0x07 |
5hel2l2y | 0:46630122dec9 | 16 | #define FIFO_CTRL3 0x08 |
5hel2l2y | 0:46630122dec9 | 17 | #define FIFO_CTRL4 0x09 |
5hel2l2y | 0:46630122dec9 | 18 | #define FIFO_CTRL5 0x0A |
5hel2l2y | 0:46630122dec9 | 19 | #define ORIENT_CFG_G 0x0B |
5hel2l2y | 0:46630122dec9 | 20 | #define REFERENCE_G 0x0C |
5hel2l2y | 0:46630122dec9 | 21 | #define INT1_CTRL 0x0D |
5hel2l2y | 0:46630122dec9 | 22 | #define INT2_CTRL 0x0E |
5hel2l2y | 0:46630122dec9 | 23 | #define WHO_AM_I_REG 0X0F |
5hel2l2y | 0:46630122dec9 | 24 | #define CTRL1_XL 0x10 |
5hel2l2y | 0:46630122dec9 | 25 | #define CTRL2_G 0x11 |
5hel2l2y | 0:46630122dec9 | 26 | #define CTRL3_C 0x12 |
5hel2l2y | 0:46630122dec9 | 27 | #define CTRL4_C 0x13 |
5hel2l2y | 0:46630122dec9 | 28 | #define CTRL5_C 0x14 |
5hel2l2y | 1:924c7dea286e | 29 | #define CTRL6_C 0x15 |
5hel2l2y | 0:46630122dec9 | 30 | #define CTRL7_G 0x16 |
5hel2l2y | 0:46630122dec9 | 31 | #define CTRL8_XL 0x17 |
5hel2l2y | 0:46630122dec9 | 32 | #define CTRL9_XL 0x18 |
5hel2l2y | 0:46630122dec9 | 33 | #define CTRL10_C 0x19 |
5hel2l2y | 0:46630122dec9 | 34 | #define MASTER_CONFIG 0x1A |
5hel2l2y | 0:46630122dec9 | 35 | #define WAKE_UP_SRC 0x1B |
5hel2l2y | 0:46630122dec9 | 36 | #define TAP_SRC 0x1C |
5hel2l2y | 0:46630122dec9 | 37 | #define D6D_SRC 0x1D |
5hel2l2y | 0:46630122dec9 | 38 | #define STATUS_REG 0x1E |
5hel2l2y | 0:46630122dec9 | 39 | #define OUT_TEMP_L 0x20 |
5hel2l2y | 0:46630122dec9 | 40 | #define OUT_TEMP_H 0x21 |
5hel2l2y | 0:46630122dec9 | 41 | #define OUTX_L_G 0x22 |
5hel2l2y | 0:46630122dec9 | 42 | #define OUTX_H_G 0x23 |
5hel2l2y | 0:46630122dec9 | 43 | #define OUTY_L_G 0x24 |
5hel2l2y | 0:46630122dec9 | 44 | #define OUTY_H_G 0x25 |
5hel2l2y | 0:46630122dec9 | 45 | #define OUTZ_L_G 0x26 |
5hel2l2y | 0:46630122dec9 | 46 | #define OUTZ_H_G 0x27 |
5hel2l2y | 0:46630122dec9 | 47 | #define OUTX_L_XL 0x28 |
5hel2l2y | 0:46630122dec9 | 48 | #define OUTX_H_XL 0x29 |
5hel2l2y | 0:46630122dec9 | 49 | #define OUTY_L_XL 0x2A |
5hel2l2y | 0:46630122dec9 | 50 | #define OUTY_H_XL 0x2B |
5hel2l2y | 0:46630122dec9 | 51 | #define OUTZ_L_XL 0x2C |
5hel2l2y | 0:46630122dec9 | 52 | #define OUTZ_H_XL 0x2D |
5hel2l2y | 0:46630122dec9 | 53 | #define SENSORHUB1_REG 0x2E |
5hel2l2y | 0:46630122dec9 | 54 | #define SENSORHUB2_REG 0x2F |
5hel2l2y | 0:46630122dec9 | 55 | #define SENSORHUB3_REG 0x30 |
5hel2l2y | 0:46630122dec9 | 56 | #define SENSORHUB4_REG 0x31 |
5hel2l2y | 0:46630122dec9 | 57 | #define SENSORHUB5_REG 0x32 |
5hel2l2y | 0:46630122dec9 | 58 | #define SENSORHUB6_REG 0x33 |
5hel2l2y | 0:46630122dec9 | 59 | #define SENSORHUB7_REG 0x34 |
5hel2l2y | 0:46630122dec9 | 60 | #define SENSORHUB8_REG 0x35 |
5hel2l2y | 0:46630122dec9 | 61 | #define SENSORHUB9_REG 0x36 |
5hel2l2y | 0:46630122dec9 | 62 | #define SENSORHUB10_REG 0x37 |
5hel2l2y | 0:46630122dec9 | 63 | #define SENSORHUB11_REG 0x38 |
5hel2l2y | 0:46630122dec9 | 64 | #define SENSORHUB12_REG 0x39 |
5hel2l2y | 0:46630122dec9 | 65 | #define FIFO_STATUS1 0x3A |
5hel2l2y | 0:46630122dec9 | 66 | #define FIFO_STATUS2 0x3B |
5hel2l2y | 0:46630122dec9 | 67 | #define FIFO_STATUS3 0x3C |
5hel2l2y | 0:46630122dec9 | 68 | #define FIFO_STATUS4 0x3D |
5hel2l2y | 0:46630122dec9 | 69 | #define FIFO_DATA_OUT_L 0x3E |
5hel2l2y | 0:46630122dec9 | 70 | #define FIFO_DATA_OUT_H 0x3F |
5hel2l2y | 0:46630122dec9 | 71 | #define TIMESTAMP0_REG 0x40 |
5hel2l2y | 0:46630122dec9 | 72 | #define TIMESTAMP1_REG 0x41 |
5hel2l2y | 0:46630122dec9 | 73 | #define TIMESTAMP2_REG 0x42 |
5hel2l2y | 0:46630122dec9 | 74 | #define STEP_COUNTER_L 0x4B |
5hel2l2y | 0:46630122dec9 | 75 | #define STEP_COUNTER_H 0x4C |
5hel2l2y | 0:46630122dec9 | 76 | #define FUNC_SR 0x53 |
5hel2l2y | 0:46630122dec9 | 77 | #define TAP_CFG 0x58 |
5hel2l2y | 0:46630122dec9 | 78 | #define TAP_THS_6D 0x59 |
5hel2l2y | 0:46630122dec9 | 79 | #define INT_DUR2 0x5A |
5hel2l2y | 0:46630122dec9 | 80 | #define WAKE_UP_THS 0x5B |
5hel2l2y | 0:46630122dec9 | 81 | #define WAKE_UP_DUR 0x5C |
5hel2l2y | 0:46630122dec9 | 82 | #define FREE_FALL 0x5D |
5hel2l2y | 0:46630122dec9 | 83 | #define MD1_CFG 0x5E |
5hel2l2y | 0:46630122dec9 | 84 | #define MD2_CFG 0x5F |
5hel2l2y | 0:46630122dec9 | 85 | |
5hel2l2y | 0:46630122dec9 | 86 | // Possible I2C addresses for the accel/gyro |
5hel2l2y | 0:46630122dec9 | 87 | #define LSM6DS3_AG_I2C_ADDR(sa0) ((sa0) ? 0xD6 : 0xD4) |
5hel2l2y | 0:46630122dec9 | 88 | |
5hel2l2y | 0:46630122dec9 | 89 | /** |
5hel2l2y | 0:46630122dec9 | 90 | * LSM6DS3 Class - driver for the 9 DoF IMU |
5hel2l2y | 0:46630122dec9 | 91 | */ |
5hel2l2y | 0:46630122dec9 | 92 | class LSM6DS3 |
5hel2l2y | 0:46630122dec9 | 93 | { |
5hel2l2y | 0:46630122dec9 | 94 | public: |
5hel2l2y | 0:46630122dec9 | 95 | |
5hel2l2y | 0:46630122dec9 | 96 | /// gyro_scale defines the possible full-scale ranges of the gyroscope: |
5hel2l2y | 0:46630122dec9 | 97 | enum gyro_scale |
5hel2l2y | 0:46630122dec9 | 98 | { |
5hel2l2y | 0:46630122dec9 | 99 | G_SCALE_245DPS = 0x0 << 3, // 00 << 3: +/- 245 degrees per second |
5hel2l2y | 0:46630122dec9 | 100 | G_SCALE_500DPS = 0x1 << 3, // 01 << 3: +/- 500 dps |
5hel2l2y | 1:924c7dea286e | 101 | G_SCALE_1000DPS = 0x2 << 3, // 10 << 3: +/- 1000 dps |
5hel2l2y | 0:46630122dec9 | 102 | G_SCALE_2000DPS = 0x3 << 3 // 11 << 3: +/- 2000 dps |
5hel2l2y | 0:46630122dec9 | 103 | }; |
5hel2l2y | 0:46630122dec9 | 104 | |
5hel2l2y | 0:46630122dec9 | 105 | /// gyro_odr defines all possible data rate/bandwidth combos of the gyro: |
5hel2l2y | 0:46630122dec9 | 106 | enum gyro_odr |
5hel2l2y | 0:46630122dec9 | 107 | { // ODR (Hz) --- Cutoff |
5hel2l2y | 0:46630122dec9 | 108 | G_POWER_DOWN = 0x00, // 0 0 |
5hel2l2y | 1:924c7dea286e | 109 | G_ODR_13_BW_0 = 0x10, // 12.5 0.0081 low power |
5hel2l2y | 1:924c7dea286e | 110 | G_ODR_26_BW_2 = 0x20, // 26 2.07 low power |
5hel2l2y | 1:924c7dea286e | 111 | G_ODR_52_BW_16 = 0x30, // 52 16.32 low power |
5hel2l2y | 1:924c7dea286e | 112 | G_ODR_104 = 0x40, // 104 |
5hel2l2y | 1:924c7dea286e | 113 | G_ODR_208 = 0x50, // 208 |
5hel2l2y | 1:924c7dea286e | 114 | G_ODR_416 = 0x60, // 416 |
5hel2l2y | 1:924c7dea286e | 115 | G_ODR_833 = 0x70, // 833 |
5hel2l2y | 1:924c7dea286e | 116 | G_ODR_1660 = 0x80 // 1660 |
5hel2l2y | 0:46630122dec9 | 117 | }; |
5hel2l2y | 0:46630122dec9 | 118 | |
5hel2l2y | 0:46630122dec9 | 119 | /// accel_scale defines all possible FSR's of the accelerometer: |
5hel2l2y | 0:46630122dec9 | 120 | enum accel_scale |
5hel2l2y | 0:46630122dec9 | 121 | { |
5hel2l2y | 0:46630122dec9 | 122 | A_SCALE_2G, // 00: +/- 2g |
5hel2l2y | 0:46630122dec9 | 123 | A_SCALE_16G,// 01: +/- 16g |
5hel2l2y | 0:46630122dec9 | 124 | A_SCALE_4G, // 10: +/- 4g |
5hel2l2y | 0:46630122dec9 | 125 | A_SCALE_8G // 11: +/- 8g |
5hel2l2y | 0:46630122dec9 | 126 | }; |
5hel2l2y | 0:46630122dec9 | 127 | |
5hel2l2y | 0:46630122dec9 | 128 | /// accel_oder defines all possible output data rates of the accelerometer: |
5hel2l2y | 0:46630122dec9 | 129 | enum accel_odr |
5hel2l2y | 0:46630122dec9 | 130 | { |
5hel2l2y | 0:46630122dec9 | 131 | A_POWER_DOWN, // Power-down mode (0x0) |
5hel2l2y | 1:924c7dea286e | 132 | A_ODR_13, // 12.5 Hz (0x1) low power |
5hel2l2y | 1:924c7dea286e | 133 | A_ODR_26, // 26 Hz (0x2) low power |
5hel2l2y | 1:924c7dea286e | 134 | A_ODR_52, // 52 Hz (0x3) low power |
5hel2l2y | 1:924c7dea286e | 135 | A_ODR_104, // 104 Hz (0x4) normal mode |
5hel2l2y | 1:924c7dea286e | 136 | A_ODR_208, // 208 Hz (0x5) normal mode |
5hel2l2y | 1:924c7dea286e | 137 | A_ODR_416, // 416 Hz (0x6) high performance |
5hel2l2y | 1:924c7dea286e | 138 | A_ODR_833, // 833 Hz (0x7) high performance |
5hel2l2y | 1:924c7dea286e | 139 | A_ODR_1660, // 1.66 kHz (0x8) high performance |
5hel2l2y | 1:924c7dea286e | 140 | A_ODR_3330, // 3.33 kHz (0x9) high performance |
5hel2l2y | 1:924c7dea286e | 141 | A_ODR_6660, // 6.66 kHz (0xA) high performance |
5hel2l2y | 0:46630122dec9 | 142 | }; |
5hel2l2y | 0:46630122dec9 | 143 | |
5hel2l2y | 0:46630122dec9 | 144 | // accel_bw defines all possible bandwiths for low-pass filter of the accelerometer: |
5hel2l2y | 0:46630122dec9 | 145 | enum accel_bw |
5hel2l2y | 0:46630122dec9 | 146 | { |
5hel2l2y | 0:46630122dec9 | 147 | A_BW_AUTO_SCALE = 0x0, // Automatic BW scaling (0x0) |
5hel2l2y | 0:46630122dec9 | 148 | A_BW_408 = 0x4, // 408 Hz (0x4) |
5hel2l2y | 0:46630122dec9 | 149 | A_BW_211 = 0x5, // 211 Hz (0x5) |
5hel2l2y | 0:46630122dec9 | 150 | A_BW_105 = 0x6, // 105 Hz (0x6) |
5hel2l2y | 0:46630122dec9 | 151 | A_BW_50 = 0x7 // 50 Hz (0x7) |
5hel2l2y | 0:46630122dec9 | 152 | }; |
5hel2l2y | 2:ed14e6196255 | 153 | |
5hel2l2y | 2:ed14e6196255 | 154 | |
5hel2l2y | 0:46630122dec9 | 155 | |
5hel2l2y | 0:46630122dec9 | 156 | // We'll store the gyro, and accel, readings in a series of |
5hel2l2y | 0:46630122dec9 | 157 | // public class variables. Each sensor gets three variables -- one for each |
5hel2l2y | 0:46630122dec9 | 158 | // axis. Call readGyro(), and readAccel() first, before using |
5hel2l2y | 0:46630122dec9 | 159 | // these variables! |
5hel2l2y | 0:46630122dec9 | 160 | // These values are the RAW signed 16-bit readings from the sensors. |
5hel2l2y | 0:46630122dec9 | 161 | int16_t gx_raw, gy_raw, gz_raw; // x, y, and z axis readings of the gyroscope |
5hel2l2y | 0:46630122dec9 | 162 | int16_t ax_raw, ay_raw, az_raw; // x, y, and z axis readings of the accelerometer |
5hel2l2y | 0:46630122dec9 | 163 | int16_t temperature_raw; |
5hel2l2y | 0:46630122dec9 | 164 | |
5hel2l2y | 0:46630122dec9 | 165 | // floating-point values of scaled data in real-world units |
5hel2l2y | 0:46630122dec9 | 166 | float gx, gy, gz; |
5hel2l2y | 0:46630122dec9 | 167 | float ax, ay, az; |
5hel2l2y | 0:46630122dec9 | 168 | float temperature_c, temperature_f; // temperature in celcius and fahrenheit |
5hel2l2y | 2:ed14e6196255 | 169 | float intr; |
5hel2l2y | 0:46630122dec9 | 170 | |
5hel2l2y | 0:46630122dec9 | 171 | |
5hel2l2y | 0:46630122dec9 | 172 | /** LSM6DS3 -- LSM6DS3 class constructor |
5hel2l2y | 0:46630122dec9 | 173 | * The constructor will set up a handful of private variables, and set the |
5hel2l2y | 0:46630122dec9 | 174 | * communication mode as well. |
5hel2l2y | 0:46630122dec9 | 175 | * Input: |
5hel2l2y | 0:46630122dec9 | 176 | * - interface = Either MODE_SPI or MODE_I2C, whichever you're using |
5hel2l2y | 0:46630122dec9 | 177 | * to talk to the IC. |
5hel2l2y | 0:46630122dec9 | 178 | * - xgAddr = If MODE_I2C, this is the I2C address of the accel/gyro. |
5hel2l2y | 0:46630122dec9 | 179 | * If MODE_SPI, this is the chip select pin of the accel/gyro (CS_A/G) |
5hel2l2y | 0:46630122dec9 | 180 | */ |
5hel2l2y | 0:46630122dec9 | 181 | LSM6DS3(PinName sda, PinName scl, uint8_t xgAddr = LSM6DS3_AG_I2C_ADDR(1)); |
5hel2l2y | 0:46630122dec9 | 182 | |
5hel2l2y | 0:46630122dec9 | 183 | /** begin() -- Initialize the gyro, and accelerometer. |
5hel2l2y | 0:46630122dec9 | 184 | * This will set up the scale and output rate of each sensor. It'll also |
5hel2l2y | 0:46630122dec9 | 185 | * "turn on" every sensor and every axis of every sensor. |
5hel2l2y | 0:46630122dec9 | 186 | * Input: |
5hel2l2y | 0:46630122dec9 | 187 | * - gScl = The scale of the gyroscope. This should be a gyro_scale value. |
5hel2l2y | 0:46630122dec9 | 188 | * - aScl = The scale of the accelerometer. Should be a accel_scale value. |
5hel2l2y | 0:46630122dec9 | 189 | * - gODR = Output data rate of the gyroscope. gyro_odr value. |
5hel2l2y | 0:46630122dec9 | 190 | * - aODR = Output data rate of the accelerometer. accel_odr value. |
5hel2l2y | 0:46630122dec9 | 191 | * Output: The function will return an unsigned 16-bit value. The most-sig |
5hel2l2y | 0:46630122dec9 | 192 | * bytes of the output are the WHO_AM_I reading of the accel/gyro. |
5hel2l2y | 0:46630122dec9 | 193 | * All parameters have a defaulted value, so you can call just "begin()". |
5hel2l2y | 0:46630122dec9 | 194 | * Default values are FSR's of: +/- 245DPS, 4g, 2Gs; ODRs of 119 Hz for |
5hel2l2y | 0:46630122dec9 | 195 | * gyro, 119 Hz for accelerometer. |
5hel2l2y | 0:46630122dec9 | 196 | * Use the return value of this function to verify communication. |
5hel2l2y | 0:46630122dec9 | 197 | */ |
5hel2l2y | 0:46630122dec9 | 198 | uint16_t begin(gyro_scale gScl = G_SCALE_245DPS, |
5hel2l2y | 1:924c7dea286e | 199 | accel_scale aScl = A_SCALE_2G, gyro_odr gODR = G_ODR_104, |
5hel2l2y | 1:924c7dea286e | 200 | accel_odr aODR = A_ODR_104); |
5hel2l2y | 0:46630122dec9 | 201 | |
5hel2l2y | 0:46630122dec9 | 202 | /** readGyro() -- Read the gyroscope output registers. |
5hel2l2y | 0:46630122dec9 | 203 | * This function will read all six gyroscope output registers. |
5hel2l2y | 0:46630122dec9 | 204 | * The readings are stored in the class' gx_raw, gy_raw, and gz_raw variables. Read |
5hel2l2y | 0:46630122dec9 | 205 | * those _after_ calling readGyro(). |
5hel2l2y | 0:46630122dec9 | 206 | */ |
5hel2l2y | 0:46630122dec9 | 207 | void readGyro(); |
5hel2l2y | 0:46630122dec9 | 208 | |
5hel2l2y | 0:46630122dec9 | 209 | /** readAccel() -- Read the accelerometer output registers. |
5hel2l2y | 0:46630122dec9 | 210 | * This function will read all six accelerometer output registers. |
5hel2l2y | 0:46630122dec9 | 211 | * The readings are stored in the class' ax_raw, ay_raw, and az_raw variables. Read |
5hel2l2y | 0:46630122dec9 | 212 | * those _after_ calling readAccel(). |
5hel2l2y | 0:46630122dec9 | 213 | */ |
5hel2l2y | 0:46630122dec9 | 214 | void readAccel(); |
5hel2l2y | 0:46630122dec9 | 215 | |
5hel2l2y | 0:46630122dec9 | 216 | /** readTemp() -- Read the temperature output register. |
5hel2l2y | 0:46630122dec9 | 217 | * This function will read two temperature output registers. |
5hel2l2y | 0:46630122dec9 | 218 | * The combined readings are stored in the class' temperature variables. Read |
5hel2l2y | 0:46630122dec9 | 219 | * those _after_ calling readTemp(). |
5hel2l2y | 0:46630122dec9 | 220 | */ |
5hel2l2y | 0:46630122dec9 | 221 | void readTemp(); |
5hel2l2y | 0:46630122dec9 | 222 | |
5hel2l2y | 2:ed14e6196255 | 223 | /** Read Interrupt **/ |
5hel2l2y | 2:ed14e6196255 | 224 | void readIntr(); |
5hel2l2y | 2:ed14e6196255 | 225 | |
5hel2l2y | 0:46630122dec9 | 226 | /** setGyroScale() -- Set the full-scale range of the gyroscope. |
5hel2l2y | 0:46630122dec9 | 227 | * This function can be called to set the scale of the gyroscope to |
5hel2l2y | 0:46630122dec9 | 228 | * 245, 500, or 2000 degrees per second. |
5hel2l2y | 0:46630122dec9 | 229 | * Input: |
5hel2l2y | 0:46630122dec9 | 230 | * - gScl = The desired gyroscope scale. Must be one of three possible |
5hel2l2y | 0:46630122dec9 | 231 | * values from the gyro_scale enum. |
5hel2l2y | 0:46630122dec9 | 232 | */ |
5hel2l2y | 0:46630122dec9 | 233 | void setGyroScale(gyro_scale gScl); |
5hel2l2y | 0:46630122dec9 | 234 | |
5hel2l2y | 0:46630122dec9 | 235 | /** setAccelScale() -- Set the full-scale range of the accelerometer. |
5hel2l2y | 0:46630122dec9 | 236 | * This function can be called to set the scale of the accelerometer to |
5hel2l2y | 0:46630122dec9 | 237 | * 2, 4, 8, or 16 g's. |
5hel2l2y | 0:46630122dec9 | 238 | * Input: |
5hel2l2y | 0:46630122dec9 | 239 | * - aScl = The desired accelerometer scale. Must be one of five possible |
5hel2l2y | 0:46630122dec9 | 240 | * values from the accel_scale enum. |
5hel2l2y | 0:46630122dec9 | 241 | */ |
5hel2l2y | 0:46630122dec9 | 242 | void setAccelScale(accel_scale aScl); |
5hel2l2y | 0:46630122dec9 | 243 | |
5hel2l2y | 0:46630122dec9 | 244 | /** setGyroODR() -- Set the output data rate and bandwidth of the gyroscope |
5hel2l2y | 0:46630122dec9 | 245 | * Input: |
5hel2l2y | 0:46630122dec9 | 246 | * - gRate = The desired output rate and cutoff frequency of the gyro. |
5hel2l2y | 0:46630122dec9 | 247 | * Must be a value from the gyro_odr enum (check above). |
5hel2l2y | 0:46630122dec9 | 248 | */ |
5hel2l2y | 0:46630122dec9 | 249 | void setGyroODR(gyro_odr gRate); |
5hel2l2y | 0:46630122dec9 | 250 | |
5hel2l2y | 0:46630122dec9 | 251 | /** setAccelODR() -- Set the output data rate of the accelerometer |
5hel2l2y | 0:46630122dec9 | 252 | * Input: |
5hel2l2y | 0:46630122dec9 | 253 | * - aRate = The desired output rate of the accel. |
5hel2l2y | 0:46630122dec9 | 254 | * Must be a value from the accel_odr enum (check above). |
5hel2l2y | 0:46630122dec9 | 255 | */ |
5hel2l2y | 0:46630122dec9 | 256 | void setAccelODR(accel_odr aRate); |
5hel2l2y | 0:46630122dec9 | 257 | |
5hel2l2y | 0:46630122dec9 | 258 | |
5hel2l2y | 0:46630122dec9 | 259 | private: |
5hel2l2y | 0:46630122dec9 | 260 | /** xgAddress store the I2C address |
5hel2l2y | 0:46630122dec9 | 261 | * for each sensor. |
5hel2l2y | 0:46630122dec9 | 262 | */ |
5hel2l2y | 0:46630122dec9 | 263 | uint8_t xgAddress; |
5hel2l2y | 0:46630122dec9 | 264 | |
5hel2l2y | 0:46630122dec9 | 265 | // I2C bus |
5hel2l2y | 0:46630122dec9 | 266 | I2C i2c; |
5hel2l2y | 0:46630122dec9 | 267 | |
5hel2l2y | 0:46630122dec9 | 268 | /** gScale, and aScale store the current scale range for each |
5hel2l2y | 0:46630122dec9 | 269 | * sensor. Should be updated whenever that value changes. |
5hel2l2y | 0:46630122dec9 | 270 | */ |
5hel2l2y | 0:46630122dec9 | 271 | gyro_scale gScale; |
5hel2l2y | 0:46630122dec9 | 272 | accel_scale aScale; |
5hel2l2y | 0:46630122dec9 | 273 | |
5hel2l2y | 0:46630122dec9 | 274 | /** gRes, and aRes store the current resolution for each sensor. |
5hel2l2y | 0:46630122dec9 | 275 | * Units of these values would be DPS (or g's or Gs's) per ADC tick. |
5hel2l2y | 0:46630122dec9 | 276 | * This value is calculated as (sensor scale) / (2^15). |
5hel2l2y | 0:46630122dec9 | 277 | */ |
5hel2l2y | 0:46630122dec9 | 278 | float gRes, aRes; |
5hel2l2y | 0:46630122dec9 | 279 | |
5hel2l2y | 0:46630122dec9 | 280 | /** initGyro() -- Sets up the gyroscope to begin reading. |
5hel2l2y | 0:46630122dec9 | 281 | * This function steps through all three gyroscope control registers. |
5hel2l2y | 0:46630122dec9 | 282 | */ |
5hel2l2y | 0:46630122dec9 | 283 | void initGyro(); |
5hel2l2y | 0:46630122dec9 | 284 | |
5hel2l2y | 0:46630122dec9 | 285 | /** initAccel() -- Sets up the accelerometer to begin reading. |
5hel2l2y | 0:46630122dec9 | 286 | * This function steps through all accelerometer related control registers. |
5hel2l2y | 0:46630122dec9 | 287 | */ |
5hel2l2y | 0:46630122dec9 | 288 | void initAccel(); |
5hel2l2y | 0:46630122dec9 | 289 | |
5hel2l2y | 2:ed14e6196255 | 290 | /** Setup Interrupt **/ |
5hel2l2y | 2:ed14e6196255 | 291 | void initIntr(); |
5hel2l2y | 2:ed14e6196255 | 292 | |
5hel2l2y | 0:46630122dec9 | 293 | /** calcgRes() -- Calculate the resolution of the gyroscope. |
5hel2l2y | 0:46630122dec9 | 294 | * This function will set the value of the gRes variable. gScale must |
5hel2l2y | 0:46630122dec9 | 295 | * be set prior to calling this function. |
5hel2l2y | 0:46630122dec9 | 296 | */ |
5hel2l2y | 0:46630122dec9 | 297 | void calcgRes(); |
5hel2l2y | 0:46630122dec9 | 298 | |
5hel2l2y | 0:46630122dec9 | 299 | /** calcaRes() -- Calculate the resolution of the accelerometer. |
5hel2l2y | 0:46630122dec9 | 300 | * This function will set the value of the aRes variable. aScale must |
5hel2l2y | 0:46630122dec9 | 301 | * be set prior to calling this function. |
5hel2l2y | 0:46630122dec9 | 302 | */ |
5hel2l2y | 0:46630122dec9 | 303 | void calcaRes(); |
5hel2l2y | 0:46630122dec9 | 304 | }; |
5hel2l2y | 0:46630122dec9 | 305 | |
5hel2l2y | 0:46630122dec9 | 306 | #endif // _LSM6DS3_H // |