-
Notifications
You must be signed in to change notification settings - Fork 10
/
getbno055.h
351 lines (320 loc) · 14.6 KB
/
getbno055.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
/* ------------------------------------------------------------ *
* file: getbno055.h *
* purpose: header file for getbno055.c and i2c_bno055.c *
* *
* author: 05/04/2018 Frank4DD *
* ------------------------------------------------------------ */
#define I2CBUS "/dev/i2c-1"
#define BNO055_ID 0xA0
#define POWER_MODE_NORMAL 0x00
//#define CALIB_BYTECOUNT 22
#define CALIB_BYTECOUNT 34
#define REGISTERMAP_END 0x7F
/* ------------------------------------------------------------ *
* Page-0 registers with general confguration and data output *
* ------------------------------------------------------------ */
#define BNO055_CHIP_ID_ADDR 0x00
/* Page ID register, for page switching */
#define BNO055_PAGE_ID_ADDR 0x07
/* Accel data register */
#define BNO055_ACC_DATA_X_LSB_ADDR 0x08
#define BNO055_ACC_DATA_X_MSB_ADDR 0x09
#define BNO055_ACC_DATA_Y_LSB_ADDR 0x0A
#define BNO055_ACC_DATA_Y_MSB_ADDR 0x0B
#define BNO055_ACC_DATA_Z_LSB_ADDR 0x0C
#define BNO055_ACC_DATA_Z_MSB_ADDR 0x0D
/* Mag data register */
#define BNO055_MAG_DATA_X_LSB_ADDR 0x0E
#define BNO055_MAG_DATA_X_MSB_ADDR 0x0F
#define BNO055_MAG_DATA_Y_LSB_ADDR 0x10
#define BNO055_MAG_DATA_Y_MSB_ADDR 0x11
#define BNO055_MAG_DATA_Z_LSB_ADDR 0x12
#define BNO055_MAG_DATA_Z_MSB_ADDR 0x13
/* Gyro data registers */
#define BNO055_GYRO_DATA_X_LSB_ADDR 0x14
#define BNO055_GYRO_DATA_X_MSB_ADDR 0x15
#define BNO055_GYRO_DATA_Y_LSB_ADDR 0x16
#define BNO055_GYRO_DATA_Y_MSB_ADDR 0x17
#define BNO055_GYRO_DATA_Z_LSB_ADDR 0x18
#define BNO055_GYRO_DATA_Z_MSB_ADDR 0x19
/* Euler data registers */
#define BNO055_EULER_H_LSB_ADDR 0x1A
#define BNO055_EULER_H_MSB_ADDR 0x1B
#define BNO055_EULER_R_LSB_ADDR 0x1C
#define BNO055_EULER_R_MSB_ADDR 0x1D
#define BNO055_EULER_P_LSB_ADDR 0x1E
#define BNO055_EULER_P_MSB_ADDR 0x1F
/* Quaternion data registers */
#define BNO055_QUATERNION_DATA_W_LSB_ADDR 0x20
#define BNO055_QUATERNION_DATA_W_MSB_ADDR 0x21
#define BNO055_QUATERNION_DATA_X_LSB_ADDR 0x22
#define BNO055_QUATERNION_DATA_X_MSB_ADDR 0x23
#define BNO055_QUATERNION_DATA_Y_LSB_ADDR 0x24
#define BNO055_QUATERNION_DATA_Y_MSB_ADDR 0x25
#define BNO055_QUATERNION_DATA_Z_LSB_ADDR 0x26
#define BNO055_QUATERNION_DATA_Z_MSB_ADDR 0x27
/* Linear acceleration data registers */
#define BNO055_LIN_ACC_DATA_X_LSB_ADDR 0x28
#define BNO055_LIN_ACC_DATA_X_MSB_ADDR 0x29
#define BNO055_LIN_ACC_DATA_Y_LSB_ADDR 0x2A
#define BNO055_LIN_ACC_DATA_Y_MSB_ADDR 0x2B
#define BNO055_LIN_ACC_DATA_Z_LSB_ADDR 0x2C
#define BNO055_LIN_ACC_DATA_Z_MSB_ADDR 0x2D
/* Gravity data registers */
#define BNO055_GRAVITY_DATA_X_LSB_ADDR 0x2E
#define BNO055_GRAVITY_DATA_X_MSB_ADDR 0x2F
#define BNO055_GRAVITY_DATA_Y_LSB_ADDR 0x30
#define BNO055_GRAVITY_DATA_Y_MSB_ADDR 0x31
#define BNO055_GRAVITY_DATA_Z_LSB_ADDR 0x32
#define BNO055_GRAVITY_DATA_Z_MSB_ADDR 0x33
/* Temperature data register */
#define BNO055_TEMP_ADDR 0x34
/* Status registers */
#define BNO055_CALIB_STAT_ADDR 0x35
#define BNO055_SELFTSTRES_ADDR 0x36
#define BNO055_INTR_STAT_ADDR 0x37
#define BNO055_SYS_CLK_STAT_ADDR 0x38
#define BNO055_SYS_STAT_ADDR 0x39
#define BNO055_SYS_ERR_ADDR 0x3A
/* Unit selection register */
#define BNO055_UNIT_SEL_ADDR 0x3B
#define BNO055_DATA_SELECT_ADDR 0x3C
/* Mode registers */
#define BNO055_OPR_MODE_ADDR 0x3D
#define BNO055_PWR_MODE_ADDR 0x3E
#define BNO055_SYS_TRIGGER_ADDR 0x3F
#define BNO055_TEMP_SOURCE_ADDR 0x40
/* Axis remap registers */
#define BNO055_AXIS_MAP_CONFIG_ADDR 0x41
#define BNO055_AXIS_MAP_SIGN_ADDR 0x42
/* Soft Iron Calibration registers */
#define BNO055_SIC_MATRIX_0_LSB_ADDR 0x43
#define BNO055_SIC_MATRIX_0_MSB_ADDR 0x44
#define BNO055_SIC_MATRIX_1_LSB_ADDR 0x45
#define BNO055_SIC_MATRIX_1_MSB_ADDR 0x46
#define BNO055_SIC_MATRIX_2_LSB_ADDR 0x47
#define BNO055_SIC_MATRIX_2_MSB_ADDR 0x48
#define BNO055_SIC_MATRIX_3_LSB_ADDR 0x49
#define BNO055_SIC_MATRIX_3_MSB_ADDR 0x4A
#define BNO055_SIC_MATRIX_4_LSB_ADDR 0x4B
#define BNO055_SIC_MATRIX_4_MSB_ADDR 0x4C
#define BNO055_SIC_MATRIX_5_LSB_ADDR 0x4D
#define BNO055_SIC_MATRIX_5_MSB_ADDR 0x4E
#define BNO055_SIC_MATRIX_6_LSB_ADDR 0x4F
#define BNO055_SIC_MATRIX_6_MSB_ADDR 0x50
#define BNO055_SIC_MATRIX_7_LSB_ADDR 0x51
#define BNO055_SIC_MATRIX_7_MSB_ADDR 0x52
#define BNO055_SIC_MATRIX_8_LSB_ADDR 0x53
#define BNO055_SIC_MATRIX_8_MSB_ADDR 0x54
/* Accelerometer Offset registers */
#define ACC_OFFSET_X_LSB_ADDR 0x55
#define ACC_OFFSET_X_MSB_ADDR 0x56
#define ACC_OFFSET_Y_LSB_ADDR 0x57
#define ACC_OFFSET_Y_MSB_ADDR 0x58
#define ACC_OFFSET_Z_LSB_ADDR 0x59
#define ACC_OFFSET_Z_MSB_ADDR 0x5A
/* Magnetometer Offset registers */
#define MAG_OFFSET_X_LSB_ADDR 0x5B
#define MAG_OFFSET_X_MSB_ADDR 0x5C
#define MAG_OFFSET_Y_LSB_ADDR 0x5D
#define MAG_OFFSET_Y_MSB_ADDR 0x5E
#define MAG_OFFSET_Z_LSB_ADDR 0x5F
#define MAG_OFFSET_Z_MSB_ADDR 0x60
/* Gyroscope Offset register s*/
#define GYRO_OFFSET_X_LSB_ADDR 0x61
#define GYRO_OFFSET_X_MSB_ADDR 0x62
#define GYRO_OFFSET_Y_LSB_ADDR 0x63
#define GYRO_OFFSET_Y_MSB_ADDR 0x64
#define GYRO_OFFSET_Z_LSB_ADDR 0x65
#define GYRO_OFFSET_Z_MSB_ADDR 0x66
/* Radius registers */
#define ACCEL_RADIUS_LSB_ADDR 0x67
#define ACCEL_RADIUS_MSB_ADDR 0x68
#define MAG_RADIUS_LSB_ADDR 0x69
#define MAG_RADIUS_MSB_ADDR 0x6A
/* ------------------------------------------------------------ *
* Page-1 contains sensor component specific confguration data *
* ------------------------------------------------------------ */
#define BNO055_ACC_CONFIG_ADDR 0x08
#define BNO055_MAG_CONFIG_ADDR 0x09
#define BNO055_GYR_CONFIG0_ADDR 0x0A
#define BNO055_GYR_CONFIG1_ADDR 0x0B
#define BNO055_ACC_SLEEP_CONFIG_ADDR 0x0C
#define BNO055_GYR_SLEEP_CONFIG_ADDR 0x0D
/* ------------------------------------------------------------ *
* global variables *
* ------------------------------------------------------------ */
extern int verbose; // debug flag, 0 = normal, 1 = debug mode
/* ------------------------------------------------------------ *
* BNO055 versions, status data and other infos struct *
* ------------------------------------------------------------ */
struct bnoinf{
char chip_id; // reg 0x00 default 0xA0
char acc_id; // reg 0x01 default 0xFB
char mag_id; // reg 0x02 default 0x32
char gyr_id; // reg 0x03 default 0x0F
char sw_lsb; // reg 0x04 default 0x08
char sw_msb; // reg 0x05 default 0x03
char bl_rev; // reg 0x06 no default
char opr_mode; // reg 0x3D default 0x1C
char pwr_mode; // reg 0x3E default 0x00
char axr_conf; // reg 0x41 default 0x24
char axr_sign; // reg 0x42 default 0x00
char sys_stat; // reg 0x39 system error status, range 0-6
char selftest; // reg 0x36 self test result
char sys_err; // reg 0x3a system error code, 0=OK
char unitsel; // reg 0x3b SI units definition
char temp_val; // reg 0x34 sensor temperature value
};
/* ------------------------------------------------------------ *
* BNO055 calibration data struct. The offset ranges depend on *
* the component operation range. For example, the accelerometer*
* range can be set as 2G, 4G, 8G, and 16G. I.e. the offset for *
* the accelerometer at 16G has a range of +/- 16000mG. Offset *
* is stored on the sensor in two bytes with max value of 32768.*
* ------------------------------------------------------------ */
struct bnocal{
char scal_st; // reg 0x35 system calibration state, range 0-3
char gcal_st; // gyroscope calibration state, range 0-3
char acal_st; // accelerometer calibration state, range 0-3
char mcal_st; // magnetometer calibration state, range 0-3
int aoff_x; // accelerometer offset, X-axis
int aoff_y; // accelerometer offset, Y-axis
int aoff_z; // accelerometer offset, Z-axis
int moff_x; // magnetometer offset, X-axis
int moff_y; // magnetometer offset, Y-axis
int moff_z; // magnetometer offset, Z-axis
int goff_x; // gyroscope offset, X-axis
int goff_y; // gyroscope offset, Y-axis
int goff_z; // gyroscope offset, Z-axis
int acc_rad; // accelerometer radius
int mag_rad; // magnetometer radius
};
/* ------------------------------------------------------------ *
* BNO055 measurement data structs. Data gets filled in based *
* on the sensor component type that was requested for reading. *
* ------------------------------------------------------------ */
struct bnoacc{
double adata_x; // accelerometer data, X-axis
double adata_y; // accelerometer data, Y-axis
double adata_z; // accelerometer data, Z-axis
};
struct bnomag{
double mdata_x; // magnetometer data, X-axis
double mdata_y; // magnetometer data, Y-axis
double mdata_z; // magnetometer data, Z-axis
};
struct bnogyr{
double gdata_x; // gyroscope data, X-axis
double gdata_y; // gyroscope data, Y-axis
double gdata_z; // gyroscope data, Z-axis
};
struct bnoeul{
double eul_head; // Euler heading data
double eul_roll; // Euler roll data
double eul_pitc; // Euler picth data
};
struct bnoqua{
double quater_w; // Quaternation data W
double quater_x; // Quaternation data X
double quater_y; // Quaternation data Y
double quater_z; // Quaternation data Z
};
struct bnogra{
double gravityx; // Gravity Vector X
double gravityy; // Gravity Vector Y
double gravityz; // Gravity Vector Z
};
struct bnolin{
double linacc_x; // Linear Acceleration X
double linacc_y; // Linear Acceleration Y
double linacc_z; // Linear Acceleration Z
};
/* ------------------------------------------------------------ *
* BNO055 accelerometer gyroscope magnetometer config structs *
* ------------------------------------------------------------ */
struct bnoaconf{
int pwrmode; // p-1 reg 0x08 accelerometer power mode
int bandwth; // p-1 reg 0x08 accelerometer bandwidth
int range; // p-1 reg 0x08 accelerometer rate
int slpmode; // p-1 reg 0x0C accelerometer sleep mode
int slpdur; // p-1 reg 0x0C accelerometer sleep duration
};
struct bnomconf{
int pwrmode; // p-1 reg 0x09 magnetometer power mode
int oprmode; // p-1 reg 0x09 magnetometer operation
int outrate; // p-1 reg 0x09 magnetometer output rate
};
struct bnogconf{
int pwrmode; // p-1 reg 0x0B gyroscope power mode
int bandwth; // p-1 reg 0x0A gyroscope bandwidth
int range; // p-1 reg 0x0A gyroscope range
int slpdur; // p-1 reg 0x0D gyroscope sleep duration
int aslpdur; // p-1 reg 0x0D gyroscope auto sleep dur
};
/* ------------------------------------------------------------ *
* Operations and power mode, name to value translation *
* ------------------------------------------------------------ */
typedef enum {
config = 0x00,
acconly = 0x01,
magonly = 0x02,
gyronly = 0x03,
accmag = 0x04,
accgyro = 0x05,
maggyro = 0x06,
amg = 0x07,
imu = 0x08,
compass = 0x09,
m4g = 0x0A,
ndof = 0x0B,
ndof_fmc = 0x0C
} opmode_t;
typedef enum {
normal = 0x00,
low = 0x01,
suspend = 0x02
} power_t;
/* ------------------------------------------------------------ *
* external function prototypes for I2C bus communication code *
* ------------------------------------------------------------ */
extern void get_i2cbus(char*, char*); // get the I2C bus file handle
extern int set_page0(); // set register map page 0
extern int set_page1(); // set register map page 1
extern int get_calstatus(struct bnocal*); // read calibration status
extern int get_caloffset(struct bnocal*); // read calibration values
extern int get_inf(struct bnoinf*); // read sensor information
extern int get_acc(struct bnoacc*); // read accelerometer data
extern int get_mag(struct bnomag*); // read magnetometer data
extern int get_gyr(struct bnogyr*); // read gyroscope data
extern int get_eul(struct bnoeul*); // read euler orientation
extern int get_qua(struct bnoqua*); // read quaternation data
extern int get_gra(struct bnogra*); // read gravity data
extern int get_lin(struct bnolin*); // read linar acceleration data
extern int get_clksrc(); // get the clock source setting
extern void print_clksrc(); // print clock source setting
extern int set_mode(opmode_t); // set the sensor ops mode
extern int get_mode(); // get the sensor ops mode
extern int print_mode(int); // print ops mode string
extern void print_unit(int); // print SI unit configuration
extern int set_power(power_t); // set the sensor power mode
extern int get_power(); // get the sensor power mode
extern int print_power(int); // print power mode string
extern int get_sstat(); // get system status code
extern int print_sstat(int); // print system status string
extern int get_remap(char); // get the axis remap values
extern int print_remap_conf(int); // print axis configuration
extern int print_remap_sign(int); // print the axis remap +/-
extern int bno_dump(); // dump the register map data
extern int bno_reset(); // reset the sensor
extern int save_cal(char*); // write calibration to file
extern int load_cal(char*); // load calibration from file
extern int get_acc_conf(struct bnoaconf*);// get accelerometer config
extern int get_mag_conf(struct bnomconf*);// get magnetometer config
extern int get_gyr_conf(struct bnogconf*);// get gyroscope config
extern int set_acc_conf(); // set accelerometer config
extern int set_mag_conf(); // set magnetometer config
extern int set_gyr_conf(); // set gyroscope config
extern void print_acc_conf(); // print accelerometer config
extern void print_mag_conf(); // print magnetometer config
extern void print_gyr_conf(); // print gyroscope config