1 | /****************************************************************************
|
---|
2 | * Copyright (C) 2011 - 2014 Bosch Sensortec GmbH
|
---|
3 | *
|
---|
4 | * NAxisMotion.cpp
|
---|
5 | * Date: 2015/02/10
|
---|
6 | * Revision: 3.0 $
|
---|
7 | *
|
---|
8 | * Usage: Source file of the C++ Wrapper for the BNO055 Sensor API
|
---|
9 | *
|
---|
10 | ****************************************************************************
|
---|
11 | *
|
---|
12 | * Added Arduino M0/M0 Pro support
|
---|
13 | *
|
---|
14 | * Date: 07/27/2015
|
---|
15 | *
|
---|
16 | * Modified by: Arduino.org development Team.
|
---|
17 | *
|
---|
18 | ****************************************************************************
|
---|
19 | /***************************************************************************
|
---|
20 | * License:
|
---|
21 | *
|
---|
22 | * Redistribution and use in source and binary forms, with or without
|
---|
23 | * modification, are permitted provided that the following conditions are met:
|
---|
24 | *
|
---|
25 | * Redistributions of source code must retain the above copyright
|
---|
26 | * notice, this list of conditions and the following disclaimer.
|
---|
27 | *
|
---|
28 | * Redistributions in binary form must reproduce the above copyright
|
---|
29 | * notice, this list of conditions and the following disclaimer in the
|
---|
30 | * documentation and/or other materials provided with the distribution.
|
---|
31 | *
|
---|
32 | * Neither the name of the copyright holder nor the names of the
|
---|
33 | * contributors may be used to endorse or promote products derived from
|
---|
34 | * this software without specific prior written permission.
|
---|
35 | *
|
---|
36 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
---|
37 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
---|
38 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
---|
39 | * DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
|
---|
40 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
---|
41 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
---|
42 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
---|
43 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
44 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
---|
45 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
|
---|
46 | *
|
---|
47 | * The information provided is believed to be accurate and reliable.
|
---|
48 | * The copyright holder assumes no responsibility for the consequences of use
|
---|
49 | * of such information nor for any infringement of patents or
|
---|
50 | * other rights of third parties which may result from its use.
|
---|
51 | * No license is granted by implication or otherwise under any patent or
|
---|
52 | * patent rights of the copyright holder.
|
---|
53 | */
|
---|
54 | #include "NAxisMotion.h"
|
---|
55 | //Function Definitions
|
---|
56 | /*******************************************************************************************
|
---|
57 | *Description: Constructor of the class with the default initialization
|
---|
58 | *Input Parameters: None
|
---|
59 | *Return Parameter: None
|
---|
60 | *******************************************************************************************/
|
---|
61 | NAxisMotion::NAxisMotion()
|
---|
62 | {
|
---|
63 | //Blank
|
---|
64 | }
|
---|
65 |
|
---|
66 | /*******************************************************************************************
|
---|
67 | *Description: Function with the bare minimum initialization
|
---|
68 | *Input Parameters: None
|
---|
69 | *Return Parameter: None
|
---|
70 | *******************************************************************************************/
|
---|
71 | void NAxisMotion::initSensor(unsigned int address)
|
---|
72 | {
|
---|
73 | //Initialize the GPIO peripheral
|
---|
74 | pinMode(INT_PIN, INPUT_PULLUP); //Configure Interrupt pin
|
---|
75 | pinMode(RESET_PIN, OUTPUT); //Configure Reset pin
|
---|
76 |
|
---|
77 | //Power on the BNO055
|
---|
78 | resetSensor(address);
|
---|
79 | }
|
---|
80 |
|
---|
81 | /*******************************************************************************************
|
---|
82 | *Description: This function is used to reset the BNO055
|
---|
83 | *Input Parameters: None
|
---|
84 | *Return Parameter: None
|
---|
85 | *******************************************************************************************/
|
---|
86 | void NAxisMotion::resetSensor(unsigned int address)
|
---|
87 | {
|
---|
88 | //Reset sequence
|
---|
89 | digitalWrite(RESET_PIN, LOW); //Set the Reset pin LOW
|
---|
90 | delay(RESET_PERIOD); //Hold it for a while
|
---|
91 | digitalWrite(RESET_PIN, HIGH); //Set the Reset pin HIGH
|
---|
92 | delay(INIT_PERIOD); //Pause for a while to let the sensor initialize completely (Anything >500ms should be fine)
|
---|
93 | //Initialization sequence
|
---|
94 | //Link the function pointers for communication (late-binding)
|
---|
95 | myBNO.bus_read = BNO055_I2C_bus_read;
|
---|
96 | myBNO.bus_write = BNO055_I2C_bus_write;
|
---|
97 | myBNO.delay_msec = _delay;
|
---|
98 |
|
---|
99 | //Set the I2C address here !!! ADDR1 is the default address
|
---|
100 | //myBNO.dev_addr = BNO055_I2C_ADDR1;
|
---|
101 | myBNO.dev_addr = address;
|
---|
102 | //myBNO.dev_addr = BNO055_I2C_ADDR2;
|
---|
103 |
|
---|
104 | //Initialize the BNO055 structure to hold the device information
|
---|
105 | bno055_init(&myBNO);
|
---|
106 |
|
---|
107 | //Post initialization delay
|
---|
108 | delay(POST_INIT_PERIOD);
|
---|
109 |
|
---|
110 | //To set the output data format to the Android style
|
---|
111 | bno055_set_data_output_format(ANDROID);
|
---|
112 |
|
---|
113 | //Set the default data update mode to auto
|
---|
114 | dataUpdateMode = AUTO;
|
---|
115 | }
|
---|
116 |
|
---|
117 | /*******************************************************************************************
|
---|
118 | *Description: This function is used to set the operation mode of the BNO055
|
---|
119 | *Input Parameters:
|
---|
120 | * byte operationMode: To assign which operation mode the device has to
|
---|
121 | * ---------------------------------------------------
|
---|
122 | * Constant Definition Constant Value Comment
|
---|
123 | * ---------------------------------------------------
|
---|
124 | * OPERATION_MODE_CONFIG 0x00 Configuration Mode
|
---|
125 | * (Transient Mode)
|
---|
126 | * OPERATION_MODE_ACCONLY 0x01 Accelerometer only
|
---|
127 | * OPERATION_MODE_MAGONLY 0x02 Magnetometer only
|
---|
128 | * OPERATION_MODE_GYRONLY 0x03 Gyroscope only
|
---|
129 | * OPERATION_MODE_ACCMAG 0x04 Accelerometer and Magnetometer only
|
---|
130 | * OPERATION_MODE_ACCGYRO 0x05 Accelerometer and Gyroscope only
|
---|
131 | * OPERATION_MODE_MAGGYRO 0x06 Magnetometer and Gyroscope only
|
---|
132 | * OPERATION_MODE_AMG 0x07 Accelerometer, Magnetometer and
|
---|
133 | * Gyroscope (without fusion)
|
---|
134 | * OPERATION_MODE_IMUPLUS 0x08 Inertial Measurement Unit
|
---|
135 | * (Accelerometer and Gyroscope
|
---|
136 | * Sensor Fusion Mode)
|
---|
137 | * OPERATION_MODE_COMPASS 0x09 Tilt Compensated Compass
|
---|
138 | * (Accelerometer and Magnetometer
|
---|
139 | * Sensor Fusion Mode)
|
---|
140 | * OPERATION_MODE_M4G 0x0A Magnetometer and Gyroscope Sensor
|
---|
141 | * Fusion Mode
|
---|
142 | * OPERATION_MODE_NDOF_FMC_OFF 0x0B 9 Degrees of Freedom Sensor Fusion
|
---|
143 | * with Fast Magnetometer Calibration Off
|
---|
144 | * OPERATION_MODE_NDOF 0x0C 9 Degrees of Freedom Sensor Fusion
|
---|
145 | *Return Parameter: None
|
---|
146 | *******************************************************************************************/
|
---|
147 | void NAxisMotion::setOperationMode(byte operationMode)
|
---|
148 | {
|
---|
149 | BNO055_RETURN_FUNCTION_TYPE comRes = BNO055_ZERO_U8X; //Holds the communication results
|
---|
150 | comRes = bno055_set_operation_mode(operationMode); //Set the Operation Mode
|
---|
151 | }
|
---|
152 |
|
---|
153 | /*******************************************************************************************
|
---|
154 | *Description: This function is used to set the power mode
|
---|
155 | *Input Parameters:
|
---|
156 | * byte powerMode: To assign the power mode the device has to switch to
|
---|
157 | * --------------------------------------
|
---|
158 | * Constant Definition Constant Value
|
---|
159 | * --------------------------------------
|
---|
160 | * POWER_MODE_NORMAL 0x00
|
---|
161 | * POWER_MODE_LOWPOWER 0x01
|
---|
162 | * POWER_MODE_SUSPEND 0x02
|
---|
163 | *Return Parameter:
|
---|
164 | *******************************************************************************************/
|
---|
165 | void NAxisMotion::setPowerMode(byte powerMode)
|
---|
166 | {
|
---|
167 | BNO055_RETURN_FUNCTION_TYPE comRes = BNO055_ZERO_U8X; //Holds the communication results
|
---|
168 | comRes = bno055_set_power_mode(powerMode); //Set the Power Mode
|
---|
169 | }
|
---|
170 |
|
---|
171 | /*******************************************************************************************
|
---|
172 | *Description: This function is used to update the accelerometer data in m/s2
|
---|
173 | *Input Parameters: None
|
---|
174 | *Return Parameter: None
|
---|
175 | *******************************************************************************************/
|
---|
176 | void NAxisMotion::updateAccel(void)
|
---|
177 | {
|
---|
178 | BNO055_RETURN_FUNCTION_TYPE comRes = BNO055_ZERO_U8X; //Holds the communication results
|
---|
179 | comRes = bno055_convert_float_accel_xyz_msq(&accelData); //Read the data from the sensor
|
---|
180 | }
|
---|
181 |
|
---|
182 | /*******************************************************************************************
|
---|
183 | *Description: This function is used to update the magnetometer data in microTesla
|
---|
184 | *Input Parameters: None
|
---|
185 | *Return Parameter: None
|
---|
186 | *******************************************************************************************/
|
---|
187 | void NAxisMotion::updateMag(void)
|
---|
188 | {
|
---|
189 | BNO055_RETURN_FUNCTION_TYPE comRes = BNO055_ZERO_U8X; //Holds the communication results
|
---|
190 | comRes = bno055_convert_float_mag_xyz_uT(&magData); //Read the data from the sensor
|
---|
191 | }
|
---|
192 |
|
---|
193 | /*******************************************************************************************
|
---|
194 | *Description: This function is used to update the gyroscope data in deg/s
|
---|
195 | *Input Parameters: None
|
---|
196 | *Return Parameter: None
|
---|
197 | *******************************************************************************************/
|
---|
198 | void NAxisMotion::updateGyro(void)
|
---|
199 | {
|
---|
200 | BNO055_RETURN_FUNCTION_TYPE comRes = BNO055_ZERO_U8X; //Holds the communication results
|
---|
201 | comRes = bno055_convert_float_gyro_xyz_dps(&gyroData); //Read the data from the sensor
|
---|
202 | }
|
---|
203 |
|
---|
204 | /*******************************************************************************************
|
---|
205 | *Description: This function is used to update the quaternion data
|
---|
206 | *Input Parameters: None
|
---|
207 | *Return Parameter: None
|
---|
208 | *******************************************************************************************/
|
---|
209 | void NAxisMotion::updateQuat(void)
|
---|
210 | {
|
---|
211 | BNO055_RETURN_FUNCTION_TYPE comRes = BNO055_ZERO_U8X; //Holds the communication results
|
---|
212 | comRes = bno055_read_quaternion_wxyz(&quatData); //Read the data from the sensor
|
---|
213 | }
|
---|
214 |
|
---|
215 | /*******************************************************************************************
|
---|
216 | *Description: This function is used to update the euler data in degrees
|
---|
217 | *Input Parameters: None
|
---|
218 | *Return Parameter: None
|
---|
219 | *******************************************************************************************/
|
---|
220 | void NAxisMotion::updateEuler(void)
|
---|
221 | {
|
---|
222 | BNO055_RETURN_FUNCTION_TYPE comRes = BNO055_ZERO_U8X; //Holds the communication results
|
---|
223 | comRes = bno055_convert_float_euler_hpr_deg(&eulerData); //Read the data from the sensor
|
---|
224 | }
|
---|
225 |
|
---|
226 |
|
---|
227 | /*******************************************************************************************
|
---|
228 | *Description: This function is used to update the linear acceleration data in m/s2
|
---|
229 | *Input Parameters: None
|
---|
230 | *Return Parameter: None
|
---|
231 | *******************************************************************************************/
|
---|
232 | void NAxisMotion::updateLinearAccel(void)
|
---|
233 | {
|
---|
234 | BNO055_RETURN_FUNCTION_TYPE comRes = BNO055_ZERO_U8X; //Holds the communication results
|
---|
235 | comRes = bno055_convert_float_linear_accel_xyz_msq(&linearAccelData); //Read the data from the sensor
|
---|
236 | }
|
---|
237 |
|
---|
238 | /*******************************************************************************************
|
---|
239 | *Description: This function is used to update the gravity acceleration data in m/s2
|
---|
240 | *Input Parameters: None
|
---|
241 | *Return Parameter: None
|
---|
242 | *******************************************************************************************/
|
---|
243 | void NAxisMotion::updateGravAccel(void)
|
---|
244 | {
|
---|
245 | BNO055_RETURN_FUNCTION_TYPE comRes = BNO055_ZERO_U8X; //Holds the communication results
|
---|
246 | comRes = bno055_convert_float_gravity_xyz_msq(&gravAccelData); //Read the data from the sensor
|
---|
247 | }
|
---|
248 |
|
---|
249 | /*******************************************************************************************
|
---|
250 | *Description: This function is used to update the calibration status
|
---|
251 | *Input Parameters: None
|
---|
252 | *Return Parameter: None
|
---|
253 | *******************************************************************************************/
|
---|
254 | void NAxisMotion::updateCalibStatus(void)
|
---|
255 | {
|
---|
256 | BNO055_RETURN_FUNCTION_TYPE comRes = BNO055_ZERO_U8X; //Holds the communication results
|
---|
257 | comRes = bno055_get_accel_calib_stat(&calibStatus.accel);
|
---|
258 | comRes = bno055_get_mag_calib_stat(&calibStatus.mag);
|
---|
259 | comRes = bno055_get_gyro_calib_stat(&calibStatus.gyro);
|
---|
260 | comRes = bno055_get_sys_calib_stat(&calibStatus.system);
|
---|
261 | }
|
---|
262 |
|
---|
263 | /*******************************************************************************************
|
---|
264 | *Description: This function is used to write the accelerometer configurations
|
---|
265 | *Input Parameters:
|
---|
266 | * uint8_t range: To assign the range of the accelerometer
|
---|
267 | * --------------------------------------
|
---|
268 | * Constant Definition Constant Value
|
---|
269 | * --------------------------------------
|
---|
270 | * ACCEL_RANGE_2G 0X00
|
---|
271 | * ACCEL_RANGE_4G 0X01
|
---|
272 | * ACCEL_RANGE_8G 0X02
|
---|
273 | * ACCEL_RANGE_16G 0X03
|
---|
274 | * uint8_t bandwidth: To assign the filter bandwidth of the accelerometer
|
---|
275 | * --------------------------------------
|
---|
276 | * Constant Definition Constant Value
|
---|
277 | * --------------------------------------
|
---|
278 | * ACCEL_BW_7_81HZ 0x00
|
---|
279 | * ACCEL_BW_15_63HZ 0x01
|
---|
280 | * ACCEL_BW_31_25HZ 0x02
|
---|
281 | * ACCEL_BW_62_5HZ 0X03
|
---|
282 | * ACCEL_BW_125HZ 0X04
|
---|
283 | * ACCEL_BW_250HZ 0X05
|
---|
284 | * ACCEL_BW_500HZ 0X06
|
---|
285 | * ACCEL_BW_1000HZ 0X07
|
---|
286 | * uint8_t powerMode: To assign the power mode of the accelerometer
|
---|
287 | * --------------------------------------
|
---|
288 | * Constant Definition Constant Value
|
---|
289 | * --------------------------------------
|
---|
290 | * ACCEL_NORMAL 0X00
|
---|
291 | * ACCEL_SUSPEND 0X01
|
---|
292 | * ACCEL_LOWPOWER_1 0X02
|
---|
293 | * ACCEL_STANDBY 0X03
|
---|
294 | * ACCEL_LOWPOWER_2 0X04
|
---|
295 | * ACCEL_DEEPSUSPEND 0X05
|
---|
296 | *Return Parameter: None
|
---|
297 | *******************************************************************************************/
|
---|
298 | void NAxisMotion::writeAccelConfig(uint8_t range, uint8_t bandwidth, uint8_t powerMode)
|
---|
299 | {
|
---|
300 | BNO055_RETURN_FUNCTION_TYPE comRes = BNO055_ZERO_U8X; //Holds the communication results
|
---|
301 | comRes = bno055_set_accel_range(range);
|
---|
302 | comRes = bno055_set_accel_bw(bandwidth);
|
---|
303 | comRes = bno055_set_accel_power_mode(powerMode);
|
---|
304 | }
|
---|
305 |
|
---|
306 | /*******************************************************************************************
|
---|
307 | *Description: This function is used to update the accelerometer configurations
|
---|
308 | *Input Parameters: None
|
---|
309 | *Return Parameter: None
|
---|
310 | *******************************************************************************************/
|
---|
311 | void NAxisMotion::updateAccelConfig(void)
|
---|
312 | {
|
---|
313 | BNO055_RETURN_FUNCTION_TYPE comRes = BNO055_ZERO_U8X; //Holds the communication results
|
---|
314 | comRes = bno055_get_accel_range(&accelStatus.range);
|
---|
315 | comRes = bno055_get_accel_bw(&accelStatus.bandwidth);
|
---|
316 | comRes = bno055_get_accel_power_mode(&accelStatus.powerMode);
|
---|
317 | }
|
---|
318 |
|
---|
319 | /*******************************************************************************************
|
---|
320 | *Description: This function is used to control which axis of the accelerometer triggers the
|
---|
321 | * interrupt
|
---|
322 | *Input Parameters:
|
---|
323 | * bool xStatus: To know whether the x axis has to trigger the interrupt
|
---|
324 | * ---------------------------------------------------
|
---|
325 | * Constant Definition Constant Value Comment
|
---|
326 | * ---------------------------------------------------
|
---|
327 | * ENABLE 1 Enables interrupts from that axis
|
---|
328 | * DISABLE 0 Disables interrupts from that axis
|
---|
329 | * bool yStatus: To know whether the x axis has to trigger the interrupt
|
---|
330 | * ---------------------------------------------------
|
---|
331 | * Constant Definition Constant Value Comment
|
---|
332 | * ---------------------------------------------------
|
---|
333 | * ENABLE 1 Enables interrupts from that axis
|
---|
334 | * DISABLE 0 Disables interrupts from that axis
|
---|
335 | * bool zStatus: To know whether the x axis has to trigger the interrupt
|
---|
336 | * ---------------------------------------------------
|
---|
337 | * Constant Definition Constant Value Comment
|
---|
338 | * ---------------------------------------------------
|
---|
339 | * ENABLE 1 Enables interrupts from that axis
|
---|
340 | * DISABLE 0 Disables interrupts from that axis
|
---|
341 | *Return Parameter: None
|
---|
342 | *******************************************************************************************/
|
---|
343 | void NAxisMotion::accelInterrupts(bool xStatus, bool yStatus, bool zStatus)
|
---|
344 | {
|
---|
345 | BNO055_RETURN_FUNCTION_TYPE comRes = BNO055_ZERO_U8X; //Holds the communication results
|
---|
346 | comRes = bno055_set_accel_any_motion_no_motion_axis_enable(BNO055_ACCEL_ANY_MOTION_NO_MOTION_X_AXIS, xStatus);
|
---|
347 | comRes = bno055_set_accel_any_motion_no_motion_axis_enable(BNO055_ACCEL_ANY_MOTION_NO_MOTION_Y_AXIS, yStatus);
|
---|
348 | comRes = bno055_set_accel_any_motion_no_motion_axis_enable(BNO055_ACCEL_ANY_MOTION_NO_MOTION_Z_AXIS, zStatus);
|
---|
349 | }
|
---|
350 |
|
---|
351 | /*******************************************************************************************
|
---|
352 | *Description: This function is used to reset the interrupt line
|
---|
353 | *Input Parameters: None
|
---|
354 | *Return Parameter: None
|
---|
355 | *******************************************************************************************/
|
---|
356 | void NAxisMotion::resetInterrupt(void)
|
---|
357 | {
|
---|
358 | BNO055_RETURN_FUNCTION_TYPE comRes = BNO055_ZERO_U8X; //Holds the communication results
|
---|
359 | comRes = bno055_set_intr_rst(ENABLE);
|
---|
360 | }
|
---|
361 |
|
---|
362 | /*******************************************************************************************
|
---|
363 | *Description: This function is used to enable the any motion interrupt based on the
|
---|
364 | * accelerometer
|
---|
365 | *Input Parameters:
|
---|
366 | * uint8_t threshold: The threshold that triggers the any motion interrupt
|
---|
367 | * The threshold should be entered as an integer. The corresponding value of
|
---|
368 | * the threshold depends on the range that has been set on the
|
---|
369 | * accelerometer. Below is a table showing the value of 1LSB in
|
---|
370 | * corresponding units.
|
---|
371 | * Resolution:
|
---|
372 | * ACCEL_RANGE_2G, 1LSB = 3.91mg = ~0.03835m/s2
|
---|
373 | * ACCEL_RANGE_4G, 1LSB = 7.81mg = ~0.07661m/s2
|
---|
374 | * ACCEL_RANGE_8G, 1LSB = 15.6mg = ~0.15303m/s2
|
---|
375 | * ACCEL_RANGE_16G, 1LSB = 31.3mg = ~0.30705m/s2
|
---|
376 | * Maximum:
|
---|
377 | * ACCEL_RANGE_2G, 1LSB = 996mg = ~9.77076m/s2,
|
---|
378 | * ACCEL_RANGE_4G, 1LSB = 1.99g = ~19.5219m/s2
|
---|
379 | * ACCEL_RANGE_8G, 1LSB = 3.98g = ~39.0438m/s2
|
---|
380 | * ACCEL_RANGE_16G, 1LSB = 7.97g = ~97.1857m/s2
|
---|
381 | * uint8_t duration: The duration for which the desired threshold exist
|
---|
382 | * The time difference between the successive acceleration signals depends
|
---|
383 | * on the selected bandwidth and equates to 1/(2*bandwidth).
|
---|
384 | * In order to suppress false triggers, the interrupt is only generated (cleared)
|
---|
385 | * if a certain number N of consecutive slope data points is larger (smaller)
|
---|
386 | * than the slope 'threshold'. This number is set by the 'duration'.
|
---|
387 | * It is N = duration + 1.
|
---|
388 | * Resolution:
|
---|
389 | * ACCEL_BW_7_81HZ, 1LSB = 64ms
|
---|
390 | * ACCEL_BW_15_63HZ, 1LSB = 32ms
|
---|
391 | * ACCEL_BW_31_25HZ, 1LSB = 16ms
|
---|
392 | * ACCEL_BW_62_5HZ, 1LSB = 8ms
|
---|
393 | * ACCEL_BW_125HZ, 1LSB = 4ms
|
---|
394 | * ACCEL_BW_250HZ, 1LSB = 2ms
|
---|
395 | * ACCEL_BW_500HZ, 1LSB = 1ms
|
---|
396 | * ACCEL_BW_1000HZ, 1LSB = 0.5ms
|
---|
397 | *Return Parameter: None
|
---|
398 | *******************************************************************************************/
|
---|
399 | void NAxisMotion::enableAnyMotion(uint8_t threshold, uint8_t duration)
|
---|
400 | {
|
---|
401 | BNO055_RETURN_FUNCTION_TYPE comRes = BNO055_ZERO_U8X; //Holds the communication results
|
---|
402 | comRes = bno055_set_accel_any_motion_thres(threshold);
|
---|
403 | comRes = bno055_set_accel_any_motion_durn(duration);
|
---|
404 | comRes = bno055_set_intr_accel_any_motion(ENABLE);
|
---|
405 | comRes = bno055_set_intr_mask_accel_any_motion(ENABLE);
|
---|
406 | }
|
---|
407 |
|
---|
408 | /*******************************************************************************************
|
---|
409 | *Description: This function is used to disable the any motion interrupt
|
---|
410 | *Input Parameters: None
|
---|
411 | *Return Parameter: None
|
---|
412 | *******************************************************************************************/
|
---|
413 | void NAxisMotion::disableAnyMotion(void)
|
---|
414 | {
|
---|
415 | BNO055_RETURN_FUNCTION_TYPE comRes = BNO055_ZERO_U8X; //Holds the communication results
|
---|
416 | comRes = bno055_set_intr_accel_any_motion(DISABLE);
|
---|
417 | comRes = bno055_set_intr_mask_accel_any_motion(DISABLE);
|
---|
418 | }
|
---|
419 |
|
---|
420 | /*******************************************************************************************
|
---|
421 | *Description: This function is used to enable the slow or no motion interrupt based on the
|
---|
422 | * accelerometer
|
---|
423 | *Input Parameters:
|
---|
424 | * uint8_t threshold: The threshold that triggers the no motion interrupt
|
---|
425 | * The threshold should be entered as an integer. The corresponding value of
|
---|
426 | * the threshold depends on the range that has been set on the
|
---|
427 | * accelerometer. Below is a table showing the value of 1LSB in
|
---|
428 | * corresponding units.
|
---|
429 | * Resolution:
|
---|
430 | * ACCEL_RANGE_2G, 1LSB = 3.91mg = ~0.03835m/s2
|
---|
431 | * ACCEL_RANGE_4G, 1LSB = 7.81mg = ~0.07661m/s2
|
---|
432 | * ACCEL_RANGE_8G, 1LSB = 15.6mg = ~0.15303m/s2
|
---|
433 | * ACCEL_RANGE_16G, 1LSB = 31.3mg = ~0.30705m/s2
|
---|
434 | * Maximum:
|
---|
435 | * ACCEL_RANGE_2G, 1LSB = 996mg = ~9.77076m/s2,
|
---|
436 | * ACCEL_RANGE_4G, 1LSB = 1.99g = ~19.5219m/s2
|
---|
437 | * ACCEL_RANGE_8G, 1LSB = 3.98g = ~39.0438m/s2
|
---|
438 | * ACCEL_RANGE_16G, 1LSB = 7.97g = ~97.1857m/s2
|
---|
439 | * uint8_t duration: The duration for which the desired threshold should be surpassed
|
---|
440 | * The time difference between the successive acceleration signals depends
|
---|
441 | * on the selected bandwidth and equates to 1/(2*bandwidth).
|
---|
442 | * In order to suppress false triggers, the interrupt is only generated (cleared)
|
---|
443 | * if a certain number N of consecutive slope data points is larger (smaller)
|
---|
444 | * than the slope 'threshold'. This number is set by the 'duration'.
|
---|
445 | * It is N = duration + 1.
|
---|
446 | * Resolution:
|
---|
447 | * ACCEL_BW_7_81HZ, 1LSB = 64ms
|
---|
448 | * ACCEL_BW_15_63HZ, 1LSB = 32ms
|
---|
449 | * ACCEL_BW_31_25HZ, 1LSB = 16ms
|
---|
450 | * ACCEL_BW_62_5HZ, 1LSB = 8ms
|
---|
451 | * ACCEL_BW_125HZ, 1LSB = 4ms
|
---|
452 | * ACCEL_BW_250HZ, 1LSB = 2ms
|
---|
453 | * ACCEL_BW_500HZ, 1LSB = 1ms
|
---|
454 | * ACCEL_BW_1000HZ, 1LSB = 0.5ms
|
---|
455 | * bool motion: To trigger either a Slow motion or a No motion interrupt
|
---|
456 | * ---------------------------------------------------
|
---|
457 | * Constant Definition Constant Value Comment
|
---|
458 | * ---------------------------------------------------
|
---|
459 | * NO_MOTION 1 Enables the no motion interrupt
|
---|
460 | * SLOW_MOTION 0 Enables the slow motion interrupt
|
---|
461 | *Return Parameter: None
|
---|
462 | *******************************************************************************************/
|
---|
463 | void NAxisMotion::enableSlowNoMotion(uint8_t threshold, uint8_t duration, bool motion)
|
---|
464 | {
|
---|
465 | BNO055_RETURN_FUNCTION_TYPE comRes = BNO055_ZERO_U8X; //Holds the communication results
|
---|
466 | comRes = bno055_set_accel_slow_no_motion_enable(motion);
|
---|
467 | comRes = bno055_set_accel_slow_no_motion_thres(threshold);
|
---|
468 | comRes = bno055_set_accel_slow_no_motion_durn(duration);
|
---|
469 | comRes = bno055_set_intr_accel_no_motion(ENABLE);
|
---|
470 | comRes = bno055_set_intr_mask_accel_no_motion(ENABLE);
|
---|
471 | }
|
---|
472 |
|
---|
473 | /*******************************************************************************************
|
---|
474 | *Description: This function is used to disable the slow or no motion interrupt
|
---|
475 | *Input Parameters: None
|
---|
476 | *Return Parameter: None
|
---|
477 | *******************************************************************************************/
|
---|
478 | void NAxisMotion::disableSlowNoMotion(void)
|
---|
479 | {
|
---|
480 | BNO055_RETURN_FUNCTION_TYPE comRes = BNO055_ZERO_U8X; //Holds the communication results
|
---|
481 | comRes = bno055_set_intr_accel_no_motion(DISABLE);
|
---|
482 | comRes = bno055_set_intr_mask_accel_any_motion(DISABLE);
|
---|
483 | }
|
---|
484 |
|
---|
485 | /*******************************************************************************************
|
---|
486 | *Description: This function is used to change the mode of updating the local data
|
---|
487 | *Input Parameters: None
|
---|
488 | *Return Parameter: None
|
---|
489 | *******************************************************************************************/
|
---|
490 | void NAxisMotion::setUpdateMode(bool updateMode)
|
---|
491 | {
|
---|
492 | dataUpdateMode = updateMode;
|
---|
493 | }
|
---|
494 |
|
---|
495 | /*******************************************************************************************
|
---|
496 | *Description: This function is used to return the x-axis of the accelerometer data
|
---|
497 | *Input Parameters: None
|
---|
498 | *Return Parameter:
|
---|
499 | * float: X-axis accelerometer data in m/s2
|
---|
500 | *******************************************************************************************/
|
---|
501 | float NAxisMotion::readAccelX(void)
|
---|
502 | {
|
---|
503 | if (dataUpdateMode == AUTO)
|
---|
504 | {
|
---|
505 | updateAccel();
|
---|
506 | }
|
---|
507 | return accelData.x;
|
---|
508 | }
|
---|
509 |
|
---|
510 | /*******************************************************************************************
|
---|
511 | *Description: This function is used to return the y-axis of the accelerometer data
|
---|
512 | *Input Parameters: None
|
---|
513 | *Return Parameter:
|
---|
514 | * float: Y-axis accelerometer data in m/s2
|
---|
515 | *******************************************************************************************/
|
---|
516 | float NAxisMotion::readAccelY(void)
|
---|
517 | {
|
---|
518 | if (dataUpdateMode == AUTO)
|
---|
519 | {
|
---|
520 | updateAccel();
|
---|
521 | }
|
---|
522 | return accelData.y;
|
---|
523 | }
|
---|
524 |
|
---|
525 | /*******************************************************************************************
|
---|
526 | *Description: This function is used to return the z-axis of the accelerometer data
|
---|
527 | *Input Parameters: None
|
---|
528 | *Return Parameter:
|
---|
529 | * float: Z-axis accelerometer data in m/s2
|
---|
530 | *******************************************************************************************/
|
---|
531 | float NAxisMotion::readAccelZ(void)
|
---|
532 | {
|
---|
533 | if (dataUpdateMode == AUTO)
|
---|
534 | {
|
---|
535 | updateAccel();
|
---|
536 | }
|
---|
537 | return accelData.z;
|
---|
538 | }
|
---|
539 |
|
---|
540 | /*******************************************************************************************
|
---|
541 | *Description: This function is used to return the x-axis of the gyroscope data
|
---|
542 | *Input Parameters: None
|
---|
543 | *Return Parameter:
|
---|
544 | * float: X-axis gyroscope data in deg/s
|
---|
545 | *******************************************************************************************/
|
---|
546 | float NAxisMotion::readGyroX(void)
|
---|
547 | {
|
---|
548 | if (dataUpdateMode == AUTO)
|
---|
549 | {
|
---|
550 | updateGyro();
|
---|
551 | }
|
---|
552 | return gyroData.x;
|
---|
553 | }
|
---|
554 |
|
---|
555 | /*******************************************************************************************
|
---|
556 | *Description: This function is used to return the y-axis of the gyroscope data
|
---|
557 | *Input Parameters: None
|
---|
558 | *Return Parameter:
|
---|
559 | * float: Y-axis gyroscope data in deg/s
|
---|
560 | *******************************************************************************************/
|
---|
561 | float NAxisMotion::readGyroY(void)
|
---|
562 | {
|
---|
563 | if (dataUpdateMode == AUTO)
|
---|
564 | {
|
---|
565 | updateGyro();
|
---|
566 | }
|
---|
567 | return gyroData.y;
|
---|
568 | }
|
---|
569 |
|
---|
570 | /*******************************************************************************************
|
---|
571 | *Description: This function is used to return the z-axis of the gyroscope data
|
---|
572 | *Input Parameters: None
|
---|
573 | *Return Parameter:
|
---|
574 | * float: Z-axis gyroscope data in deg/s
|
---|
575 | *******************************************************************************************/
|
---|
576 | float NAxisMotion::readGyroZ(void)
|
---|
577 | {
|
---|
578 | if (dataUpdateMode == AUTO)
|
---|
579 | {
|
---|
580 | updateGyro();
|
---|
581 | }
|
---|
582 | return gyroData.z;
|
---|
583 | }
|
---|
584 |
|
---|
585 | /*******************************************************************************************
|
---|
586 | *Description: This function is used to return the x-axis of the magnetometer data
|
---|
587 | *Input Parameters: None
|
---|
588 | *Return Parameter:
|
---|
589 | * float: X-axis magnetometer data in µT
|
---|
590 | *******************************************************************************************/
|
---|
591 | float NAxisMotion::readMagX(void)
|
---|
592 | {
|
---|
593 | if (dataUpdateMode == AUTO)
|
---|
594 | {
|
---|
595 | updateMag();
|
---|
596 | }
|
---|
597 | return magData.x;
|
---|
598 | }
|
---|
599 |
|
---|
600 | /*******************************************************************************************
|
---|
601 | *Description: This function is used to return the y-axis of the magnetometer data
|
---|
602 | *Input Parameters: None
|
---|
603 | *Return Parameter:
|
---|
604 | * float: Y-axis magnetometer data in µT
|
---|
605 | *******************************************************************************************/
|
---|
606 | float NAxisMotion::readMagY(void)
|
---|
607 | {
|
---|
608 | if (dataUpdateMode == AUTO)
|
---|
609 | {
|
---|
610 | updateMag();
|
---|
611 | }
|
---|
612 | return magData.y;
|
---|
613 | }
|
---|
614 |
|
---|
615 | /*******************************************************************************************
|
---|
616 | *Description: This function is used to return the z-axis of the magnetometer data
|
---|
617 | *Input Parameters: None
|
---|
618 | *Return Parameter:
|
---|
619 | * float: Z-axis magnetometer data in µT
|
---|
620 | *******************************************************************************************/
|
---|
621 | float NAxisMotion::readMagZ(void)
|
---|
622 | {
|
---|
623 | if (dataUpdateMode == AUTO)
|
---|
624 | {
|
---|
625 | updateMag();
|
---|
626 | }
|
---|
627 | return magData.z;
|
---|
628 | }
|
---|
629 |
|
---|
630 | /*******************************************************************************************
|
---|
631 | *Description: This function is used to return the w-axis of the quaternion data
|
---|
632 | *Input Parameters: None
|
---|
633 | *Return Parameter:
|
---|
634 | * int16_t: W-axis quaternion data multiplied by 1000 (for 3 decimal places accuracy)
|
---|
635 | *******************************************************************************************/
|
---|
636 | int16_t NAxisMotion::readQuatW(void)
|
---|
637 | {
|
---|
638 | if (dataUpdateMode == AUTO)
|
---|
639 | {
|
---|
640 | updateQuat();
|
---|
641 | }
|
---|
642 | return quatData.w;
|
---|
643 | }
|
---|
644 |
|
---|
645 | /*******************************************************************************************
|
---|
646 | *Description: This function is used to return the x-axis of the quaternion data
|
---|
647 | *Input Parameters: None
|
---|
648 | *Return Parameter:
|
---|
649 | * int16_t: X-axis quaternion data multiplied by 1000 (for 3 decimal places accuracy)
|
---|
650 | *******************************************************************************************/
|
---|
651 | int16_t NAxisMotion::readQuatX(void)
|
---|
652 | {
|
---|
653 | if (dataUpdateMode == AUTO)
|
---|
654 | {
|
---|
655 | updateQuat();
|
---|
656 | }
|
---|
657 | return quatData.x;
|
---|
658 | }
|
---|
659 |
|
---|
660 | /*******************************************************************************************
|
---|
661 | *Description: This function is used to return the y-axis of the quaternion data
|
---|
662 | *Input Parameters: None
|
---|
663 | *Return Parameter:
|
---|
664 | * int16_t: Y-axis quaternion data multiplied by 1000 (for 3 decimal places accuracy)
|
---|
665 | *******************************************************************************************/
|
---|
666 | int16_t NAxisMotion::readQuatY(void)
|
---|
667 | {
|
---|
668 | if (dataUpdateMode == AUTO)
|
---|
669 | {
|
---|
670 | updateQuat();
|
---|
671 | }
|
---|
672 | return quatData.y;
|
---|
673 | }
|
---|
674 |
|
---|
675 | /*******************************************************************************************
|
---|
676 | *Description: This function is used to return the z-axis of the quaternion data
|
---|
677 | *Input Parameters: None
|
---|
678 | *Return Parameter:
|
---|
679 | * int16_t: Z-axis quaternion data multiplied by 1000 (for 3 decimal places accuracy)
|
---|
680 | *******************************************************************************************/
|
---|
681 | int16_t NAxisMotion::readQuatZ(void)
|
---|
682 | {
|
---|
683 | if (dataUpdateMode == AUTO)
|
---|
684 | {
|
---|
685 | updateQuat();
|
---|
686 | }
|
---|
687 | return quatData.z;
|
---|
688 | }
|
---|
689 |
|
---|
690 | /*******************************************************************************************
|
---|
691 | *Description: This function is used to return the heading(yaw) of the euler data
|
---|
692 | *Input Parameters: None
|
---|
693 | *Return Parameter:
|
---|
694 | * float: Heading of the euler data
|
---|
695 | *******************************************************************************************/
|
---|
696 | float NAxisMotion::readEulerHeading(void)
|
---|
697 | {
|
---|
698 | if (dataUpdateMode == AUTO)
|
---|
699 | {
|
---|
700 | updateEuler();
|
---|
701 | }
|
---|
702 | return eulerData.h;
|
---|
703 | }
|
---|
704 |
|
---|
705 | /*******************************************************************************************
|
---|
706 | *Description: This function is used to return the roll of the euler data
|
---|
707 | *Input Parameters: None
|
---|
708 | *Return Parameter:
|
---|
709 | * float: Roll of the euler data
|
---|
710 | *******************************************************************************************/
|
---|
711 | float NAxisMotion::readEulerRoll(void)
|
---|
712 | {
|
---|
713 | if (dataUpdateMode == AUTO)
|
---|
714 | {
|
---|
715 | updateEuler();
|
---|
716 | }
|
---|
717 | return eulerData.r;
|
---|
718 | }
|
---|
719 |
|
---|
720 | /*******************************************************************************************
|
---|
721 | *Description: This function is used to return the pitch of the euler data
|
---|
722 | *Input Parameters: None
|
---|
723 | *Return Parameter:
|
---|
724 | * float: Pitch of the euler data
|
---|
725 | *******************************************************************************************/
|
---|
726 | float NAxisMotion::readEulerPitch(void)
|
---|
727 | {
|
---|
728 | if (dataUpdateMode == AUTO)
|
---|
729 | {
|
---|
730 | updateEuler();
|
---|
731 | }
|
---|
732 | return eulerData.p;
|
---|
733 | }
|
---|
734 |
|
---|
735 | /*******************************************************************************************
|
---|
736 | *Description: This function is used to return the x-axis of the linear acceleration data
|
---|
737 | * (accelerometer data without the gravity vector)
|
---|
738 | *Input Parameters: None
|
---|
739 | *Return Parameter:
|
---|
740 | * float: X-axis Linear Acceleration data in m/s2
|
---|
741 | *******************************************************************************************/
|
---|
742 | float NAxisMotion::readLinearAccelX(void)
|
---|
743 | {
|
---|
744 | if (dataUpdateMode == AUTO)
|
---|
745 | {
|
---|
746 | updateLinearAccel();
|
---|
747 | }
|
---|
748 | return linearAccelData.x;
|
---|
749 | }
|
---|
750 |
|
---|
751 | /*******************************************************************************************
|
---|
752 | *Description: This function is used to return the y-axis of the linear acceleration data
|
---|
753 | * (accelerometer data without the gravity vector)
|
---|
754 | *Input Parameters: None
|
---|
755 | *Return Parameter:
|
---|
756 | * float: Y-axis Linear Acceleration data in m/s2
|
---|
757 | *******************************************************************************************/
|
---|
758 | float NAxisMotion::readLinearAccelY(void)
|
---|
759 | {
|
---|
760 | if (dataUpdateMode == AUTO)
|
---|
761 | {
|
---|
762 | updateLinearAccel();
|
---|
763 | }
|
---|
764 | return linearAccelData.y;
|
---|
765 | }
|
---|
766 |
|
---|
767 | /*******************************************************************************************
|
---|
768 | *Description: This function is used to return the z-axis of the linear acceleration data
|
---|
769 | * (accelerometer data without the gravity vector)
|
---|
770 | *Input Parameters: None
|
---|
771 | *Return Parameter:
|
---|
772 | * float: Z-axis Linear Acceleration data in m/s2
|
---|
773 | *******************************************************************************************/
|
---|
774 | float NAxisMotion::readLinearAccelZ(void)
|
---|
775 | {
|
---|
776 | if (dataUpdateMode == AUTO)
|
---|
777 | {
|
---|
778 | updateLinearAccel();
|
---|
779 | }
|
---|
780 | return linearAccelData.z;
|
---|
781 | }
|
---|
782 |
|
---|
783 | /*******************************************************************************************
|
---|
784 | *Description: This function is used to return the x-axis of the gravity acceleration data
|
---|
785 | * (accelerometer data with only the gravity vector)
|
---|
786 | *Input Parameters: None
|
---|
787 | *Return Parameter:
|
---|
788 | * float: X-axis Gravity Acceleration data in m/s2
|
---|
789 | *******************************************************************************************/
|
---|
790 | float NAxisMotion::readGravAccelX(void)
|
---|
791 | {
|
---|
792 | if (dataUpdateMode == AUTO)
|
---|
793 | {
|
---|
794 | updateGravAccel();
|
---|
795 | }
|
---|
796 | return gravAccelData.x;
|
---|
797 | }
|
---|
798 |
|
---|
799 | /*******************************************************************************************
|
---|
800 | *Description: This function is used to return the y-axis of the gravity acceleration data
|
---|
801 | * (accelerometer data with only the gravity vector)
|
---|
802 | *Input Parameters: None
|
---|
803 | *Return Parameter:
|
---|
804 | * float: Y-axis Gravity Acceleration data in m/s2
|
---|
805 | *******************************************************************************************/
|
---|
806 | float NAxisMotion::readGravAccelY(void)
|
---|
807 | {
|
---|
808 | if (dataUpdateMode == AUTO)
|
---|
809 | {
|
---|
810 | updateGravAccel();
|
---|
811 | }
|
---|
812 | return gravAccelData.y;
|
---|
813 | }
|
---|
814 |
|
---|
815 | /*******************************************************************************************
|
---|
816 | *Description: This function is used to return the z-axis of the gravity acceleration data
|
---|
817 | * (accelerometer data with only the gravity vector)
|
---|
818 | *Input Parameters: None
|
---|
819 | *Return Parameter:
|
---|
820 | * float: Z-axis Gravity Acceleration data in m/s2
|
---|
821 | *******************************************************************************************/
|
---|
822 | float NAxisMotion::readGravAccelZ(void)
|
---|
823 | {
|
---|
824 | if (dataUpdateMode == AUTO)
|
---|
825 | {
|
---|
826 | updateGravAccel();
|
---|
827 | }
|
---|
828 | return gravAccelData.z;
|
---|
829 | }
|
---|
830 |
|
---|
831 | /*******************************************************************************************
|
---|
832 | *Description: This function is used to return the accelerometer calibration status
|
---|
833 | *Input Parameters: None
|
---|
834 | *Return Parameter:
|
---|
835 | * uint8_t: Accelerometer calibration status, 0-3 (0 - low, 3 - high)
|
---|
836 | *******************************************************************************************/
|
---|
837 | uint8_t NAxisMotion::readAccelCalibStatus(void)
|
---|
838 | {
|
---|
839 | if (dataUpdateMode == AUTO)
|
---|
840 | {
|
---|
841 | updateCalibStatus();
|
---|
842 | }
|
---|
843 | return calibStatus.accel;
|
---|
844 | }
|
---|
845 |
|
---|
846 | /*******************************************************************************************
|
---|
847 | *Description: This function is used to return the gyroscope calibration status
|
---|
848 | *Input Parameters: None
|
---|
849 | *Return Parameter:
|
---|
850 | * uint8_t: Gyroscope calibration status, 0-3 (0 - low, 3 - high)
|
---|
851 | *******************************************************************************************/
|
---|
852 | uint8_t NAxisMotion::readGyroCalibStatus(void)
|
---|
853 | {
|
---|
854 | if (dataUpdateMode == AUTO)
|
---|
855 | {
|
---|
856 | updateCalibStatus();
|
---|
857 | }
|
---|
858 | return calibStatus.gyro;
|
---|
859 | }
|
---|
860 |
|
---|
861 | /*******************************************************************************************
|
---|
862 | *Description: This function is used to return the magnetometer calibration status
|
---|
863 | *Input Parameters: None
|
---|
864 | *Return Parameter:
|
---|
865 | * uint8_t: Magnetometer calibration status, 0-3 (0 - low, 3 - high)
|
---|
866 | *******************************************************************************************/
|
---|
867 | uint8_t NAxisMotion::readMagCalibStatus(void)
|
---|
868 | {
|
---|
869 | if (dataUpdateMode == AUTO)
|
---|
870 | {
|
---|
871 | updateCalibStatus();
|
---|
872 | }
|
---|
873 | return calibStatus.mag;
|
---|
874 | }
|
---|
875 |
|
---|
876 | /*******************************************************************************************
|
---|
877 | *Description: This function is used to return the system calibration status
|
---|
878 | *Input Parameters: None
|
---|
879 | *Return Parameter:
|
---|
880 | * uint8_t: System calibration status, 0-3 (0 - low, 3 - high)
|
---|
881 | *******************************************************************************************/
|
---|
882 | uint8_t NAxisMotion::readSystemCalibStatus(void)
|
---|
883 | {
|
---|
884 | if (dataUpdateMode == AUTO)
|
---|
885 | {
|
---|
886 | updateCalibStatus();
|
---|
887 | }
|
---|
888 | return calibStatus.system;
|
---|
889 | }
|
---|
890 |
|
---|
891 | /*******************************************************************************************
|
---|
892 | *Description: This function is used to return the accelerometer range
|
---|
893 | *Input Parameters: None
|
---|
894 | *Return Parameter:
|
---|
895 | * uint8_t range: Range of the accelerometer
|
---|
896 | * --------------------------------------
|
---|
897 | * Constant Definition Constant Value
|
---|
898 | * --------------------------------------
|
---|
899 | * ACCEL_RANGE_2G 0X00
|
---|
900 | * ACCEL_RANGE_4G 0X01
|
---|
901 | * ACCEL_RANGE_8G 0X02
|
---|
902 | * ACCEL_RANGE_16G 0X03
|
---|
903 | *******************************************************************************************/
|
---|
904 | uint8_t NAxisMotion::readAccelRange(void)
|
---|
905 | {
|
---|
906 | if (dataUpdateMode == AUTO)
|
---|
907 | {
|
---|
908 | updateAccelConfig();
|
---|
909 | }
|
---|
910 | return accelStatus.range;
|
---|
911 | }
|
---|
912 |
|
---|
913 | /*******************************************************************************************
|
---|
914 | *Description: This function is used to return the accelerometer bandwidth
|
---|
915 | *Input Parameters: None
|
---|
916 | *Return Parameter:
|
---|
917 | * uint8_t bandwidth: Bandwidth of the accelerometer
|
---|
918 | * --------------------------------------
|
---|
919 | * Constant Definition Constant Value
|
---|
920 | * --------------------------------------
|
---|
921 | * ACCEL_BW_7_81HZ 0x00
|
---|
922 | * ACCEL_BW_15_63HZ 0x01
|
---|
923 | * ACCEL_BW_31_25HZ 0x02
|
---|
924 | * ACCEL_BW_62_5HZ 0X03
|
---|
925 | * ACCEL_BW_125HZ 0X04
|
---|
926 | * ACCEL_BW_250HZ 0X05
|
---|
927 | * ACCEL_BW_500HZ 0X06
|
---|
928 | * ACCEL_BW_1000HZ 0X07
|
---|
929 | *******************************************************************************************/
|
---|
930 | uint8_t NAxisMotion::readAccelBandwidth(void)
|
---|
931 | {
|
---|
932 | if (dataUpdateMode == AUTO)
|
---|
933 | {
|
---|
934 | updateAccelConfig();
|
---|
935 | }
|
---|
936 | return accelStatus.bandwidth;
|
---|
937 | }
|
---|
938 |
|
---|
939 | /*******************************************************************************************
|
---|
940 | *Description: This function is used to return the accelerometer power mode
|
---|
941 | *Input Parameters: None
|
---|
942 | *Return Parameter:
|
---|
943 | * uint8_t powerMode: Power mode of the accelerometer
|
---|
944 | * --------------------------------------
|
---|
945 | * Constant Definition Constant Value
|
---|
946 | * --------------------------------------
|
---|
947 | * ACCEL_NORMAL 0X00
|
---|
948 | * ACCEL_SUSPEND 0X01
|
---|
949 | * ACCEL_LOWPOWER_1 0X02
|
---|
950 | * ACCEL_STANDBY 0X03
|
---|
951 | * ACCEL_LOWPOWER_2 0X04
|
---|
952 | * ACCEL_DEEPSUSPEND 0X05
|
---|
953 | *******************************************************************************************/
|
---|
954 | uint8_t NAxisMotion::readAccelPowerMode(void)
|
---|
955 | {
|
---|
956 | if (dataUpdateMode == AUTO)
|
---|
957 | {
|
---|
958 | updateAccelConfig();
|
---|
959 | }
|
---|
960 | return accelStatus.powerMode;
|
---|
961 | }
|
---|
962 |
|
---|
963 |
|
---|
964 | /******************** Bridge Functions for the Sensor API to control the Arduino Hardware******************************************/
|
---|
965 | signed char BNO055_I2C_bus_read(unsigned char dev_addr,unsigned char reg_addr, unsigned char *reg_data, unsigned char cnt)
|
---|
966 | {
|
---|
967 | BNO055_RETURN_FUNCTION_TYPE comres = BNO055_ZERO_U8X;
|
---|
968 | I2C.beginTransmission(dev_addr); //Start of transmission
|
---|
969 | I2C.write(reg_addr); //Desired start register
|
---|
970 | comres = I2C.endTransmission(); //Stop of transmission
|
---|
971 | delayMicroseconds(150); //Caution Delay
|
---|
972 | I2C.requestFrom(dev_addr, cnt); //Request data
|
---|
973 | while(I2C.available()) //The slave device may send less than requested (burst read)
|
---|
974 | {
|
---|
975 | *reg_data = I2C.read(); //Receive a byte
|
---|
976 | reg_data++; //Increment pointer
|
---|
977 | }
|
---|
978 | return comres;
|
---|
979 | }
|
---|
980 |
|
---|
981 |
|
---|
982 | signed char BNO055_I2C_bus_write(unsigned char dev_addr,unsigned char reg_addr, unsigned char *reg_data, unsigned char cnt)
|
---|
983 | {
|
---|
984 | BNO055_RETURN_FUNCTION_TYPE comres = BNO055_ZERO_U8X;
|
---|
985 | I2C.beginTransmission(dev_addr); //Start of transmission
|
---|
986 | I2C.write(reg_addr); //Desired start register
|
---|
987 | for(unsigned char index = 0; index < cnt; index++) //Note that the BNO055 supports burst write
|
---|
988 | {
|
---|
989 | I2C.write(*reg_data); //Write the data
|
---|
990 | reg_data++; //Increment pointer
|
---|
991 | }
|
---|
992 | comres = I2C.endTransmission(); //Stop of transmission
|
---|
993 | delayMicroseconds(150); //Caution Delay
|
---|
994 | return comres;
|
---|
995 | }
|
---|
996 |
|
---|
997 | void _delay(u_32 period)
|
---|
998 | {
|
---|
999 | delay(period);
|
---|
1000 | }
|
---|