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 |
0:46630122dec9
|
153
|
|
5hel2l2y |
0:46630122dec9
|
154
|
// We'll store the gyro, and accel, readings in a series of
|
5hel2l2y |
0:46630122dec9
|
155
|
// public class variables. Each sensor gets three variables -- one for each
|
5hel2l2y |
0:46630122dec9
|
156
|
// axis. Call readGyro(), and readAccel() first, before using
|
5hel2l2y |
0:46630122dec9
|
157
|
// these variables!
|
5hel2l2y |
0:46630122dec9
|
158
|
// These values are the RAW signed 16-bit readings from the sensors.
|
5hel2l2y |
0:46630122dec9
|
159
|
int16_t gx_raw, gy_raw, gz_raw; // x, y, and z axis readings of the gyroscope
|
5hel2l2y |
0:46630122dec9
|
160
|
int16_t ax_raw, ay_raw, az_raw; // x, y, and z axis readings of the accelerometer
|
5hel2l2y |
0:46630122dec9
|
161
|
int16_t temperature_raw;
|
5hel2l2y |
0:46630122dec9
|
162
|
|
5hel2l2y |
0:46630122dec9
|
163
|
// floating-point values of scaled data in real-world units
|
5hel2l2y |
0:46630122dec9
|
164
|
float gx, gy, gz;
|
5hel2l2y |
0:46630122dec9
|
165
|
float ax, ay, az;
|
5hel2l2y |
0:46630122dec9
|
166
|
float temperature_c, temperature_f; // temperature in celcius and fahrenheit
|
5hel2l2y |
0:46630122dec9
|
167
|
|
5hel2l2y |
0:46630122dec9
|
168
|
|
5hel2l2y |
0:46630122dec9
|
169
|
/** LSM6DS3 -- LSM6DS3 class constructor
|
5hel2l2y |
0:46630122dec9
|
170
|
* The constructor will set up a handful of private variables, and set the
|
5hel2l2y |
0:46630122dec9
|
171
|
* communication mode as well.
|
5hel2l2y |
0:46630122dec9
|
172
|
* Input:
|
5hel2l2y |
0:46630122dec9
|
173
|
* - interface = Either MODE_SPI or MODE_I2C, whichever you're using
|
5hel2l2y |
0:46630122dec9
|
174
|
* to talk to the IC.
|
5hel2l2y |
0:46630122dec9
|
175
|
* - xgAddr = If MODE_I2C, this is the I2C address of the accel/gyro.
|
5hel2l2y |
0:46630122dec9
|
176
|
* If MODE_SPI, this is the chip select pin of the accel/gyro (CS_A/G)
|
5hel2l2y |
0:46630122dec9
|
177
|
*/
|
5hel2l2y |
0:46630122dec9
|
178
|
LSM6DS3(PinName sda, PinName scl, uint8_t xgAddr = LSM6DS3_AG_I2C_ADDR(1));
|
5hel2l2y |
0:46630122dec9
|
179
|
|
5hel2l2y |
0:46630122dec9
|
180
|
/** begin() -- Initialize the gyro, and accelerometer.
|
5hel2l2y |
0:46630122dec9
|
181
|
* This will set up the scale and output rate of each sensor. It'll also
|
5hel2l2y |
0:46630122dec9
|
182
|
* "turn on" every sensor and every axis of every sensor.
|
5hel2l2y |
0:46630122dec9
|
183
|
* Input:
|
5hel2l2y |
0:46630122dec9
|
184
|
* - gScl = The scale of the gyroscope. This should be a gyro_scale value.
|
5hel2l2y |
0:46630122dec9
|
185
|
* - aScl = The scale of the accelerometer. Should be a accel_scale value.
|
5hel2l2y |
0:46630122dec9
|
186
|
* - gODR = Output data rate of the gyroscope. gyro_odr value.
|
5hel2l2y |
0:46630122dec9
|
187
|
* - aODR = Output data rate of the accelerometer. accel_odr value.
|
5hel2l2y |
0:46630122dec9
|
188
|
* Output: The function will return an unsigned 16-bit value. The most-sig
|
5hel2l2y |
0:46630122dec9
|
189
|
* bytes of the output are the WHO_AM_I reading of the accel/gyro.
|
5hel2l2y |
0:46630122dec9
|
190
|
* All parameters have a defaulted value, so you can call just "begin()".
|
5hel2l2y |
0:46630122dec9
|
191
|
* Default values are FSR's of: +/- 245DPS, 4g, 2Gs; ODRs of 119 Hz for
|
5hel2l2y |
0:46630122dec9
|
192
|
* gyro, 119 Hz for accelerometer.
|
5hel2l2y |
0:46630122dec9
|
193
|
* Use the return value of this function to verify communication.
|
5hel2l2y |
0:46630122dec9
|
194
|
*/
|
5hel2l2y |
0:46630122dec9
|
195
|
uint16_t begin(gyro_scale gScl = G_SCALE_245DPS,
|
5hel2l2y |
1:924c7dea286e
|
196
|
accel_scale aScl = A_SCALE_2G, gyro_odr gODR = G_ODR_104,
|
5hel2l2y |
1:924c7dea286e
|
197
|
accel_odr aODR = A_ODR_104);
|
5hel2l2y |
0:46630122dec9
|
198
|
|
5hel2l2y |
0:46630122dec9
|
199
|
/** readGyro() -- Read the gyroscope output registers.
|
5hel2l2y |
0:46630122dec9
|
200
|
* This function will read all six gyroscope output registers.
|
5hel2l2y |
0:46630122dec9
|
201
|
* The readings are stored in the class' gx_raw, gy_raw, and gz_raw variables. Read
|
5hel2l2y |
0:46630122dec9
|
202
|
* those _after_ calling readGyro().
|
5hel2l2y |
0:46630122dec9
|
203
|
*/
|
5hel2l2y |
0:46630122dec9
|
204
|
void readGyro();
|
5hel2l2y |
0:46630122dec9
|
205
|
|
5hel2l2y |
0:46630122dec9
|
206
|
/** readAccel() -- Read the accelerometer output registers.
|
5hel2l2y |
0:46630122dec9
|
207
|
* This function will read all six accelerometer output registers.
|
5hel2l2y |
0:46630122dec9
|
208
|
* The readings are stored in the class' ax_raw, ay_raw, and az_raw variables. Read
|
5hel2l2y |
0:46630122dec9
|
209
|
* those _after_ calling readAccel().
|
5hel2l2y |
0:46630122dec9
|
210
|
*/
|
5hel2l2y |
0:46630122dec9
|
211
|
void readAccel();
|
5hel2l2y |
0:46630122dec9
|
212
|
|
5hel2l2y |
0:46630122dec9
|
213
|
/** readTemp() -- Read the temperature output register.
|
5hel2l2y |
0:46630122dec9
|
214
|
* This function will read two temperature output registers.
|
5hel2l2y |
0:46630122dec9
|
215
|
* The combined readings are stored in the class' temperature variables. Read
|
5hel2l2y |
0:46630122dec9
|
216
|
* those _after_ calling readTemp().
|
5hel2l2y |
0:46630122dec9
|
217
|
*/
|
5hel2l2y |
0:46630122dec9
|
218
|
void readTemp();
|
5hel2l2y |
0:46630122dec9
|
219
|
|
5hel2l2y |
0:46630122dec9
|
220
|
/** setGyroScale() -- Set the full-scale range of the gyroscope.
|
5hel2l2y |
0:46630122dec9
|
221
|
* This function can be called to set the scale of the gyroscope to
|
5hel2l2y |
0:46630122dec9
|
222
|
* 245, 500, or 2000 degrees per second.
|
5hel2l2y |
0:46630122dec9
|
223
|
* Input:
|
5hel2l2y |
0:46630122dec9
|
224
|
* - gScl = The desired gyroscope scale. Must be one of three possible
|
5hel2l2y |
0:46630122dec9
|
225
|
* values from the gyro_scale enum.
|
5hel2l2y |
0:46630122dec9
|
226
|
*/
|
5hel2l2y |
0:46630122dec9
|
227
|
void setGyroScale(gyro_scale gScl);
|
5hel2l2y |
0:46630122dec9
|
228
|
|
5hel2l2y |
0:46630122dec9
|
229
|
/** setAccelScale() -- Set the full-scale range of the accelerometer.
|
5hel2l2y |
0:46630122dec9
|
230
|
* This function can be called to set the scale of the accelerometer to
|
5hel2l2y |
0:46630122dec9
|
231
|
* 2, 4, 8, or 16 g's.
|
5hel2l2y |
0:46630122dec9
|
232
|
* Input:
|
5hel2l2y |
0:46630122dec9
|
233
|
* - aScl = The desired accelerometer scale. Must be one of five possible
|
5hel2l2y |
0:46630122dec9
|
234
|
* values from the accel_scale enum.
|
5hel2l2y |
0:46630122dec9
|
235
|
*/
|
5hel2l2y |
0:46630122dec9
|
236
|
void setAccelScale(accel_scale aScl);
|
5hel2l2y |
0:46630122dec9
|
237
|
|
5hel2l2y |
0:46630122dec9
|
238
|
/** setGyroODR() -- Set the output data rate and bandwidth of the gyroscope
|
5hel2l2y |
0:46630122dec9
|
239
|
* Input:
|
5hel2l2y |
0:46630122dec9
|
240
|
* - gRate = The desired output rate and cutoff frequency of the gyro.
|
5hel2l2y |
0:46630122dec9
|
241
|
* Must be a value from the gyro_odr enum (check above).
|
5hel2l2y |
0:46630122dec9
|
242
|
*/
|
5hel2l2y |
0:46630122dec9
|
243
|
void setGyroODR(gyro_odr gRate);
|
5hel2l2y |
0:46630122dec9
|
244
|
|
5hel2l2y |
0:46630122dec9
|
245
|
/** setAccelODR() -- Set the output data rate of the accelerometer
|
5hel2l2y |
0:46630122dec9
|
246
|
* Input:
|
5hel2l2y |
0:46630122dec9
|
247
|
* - aRate = The desired output rate of the accel.
|
5hel2l2y |
0:46630122dec9
|
248
|
* Must be a value from the accel_odr enum (check above).
|
5hel2l2y |
0:46630122dec9
|
249
|
*/
|
5hel2l2y |
0:46630122dec9
|
250
|
void setAccelODR(accel_odr aRate);
|
5hel2l2y |
0:46630122dec9
|
251
|
|
5hel2l2y |
0:46630122dec9
|
252
|
|
5hel2l2y |
0:46630122dec9
|
253
|
private:
|
5hel2l2y |
0:46630122dec9
|
254
|
/** xgAddress store the I2C address
|
5hel2l2y |
0:46630122dec9
|
255
|
* for each sensor.
|
5hel2l2y |
0:46630122dec9
|
256
|
*/
|
5hel2l2y |
0:46630122dec9
|
257
|
uint8_t xgAddress;
|
5hel2l2y |
0:46630122dec9
|
258
|
|
5hel2l2y |
0:46630122dec9
|
259
|
// I2C bus
|
5hel2l2y |
0:46630122dec9
|
260
|
I2C i2c;
|
5hel2l2y |
0:46630122dec9
|
261
|
|
5hel2l2y |
0:46630122dec9
|
262
|
/** gScale, and aScale store the current scale range for each
|
5hel2l2y |
0:46630122dec9
|
263
|
* sensor. Should be updated whenever that value changes.
|
5hel2l2y |
0:46630122dec9
|
264
|
*/
|
5hel2l2y |
0:46630122dec9
|
265
|
gyro_scale gScale;
|
5hel2l2y |
0:46630122dec9
|
266
|
accel_scale aScale;
|
5hel2l2y |
0:46630122dec9
|
267
|
|
5hel2l2y |
0:46630122dec9
|
268
|
/** gRes, and aRes store the current resolution for each sensor.
|
5hel2l2y |
0:46630122dec9
|
269
|
* Units of these values would be DPS (or g's or Gs's) per ADC tick.
|
5hel2l2y |
0:46630122dec9
|
270
|
* This value is calculated as (sensor scale) / (2^15).
|
5hel2l2y |
0:46630122dec9
|
271
|
*/
|
5hel2l2y |
0:46630122dec9
|
272
|
float gRes, aRes;
|
5hel2l2y |
0:46630122dec9
|
273
|
|
5hel2l2y |
0:46630122dec9
|
274
|
/** initGyro() -- Sets up the gyroscope to begin reading.
|
5hel2l2y |
0:46630122dec9
|
275
|
* This function steps through all three gyroscope control registers.
|
5hel2l2y |
0:46630122dec9
|
276
|
*/
|
5hel2l2y |
0:46630122dec9
|
277
|
void initGyro();
|
5hel2l2y |
0:46630122dec9
|
278
|
|
5hel2l2y |
0:46630122dec9
|
279
|
/** initAccel() -- Sets up the accelerometer to begin reading.
|
5hel2l2y |
0:46630122dec9
|
280
|
* This function steps through all accelerometer related control registers.
|
5hel2l2y |
0:46630122dec9
|
281
|
*/
|
5hel2l2y |
0:46630122dec9
|
282
|
void initAccel();
|
5hel2l2y |
0:46630122dec9
|
283
|
|
5hel2l2y |
0:46630122dec9
|
284
|
/** calcgRes() -- Calculate the resolution of the gyroscope.
|
5hel2l2y |
0:46630122dec9
|
285
|
* This function will set the value of the gRes variable. gScale must
|
5hel2l2y |
0:46630122dec9
|
286
|
* be set prior to calling this function.
|
5hel2l2y |
0:46630122dec9
|
287
|
*/
|
5hel2l2y |
0:46630122dec9
|
288
|
void calcgRes();
|
5hel2l2y |
0:46630122dec9
|
289
|
|
5hel2l2y |
0:46630122dec9
|
290
|
/** calcaRes() -- Calculate the resolution of the accelerometer.
|
5hel2l2y |
0:46630122dec9
|
291
|
* This function will set the value of the aRes variable. aScale must
|
5hel2l2y |
0:46630122dec9
|
292
|
* be set prior to calling this function.
|
5hel2l2y |
0:46630122dec9
|
293
|
*/
|
5hel2l2y |
0:46630122dec9
|
294
|
void calcaRes();
|
5hel2l2y |
0:46630122dec9
|
295
|
};
|
5hel2l2y |
0:46630122dec9
|
296
|
|
5hel2l2y |
0:46630122dec9
|
297
|
#endif // _LSM6DS3_H //
|