27 |
27 |
* MIT license, all text above must be included in any redistribution
|
28 |
28 |
*/
|
29 |
29 |
|
30 |
|
#if ARDUINO >= 100
|
31 |
30 |
#include "Arduino.h"
|
32 |
|
#else
|
33 |
|
#include "WProgram.h"
|
34 |
|
#endif
|
35 |
31 |
|
36 |
32 |
#include <limits.h>
|
37 |
33 |
#include <math.h>
|
... | ... | |
40 |
36 |
|
41 |
37 |
/*!
|
42 |
38 |
* @brief Instantiates a new Adafruit_BNO055 class
|
43 |
|
* @param sensorID
|
44 |
|
* @param address
|
45 |
39 |
*/
|
46 |
|
Adafruit_BNO055::Adafruit_BNO055(int32_t sensorID, uint8_t address) {
|
47 |
|
_sensorID = sensorID;
|
48 |
|
_address = address;
|
|
40 |
Adafruit_BNO055::Adafruit_BNO055() {}
|
|
41 |
|
|
42 |
/*!
|
|
43 |
* @brief Sets up the HW
|
|
44 |
* @param mode
|
|
45 |
* mode values
|
|
46 |
* [OPERATION_MODE_CONFIG,
|
|
47 |
* OPERATION_MODE_ACCONLY,
|
|
48 |
* OPERATION_MODE_MAGONLY,
|
|
49 |
* OPERATION_MODE_GYRONLY,
|
|
50 |
* OPERATION_MODE_ACCMAG,
|
|
51 |
* OPERATION_MODE_ACCGYRO,
|
|
52 |
* OPERATION_MODE_MAGGYRO,
|
|
53 |
* OPERATION_MODE_AMG,
|
|
54 |
* OPERATION_MODE_IMUPLUS,
|
|
55 |
* OPERATION_MODE_COMPASS,
|
|
56 |
* OPERATION_MODE_M4G,
|
|
57 |
* OPERATION_MODE_NDOF_FMC_OFF,
|
|
58 |
* OPERATION_MODE_NDOF]
|
|
59 |
* @param *theWire
|
|
60 |
* Wire object
|
|
61 |
* @return true if process is successful
|
|
62 |
*/
|
|
63 |
bool Adafruit_BNO055::begin() {
|
|
64 |
_wire = &Wire;
|
|
65 |
#if defined(ARDUINO_SAMD_ZERO) && !(ARDUINO_SAMD_FEATHER_M0)
|
|
66 |
#error \
|
|
67 |
"On an arduino Zero, BNO055's ADR pin must be high. Fix that, then delete this line."
|
|
68 |
_address = BNO055_ADDRESS_B;
|
|
69 |
#else
|
|
70 |
_address = BNO055_ADDRESS_A;
|
|
71 |
#endif
|
|
72 |
|
|
73 |
return init(OPERATION_MODE_NDOF);
|
49 |
74 |
}
|
50 |
75 |
|
51 |
76 |
/*!
|
52 |
77 |
* @brief Sets up the HW
|
53 |
78 |
* @param mode
|
54 |
|
* @return true if process is sucessfull
|
|
79 |
* mode values
|
|
80 |
* [OPERATION_MODE_CONFIG,
|
|
81 |
* OPERATION_MODE_ACCONLY,
|
|
82 |
* OPERATION_MODE_MAGONLY,
|
|
83 |
* OPERATION_MODE_GYRONLY,
|
|
84 |
* OPERATION_MODE_ACCMAG,
|
|
85 |
* OPERATION_MODE_ACCGYRO,
|
|
86 |
* OPERATION_MODE_MAGGYRO,
|
|
87 |
* OPERATION_MODE_AMG,
|
|
88 |
* OPERATION_MODE_IMUPLUS,
|
|
89 |
* OPERATION_MODE_COMPASS,
|
|
90 |
* OPERATION_MODE_M4G,
|
|
91 |
* OPERATION_MODE_NDOF_FMC_OFF,
|
|
92 |
* OPERATION_MODE_NDOF]
|
|
93 |
* @param *theWire
|
|
94 |
* Wire object
|
|
95 |
* @return true if process is successful
|
55 |
96 |
*/
|
56 |
|
bool Adafruit_BNO055::begin(adafruit_bno055_opmode_t mode) {
|
|
97 |
bool Adafruit_BNO055::begin(adafruit_bno055_opmode_t mode, uint8_t address,
|
|
98 |
TwoWire *theWire) {
|
|
99 |
_wire = theWire;
|
|
100 |
_address = address;
|
|
101 |
|
|
102 |
return init(mode);
|
|
103 |
}
|
|
104 |
|
|
105 |
bool Adafruit_BNO055::init(adafruit_bno055_opmode_t mode) {
|
57 |
106 |
/* Enable I2C */
|
58 |
|
Wire.begin();
|
|
107 |
_wire->begin();
|
59 |
108 |
|
60 |
109 |
/* BNO055 clock stretches for 500us or more! */
|
61 |
110 |
#ifdef ESP8266
|
62 |
111 |
/* Allow for 1000us of clock stretching */
|
|
112 |
<<<<<<< HEAD
|
|
113 |
_wire->setClockStretchLimit(1000);
|
|
114 |
=======
|
63 |
115 |
Wire.setClockStretchLimit(1000);
|
|
116 |
>>>>>>> 75f03d2e1fd440e7febc0de8c47a52bab09c51b0
|
64 |
117 |
#endif
|
65 |
118 |
|
66 |
119 |
/* Make sure we have the right device */
|
... | ... | |
113 |
166 |
/*!
|
114 |
167 |
* @brief Puts the chip in the specified operating mode
|
115 |
168 |
* @param mode
|
|
169 |
* mode values
|
|
170 |
* [OPERATION_MODE_CONFIG,
|
|
171 |
* OPERATION_MODE_ACCONLY,
|
|
172 |
* OPERATION_MODE_MAGONLY,
|
|
173 |
* OPERATION_MODE_GYRONLY,
|
|
174 |
* OPERATION_MODE_ACCMAG,
|
|
175 |
* OPERATION_MODE_ACCGYRO,
|
|
176 |
* OPERATION_MODE_MAGGYRO,
|
|
177 |
* OPERATION_MODE_AMG,
|
|
178 |
* OPERATION_MODE_IMUPLUS,
|
|
179 |
* OPERATION_MODE_COMPASS,
|
|
180 |
* OPERATION_MODE_M4G,
|
|
181 |
* OPERATION_MODE_NDOF_FMC_OFF,
|
|
182 |
* OPERATION_MODE_NDOF]
|
116 |
183 |
*/
|
117 |
184 |
void Adafruit_BNO055::setMode(adafruit_bno055_opmode_t mode) {
|
118 |
185 |
_mode = mode;
|
... | ... | |
123 |
190 |
/*!
|
124 |
191 |
* @brief Changes the chip's axis remap
|
125 |
192 |
* @param remapcode
|
|
193 |
* remap code possible values
|
|
194 |
* [REMAP_CONFIG_P0
|
|
195 |
* REMAP_CONFIG_P1 (default)
|
|
196 |
* REMAP_CONFIG_P2
|
|
197 |
* REMAP_CONFIG_P3
|
|
198 |
* REMAP_CONFIG_P4
|
|
199 |
* REMAP_CONFIG_P5
|
|
200 |
* REMAP_CONFIG_P6
|
|
201 |
* REMAP_CONFIG_P7]
|
126 |
202 |
*/
|
127 |
203 |
void Adafruit_BNO055::setAxisRemap(
|
128 |
204 |
adafruit_bno055_axis_remap_config_t remapcode) {
|
... | ... | |
140 |
216 |
/*!
|
141 |
217 |
* @brief Changes the chip's axis signs
|
142 |
218 |
* @param remapsign
|
|
219 |
* remap sign possible values
|
|
220 |
* [REMAP_SIGN_P0
|
|
221 |
* REMAP_SIGN_P1 (default)
|
|
222 |
* REMAP_SIGN_P2
|
|
223 |
* REMAP_SIGN_P3
|
|
224 |
* REMAP_SIGN_P4
|
|
225 |
* REMAP_SIGN_P5
|
|
226 |
* REMAP_SIGN_P6
|
|
227 |
* REMAP_SIGN_P7]
|
143 |
228 |
*/
|
144 |
229 |
void Adafruit_BNO055::setAxisSign(adafruit_bno055_axis_remap_sign_t remapsign) {
|
145 |
230 |
adafruit_bno055_opmode_t modeback = _mode;
|
... | ... | |
155 |
240 |
|
156 |
241 |
/*!
|
157 |
242 |
* @brief Use the external 32.768KHz crystal
|
158 |
|
* @param usextal boolean
|
|
243 |
* @param usextal
|
|
244 |
* use external crystal boolean
|
159 |
245 |
*/
|
160 |
246 |
void Adafruit_BNO055::setExtCrystalUse(boolean usextal) {
|
161 |
247 |
adafruit_bno055_opmode_t modeback = _mode;
|
... | ... | |
178 |
264 |
/*!
|
179 |
265 |
* @brief Gets the latest system status info
|
180 |
266 |
* @param system_status
|
|
267 |
* system status info
|
181 |
268 |
* @param self_test_result
|
|
269 |
* self test result
|
182 |
270 |
* @param system_error
|
|
271 |
* system error info
|
183 |
272 |
*/
|
184 |
273 |
void Adafruit_BNO055::getSystemStatus(uint8_t *system_status,
|
185 |
274 |
uint8_t *self_test_result,
|
... | ... | |
235 |
324 |
|
236 |
325 |
/*!
|
237 |
326 |
* @brief Gets the chip revision numbers
|
|
327 |
* @param info
|
|
328 |
* revision info
|
238 |
329 |
*/
|
239 |
330 |
void Adafruit_BNO055::getRevInfo(adafruit_bno055_rev_info_t *info) {
|
240 |
331 |
uint8_t a, b;
|
... | ... | |
262 |
353 |
* @brief Gets current calibration state. Each value should be a uint8_t
|
263 |
354 |
* pointer and it will be set to 0 if not calibrated and 3 if
|
264 |
355 |
* fully calibrated.
|
|
356 |
* See section 34.3.54
|
265 |
357 |
* @param sys
|
|
358 |
* Current system calibration status, depends on status of all sensors,
|
|
359 |
* read-only
|
266 |
360 |
* @param gyro
|
|
361 |
* Current calibration status of Gyroscope, read-only
|
267 |
362 |
* @param accel
|
|
363 |
* Current calibration status of Accelerometer, read-only
|
268 |
364 |
* @param mag
|
|
365 |
* Current calibration status of Magnetometer, read-only
|
269 |
366 |
*/
|
270 |
367 |
void Adafruit_BNO055::getCalibration(uint8_t *sys, uint8_t *gyro,
|
271 |
368 |
uint8_t *accel, uint8_t *mag) {
|
... | ... | |
296 |
393 |
/*!
|
297 |
394 |
* @brief Gets a vector reading from the specified source
|
298 |
395 |
* @param vector_type
|
|
396 |
* possible vector type values
|
|
397 |
* [VECTOR_ACCELEROMETER
|
|
398 |
* VECTOR_MAGNETOMETER
|
|
399 |
* VECTOR_GYROSCOPE
|
|
400 |
* VECTOR_EULER
|
|
401 |
* VECTOR_LINEARACCEL
|
|
402 |
* VECTOR_GRAVITY]
|
299 |
403 |
* @return vector from specified source
|
300 |
404 |
*/
|
301 |
405 |
imu::Vector<3> Adafruit_BNO055::getVector(adafruit_vector_type_t vector_type) {
|
... | ... | |
501 |
605 |
|
502 |
606 |
/*!
|
503 |
607 |
* @brief Writes an array of calibration values to the sensor's offset
|
|
608 |
<<<<<<< HEAD
|
|
609 |
* registers
|
|
610 |
=======
|
504 |
611 |
* registers
|
|
612 |
>>>>>>> 75f03d2e1fd440e7febc0de8c47a52bab09c51b0
|
505 |
613 |
* @param calibData
|
|
614 |
* calibration data
|
506 |
615 |
*/
|
507 |
616 |
void Adafruit_BNO055::setSensorOffsets(const uint8_t *calibData) {
|
508 |
617 |
adafruit_bno055_opmode_t lastMode = _mode;
|
... | ... | |
548 |
657 |
/*!
|
549 |
658 |
* @brief Writes to the sensor's offset registers from an offset struct
|
550 |
659 |
* @param offsets_type
|
|
660 |
<<<<<<< HEAD
|
|
661 |
* accel_offset_x = acceleration offset x
|
|
662 |
* accel_offset_y = acceleration offset y
|
|
663 |
* accel_offset_z = acceleration offset z
|
|
664 |
*
|
|
665 |
* mag_offset_x = magnetometer offset x
|
|
666 |
* mag_offset_y = magnetometer offset y
|
|
667 |
* mag_offset_z = magnetometer offset z
|
|
668 |
*
|
|
669 |
* gyro_offset_x = gyroscrope offset x
|
|
670 |
* gyro_offset_y = gyroscrope offset y
|
|
671 |
* gyro_offset_z = gyroscrope offset z
|
|
672 |
*
|
|
673 |
*
|
|
674 |
=======
|
|
675 |
>>>>>>> 75f03d2e1fd440e7febc0de8c47a52bab09c51b0
|
551 |
676 |
*/
|
552 |
677 |
void Adafruit_BNO055::setSensorOffsets(
|
553 |
678 |
const adafruit_bno055_offsets_t &offsets_type) {
|
... | ... | |
606 |
731 |
* @brief Writes an 8 bit value over I2C
|
607 |
732 |
*/
|
608 |
733 |
bool Adafruit_BNO055::write8(adafruit_bno055_reg_t reg, byte value) {
|
609 |
|
Wire.beginTransmission(_address);
|
|
734 |
_wire->beginTransmission(_address);
|
610 |
735 |
#if ARDUINO >= 100
|
611 |
|
Wire.write((uint8_t)reg);
|
612 |
|
Wire.write((uint8_t)value);
|
|
736 |
_wire->write((uint8_t)reg);
|
|
737 |
_wire->write((uint8_t)value);
|
613 |
738 |
#else
|
614 |
|
Wire.send(reg);
|
615 |
|
Wire.send(value);
|
|
739 |
_wire->send(reg);
|
|
740 |
_wire->send(value);
|
616 |
741 |
#endif
|
617 |
|
Wire.endTransmission();
|
|
742 |
_wire->endTransmission();
|
618 |
743 |
|
619 |
744 |
/* ToDo: Check for error! */
|
620 |
745 |
return true;
|
... | ... | |
626 |
751 |
byte Adafruit_BNO055::read8(adafruit_bno055_reg_t reg) {
|
627 |
752 |
byte value = 0;
|
628 |
753 |
|
629 |
|
Wire.beginTransmission(_address);
|
|
754 |
_wire->beginTransmission(_address);
|
630 |
755 |
#if ARDUINO >= 100
|
631 |
|
Wire.write((uint8_t)reg);
|
|
756 |
_wire->write((uint8_t)reg);
|
632 |
757 |
#else
|
633 |
|
Wire.send(reg);
|
|
758 |
_wire->send(reg);
|
634 |
759 |
#endif
|
635 |
|
Wire.endTransmission();
|
636 |
|
Wire.requestFrom(_address, (byte)1);
|
|
760 |
_wire->endTransmission();
|
|
761 |
_wire->requestFrom(_address, (byte)1);
|
637 |
762 |
#if ARDUINO >= 100
|
638 |
|
value = Wire.read();
|
|
763 |
value = _wire->read();
|
639 |
764 |
#else
|
640 |
|
value = Wire.receive();
|
|
765 |
value = _wire->receive();
|
641 |
766 |
#endif
|
642 |
767 |
|
643 |
768 |
return value;
|
... | ... | |
648 |
773 |
*/
|
649 |
774 |
bool Adafruit_BNO055::readLen(adafruit_bno055_reg_t reg, byte *buffer,
|
650 |
775 |
uint8_t len) {
|
651 |
|
Wire.beginTransmission(_address);
|
|
776 |
_wire->beginTransmission(_address);
|
652 |
777 |
#if ARDUINO >= 100
|
653 |
|
Wire.write((uint8_t)reg);
|
|
778 |
_wire->write((uint8_t)reg);
|
654 |
779 |
#else
|
655 |
|
Wire.send(reg);
|
|
780 |
_wire->send(reg);
|
656 |
781 |
#endif
|
657 |
|
Wire.endTransmission();
|
658 |
|
Wire.requestFrom(_address, (byte)len);
|
|
782 |
_wire->endTransmission();
|
|
783 |
_wire->requestFrom(_address, (byte)len);
|
659 |
784 |
|
660 |
785 |
for (uint8_t i = 0; i < len; i++) {
|
661 |
786 |
#if ARDUINO >= 100
|
662 |
|
buffer[i] = Wire.read();
|
|
787 |
buffer[i] = _wire->read();
|
663 |
788 |
#else
|
664 |
|
buffer[i] = Wire.receive();
|
|
789 |
buffer[i] = _wire->receive();
|
665 |
790 |
#endif
|
666 |
791 |
}
|
667 |
792 |
|