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