Skip to content

Commit ad2327d

Browse files
committed
Update Example20-Sleep. Add non-unitary Quat debug messages.
This commit updates Example20: The I2C clock speed is only increased to 400kHz _after_ enabling the Rotation Vector. I think bus errors sometimes cause the setFeatureCommand to fail at 400kHz. Also, we only communicate with the BNO while it is awake. Talking to it continuously while it is asleep raises the current draw significantly This commit also adds extra debug messages to help trap those rare occasions when QuatI/J/K is >|1|. My theory is these are bus errors on the MS (sign) bit of the int16_t data when running at 400kHz.
1 parent 30fa0ee commit ad2327d

File tree

2 files changed

+71
-25
lines changed

2 files changed

+71
-25
lines changed

examples/Example20-Sleep/Example20-Sleep.ino

+35-25
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@
2626
#include "SparkFun_BNO080_Arduino_Library.h" // Click here to get the library: http://librarymanager/All#SparkFun_BNO080
2727
BNO080 myIMU;
2828

29+
unsigned long lastMillis = 0; // Keep track of time
30+
bool lastPowerState = true; // Toggle between "On" and "Sleep"
31+
2932
void setup()
3033
{
3134
Serial.begin(115200);
@@ -44,46 +47,51 @@ void setup()
4447
// Wire.setClockStretchLimit(4000);
4548
// //=================================
4649

50+
//myIMU.enableDebugging(); // Uncomment this line to enable helpful debug messages on Serial
51+
4752
if (myIMU.begin() == false)
4853
{
4954
Serial.println("BNO080 not detected at default I2C address. Check your jumpers and the hookup guide. Freezing...");
5055
while (1);
5156
}
5257

53-
Wire.setClock(400000); //Increase I2C data rate to 400kHz
58+
// Enable the Rotation Vector packet ** while the I2C bus is set to 100kHz **
59+
myIMU.enableRotationVector(50); //Send RV data update every 50ms
5460

55-
myIMU.enableRotationVector(50); //Send data update every 50ms
61+
Wire.setClock(400000); //Now increase I2C data rate to 400kHz
5662

5763
Serial.println(F("Rotation vector enabled"));
5864
Serial.println(F("Output in form i, j, k, real, accuracy"));
59-
}
6065

61-
unsigned long lastMillis = 0; // Keep track of time
62-
bool lastPowerState = true; // Toggle between "On" and "Sleep"
66+
lastMillis = millis(); // Keep track of time
67+
}
6368

6469
void loop()
6570
{
66-
//Look for reports from the IMU
67-
if (myIMU.dataAvailable() == true)
71+
//Look for reports from the IMU - ** but only when not asleep **
72+
if (lastPowerState) // Are we "On"? (Comment this if you are interested in how it effects the sleep current)
6873
{
69-
float quatI = myIMU.getQuatI();
70-
float quatJ = myIMU.getQuatJ();
71-
float quatK = myIMU.getQuatK();
72-
float quatReal = myIMU.getQuatReal();
73-
float quatRadianAccuracy = myIMU.getQuatRadianAccuracy();
74-
75-
Serial.print(quatI, 2);
76-
Serial.print(F(","));
77-
Serial.print(quatJ, 2);
78-
Serial.print(F(","));
79-
Serial.print(quatK, 2);
80-
Serial.print(F(","));
81-
Serial.print(quatReal, 2);
82-
Serial.print(F(","));
83-
Serial.print(quatRadianAccuracy, 2);
84-
Serial.print(F(","));
85-
86-
Serial.println();
74+
if (myIMU.dataAvailable() == true) // Is fresh data available?
75+
{
76+
float quatI = myIMU.getQuatI();
77+
float quatJ = myIMU.getQuatJ();
78+
float quatK = myIMU.getQuatK();
79+
float quatReal = myIMU.getQuatReal();
80+
float quatRadianAccuracy = myIMU.getQuatRadianAccuracy();
81+
82+
Serial.print(quatI, 2);
83+
Serial.print(F(","));
84+
Serial.print(quatJ, 2);
85+
Serial.print(F(","));
86+
Serial.print(quatK, 2);
87+
Serial.print(F(","));
88+
Serial.print(quatReal, 2);
89+
Serial.print(F(","));
90+
Serial.print(quatRadianAccuracy, 2);
91+
Serial.print(F(","));
92+
93+
Serial.println();
94+
}
8795
}
8896

8997
//Check if it is time to change the power state
@@ -102,4 +110,6 @@ void loop()
102110

103111
lastPowerState ^= 1; // Invert lastPowerState (using ex-or)
104112
}
113+
114+
delay(10); // Don't pound the bus too hard (Comment this if you are interested in how it effects the sleep current)
105115
}

src/SparkFun_BNO080_Arduino_Library.cpp

+36
Original file line numberDiff line numberDiff line change
@@ -504,20 +504,56 @@ void BNO080::getQuat(float &i, float &j, float &k, float &real, float &radAccura
504504
float BNO080::getQuatI()
505505
{
506506
float quat = qToFloat(rawQuatI, rotationVector_Q1);
507+
if (_printDebug == true)
508+
{
509+
if ((quat < -1.0) || (quat > 1.0))
510+
{
511+
_debugPort->print(F("getQuatI: quat: ")); // Debug the occasional non-unitary Quat
512+
_debugPort->print(quat, 2);
513+
_debugPort->print(F(" rawQuatI: "));
514+
_debugPort->print(rawQuatI);
515+
_debugPort->print(F(" rotationVector_Q1: "));
516+
_debugPort->println(rotationVector_Q1);
517+
}
518+
}
507519
return (quat);
508520
}
509521

510522
//Return the rotation vector quaternion J
511523
float BNO080::getQuatJ()
512524
{
513525
float quat = qToFloat(rawQuatJ, rotationVector_Q1);
526+
if (_printDebug == true)
527+
{
528+
if ((quat < -1.0) || (quat > 1.0)) // Debug the occasional non-unitary Quat
529+
{
530+
_debugPort->print(F("getQuatJ: quat: "));
531+
_debugPort->print(quat, 2);
532+
_debugPort->print(F(" rawQuatJ: "));
533+
_debugPort->print(rawQuatJ);
534+
_debugPort->print(F(" rotationVector_Q1: "));
535+
_debugPort->println(rotationVector_Q1);
536+
}
537+
}
514538
return (quat);
515539
}
516540

517541
//Return the rotation vector quaternion K
518542
float BNO080::getQuatK()
519543
{
520544
float quat = qToFloat(rawQuatK, rotationVector_Q1);
545+
if (_printDebug == true)
546+
{
547+
if ((quat < -1.0) || (quat > 1.0)) // Debug the occasional non-unitary Quat
548+
{
549+
_debugPort->print(F("getQuatK: quat: "));
550+
_debugPort->print(quat, 2);
551+
_debugPort->print(F(" rawQuatK: "));
552+
_debugPort->print(rawQuatK);
553+
_debugPort->print(F(" rotationVector_Q1: "));
554+
_debugPort->println(rotationVector_Q1);
555+
}
556+
}
521557
return (quat);
522558
}
523559

0 commit comments

Comments
 (0)