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