Skip to content

Commit 600a13c

Browse files
authored
Merge pull request #98 from bastienboudet/main
Addition of the uncalibrated gyroscope report
2 parents 869936a + 147d703 commit 600a13c

File tree

4 files changed

+176
-1
lines changed

4 files changed

+176
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/*
2+
Using the BNO080 IMU
3+
By: Bastien Boudet
4+
Date: February 3rd, 2022
5+
SparkFun code, firmware, and software is released under the MIT License.
6+
Please see LICENSE.md for further details.
7+
8+
Feel like supporting our work? Buy a board from SparkFun!
9+
https://www.sparkfun.com/products/14586
10+
11+
This example shows how to output the parts of the uncalibrated gyro.
12+
13+
It takes about 1ms at 400kHz I2C to read a record from the sensor, but we are polling the sensor continually
14+
between updates from the sensor. Use the interrupt pin on the BNO080 breakout to avoid polling.
15+
16+
Hardware Connections:
17+
Attach the Qwiic Shield to your Arduino/Photon/ESP32 or other
18+
Plug the sensor onto the shield
19+
Serial.print it out at 115200 baud to serial monitor.
20+
*/
21+
22+
#include <Wire.h>
23+
24+
#include "SparkFun_BNO080_Arduino_Library.h" // Click here to get the library: http://librarymanager/All#SparkFun_BNO080
25+
BNO080 myIMU;
26+
27+
void setup()
28+
{
29+
Serial.begin(115200);
30+
Serial.println();
31+
Serial.println("BNO080 Read Example");
32+
33+
Wire.begin();
34+
35+
myIMU.begin();
36+
37+
Wire.setClock(400000); //Increase I2C data rate to 400kHz
38+
39+
myIMU.enableUncalibratedGyro(50); //Send data update every 50ms
40+
41+
Serial.println(F("Uncalibrated Gyro enabled"));
42+
Serial.println(F("Output in form x, y, z, bx, by, bz in radians per second"));
43+
}
44+
45+
void loop()
46+
{
47+
//Look for reports from the IMU
48+
if (myIMU.dataAvailable() == true)
49+
{
50+
float x = myIMU.getUncalibratedGyroX();
51+
float y = myIMU.getUncalibratedGyroY();
52+
float z = myIMU.getUncalibratedGyroZ();
53+
float bx = myIMU.getUncalibratedGyroBiasX();
54+
float by = myIMU.getUncalibratedGyroBiasY();
55+
float bz = myIMU.getUncalibratedGyroBiasZ();
56+
57+
58+
Serial.print(x, 2);
59+
Serial.print(F(","));
60+
Serial.print(y, 2);
61+
Serial.print(F(","));
62+
Serial.print(z, 2);
63+
Serial.print(F(","));
64+
65+
Serial.print(bx, 2);
66+
Serial.print(F(","));
67+
Serial.print(by, 2);
68+
Serial.print(F(","));
69+
Serial.print(bz, 2);
70+
Serial.print(F(","));
71+
72+
Serial.println();
73+
}
74+
}

keywords.txt

+10
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ enableARVRStabilizedRotationVector KEYWORD2
3939
enableARVRStabilizedGameRotationVector KEYWORD2
4040
enableAccelerometer KEYWORD2
4141
enableGyro KEYWORD2
42+
enableUncalibratedGyro KEYWORD2
4243
enableGravity KEYWORD2
4344
enableMagnetometer KEYWORD2
4445
enableTapDetector KEYWORD2
@@ -76,6 +77,15 @@ getGyroY KEYWORD2
7677
getGyroZ KEYWORD2
7778
getGyroAccuracy KEYWORD2
7879

80+
getUncalibratedGyro KEYWORD2
81+
getUncalibratedGyroX KEYWORD2
82+
getUncalibratedGyroY KEYWORD2
83+
getUncalibratedGyroZ KEYWORD2
84+
getUncalibratedGyroAccuracy KEYWORD2
85+
getUncalibratedGyroBiasX KEYWORD2
86+
getUncalibratedGyroBiasY KEYWORD2
87+
getUncalibratedGyroBiasZ KEYWORD2
88+
7989
getGravity KEYWORD2
8090
getGravityX KEYWORD2
8191
getGravityY KEYWORD2

src/SparkFun_BNO080_Arduino_Library.cpp

+79-1
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,7 @@ uint16_t BNO080::parseInputReport(void)
291291
uint16_t data3 = (uint16_t)shtpData[5 + 9] << 8 | shtpData[5 + 8];
292292
uint16_t data4 = 0;
293293
uint16_t data5 = 0; //We would need to change this to uin32_t to capture time stamp value on Raw Accel/Gyro/Mag reports
294+
uint16_t data6 = 0;
294295

295296
if (dataLength - 5 > 9)
296297
{
@@ -300,6 +301,11 @@ uint16_t BNO080::parseInputReport(void)
300301
{
301302
data5 = (uint16_t)shtpData[5 + 13] << 8 | shtpData[5 + 12];
302303
}
304+
if (dataLength - 5 > 13)
305+
{
306+
data6 = (uint16_t)shtpData[5 + 15] << 8 | shtpData[5 + 14];
307+
}
308+
303309

304310
//Store these generic values to their proper global variable
305311
if (shtpData[5] == SENSOR_REPORTID_ACCELEROMETER)
@@ -317,12 +323,22 @@ uint16_t BNO080::parseInputReport(void)
317323
rawLinAccelZ = data3;
318324
}
319325
else if (shtpData[5] == SENSOR_REPORTID_GYROSCOPE)
320-
{
326+
{
321327
gyroAccuracy = status;
322328
rawGyroX = data1;
323329
rawGyroY = data2;
324330
rawGyroZ = data3;
325331
}
332+
else if (shtpData[5] == SENSOR_REPORTID_UNCALIBRATED_GYRO)
333+
{
334+
UncalibGyroAccuracy = status;
335+
rawUncalibGyroX = data1;
336+
rawUncalibGyroY = data2;
337+
rawUncalibGyroZ = data3;
338+
rawBiasX = data4;
339+
rawBiasY = data5;
340+
rawBiasZ = data6;
341+
}
326342
else if (shtpData[5] == SENSOR_REPORTID_MAGNETIC_FIELD)
327343
{
328344
magAccuracy = status;
@@ -697,6 +713,61 @@ uint8_t BNO080::getGyroAccuracy()
697713
return (gyroAccuracy);
698714
}
699715

716+
//Gets the full uncalibrated gyro vector
717+
//x,y,z,bx,by,bz output floats
718+
void BNO080::getUncalibratedGyro(float &x, float &y, float &z, float &bx, float &by, float &bz, uint8_t &accuracy)
719+
{
720+
x = qToFloat(rawUncalibGyroX, gyro_Q1);
721+
y = qToFloat(rawUncalibGyroY, gyro_Q1);
722+
z = qToFloat(rawUncalibGyroZ, gyro_Q1);
723+
bx = qToFloat(rawBiasX, gyro_Q1);
724+
by = qToFloat(rawBiasY, gyro_Q1);
725+
bz = qToFloat(rawBiasZ, gyro_Q1);
726+
accuracy = UncalibGyroAccuracy;
727+
}
728+
//Return the gyro component
729+
float BNO080::getUncalibratedGyroX()
730+
{
731+
float gyro = qToFloat(rawUncalibGyroX, gyro_Q1);
732+
return (gyro);
733+
}
734+
//Return the gyro component
735+
float BNO080::getUncalibratedGyroY()
736+
{
737+
float gyro = qToFloat(rawUncalibGyroY, gyro_Q1);
738+
return (gyro);
739+
}
740+
//Return the gyro component
741+
float BNO080::getUncalibratedGyroZ()
742+
{
743+
float gyro = qToFloat(rawUncalibGyroZ, gyro_Q1);
744+
return (gyro);
745+
}
746+
//Return the gyro component
747+
float BNO080::getUncalibratedGyroBiasX()
748+
{
749+
float gyro = qToFloat(rawBiasX, gyro_Q1);
750+
return (gyro);
751+
}
752+
//Return the gyro component
753+
float BNO080::getUncalibratedGyroBiasY()
754+
{
755+
float gyro = qToFloat(rawBiasY, gyro_Q1);
756+
return (gyro);
757+
}
758+
//Return the gyro component
759+
float BNO080::getUncalibratedGyroBiasZ()
760+
{
761+
float gyro = qToFloat(rawBiasZ, gyro_Q1);
762+
return (gyro);
763+
}
764+
765+
//Return the gyro component
766+
uint8_t BNO080::getUncalibratedGyroAccuracy()
767+
{
768+
return (UncalibGyroAccuracy);
769+
}
770+
700771
//Gets the full gravity vector
701772
//x,y,z output floats
702773
void BNO080::getGravity(float &x, float &y, float &z, uint8_t &accuracy)
@@ -1113,6 +1184,7 @@ uint8_t BNO080::resetReason()
11131184
//See https://en.wikipedia.org/wiki/Q_(number_format)
11141185
float BNO080::qToFloat(int16_t fixedPointValue, uint8_t qPoint)
11151186
{
1187+
11161188
float qFloat = fixedPointValue;
11171189
qFloat *= pow(2, qPoint * -1);
11181190
return (qFloat);
@@ -1166,6 +1238,12 @@ void BNO080::enableGyro(uint16_t timeBetweenReports)
11661238
setFeatureCommand(SENSOR_REPORTID_GYROSCOPE, timeBetweenReports);
11671239
}
11681240

1241+
//Sends the packet to enable the uncalibrated gyro
1242+
void BNO080::enableUncalibratedGyro(uint16_t timeBetweenReports)
1243+
{
1244+
setFeatureCommand(SENSOR_REPORTID_UNCALIBRATED_GYRO, timeBetweenReports);
1245+
}
1246+
11691247
//Sends the packet to enable the magnetometer
11701248
void BNO080::enableMagnetometer(uint16_t timeBetweenReports)
11711249
{

src/SparkFun_BNO080_Arduino_Library.h

+13
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ const byte CHANNEL_GYRO = 5;
8080
#define SENSOR_REPORTID_LINEAR_ACCELERATION 0x04
8181
#define SENSOR_REPORTID_ROTATION_VECTOR 0x05
8282
#define SENSOR_REPORTID_GRAVITY 0x06
83+
#define SENSOR_REPORTID_UNCALIBRATED_GYRO 0x07
8384
#define SENSOR_REPORTID_GAME_ROTATION_VECTOR 0x08
8485
#define SENSOR_REPORTID_GEOMAGNETIC_ROTATION_VECTOR 0x09
8586
#define SENSOR_REPORTID_GYRO_INTEGRATED_ROTATION_VECTOR 0x2A
@@ -171,6 +172,7 @@ class BNO080
171172
void enableLinearAccelerometer(uint16_t timeBetweenReports);
172173
void enableGravity(uint16_t timeBetweenReports);
173174
void enableGyro(uint16_t timeBetweenReports);
175+
void enableUncalibratedGyro(uint16_t timeBetweenReports);
174176
void enableMagnetometer(uint16_t timeBetweenReports);
175177
void enableTapDetector(uint16_t timeBetweenReports);
176178
void enableStepCounter(uint16_t timeBetweenReports);
@@ -212,6 +214,16 @@ class BNO080
212214
float getGyroZ();
213215
uint8_t getGyroAccuracy();
214216

217+
void getUncalibratedGyro(float &x, float &y, float &z, float &bx, float &by, float &bz, uint8_t &accuracy);
218+
float getUncalibratedGyroX();
219+
float getUncalibratedGyroY();
220+
float getUncalibratedGyroZ();
221+
float getUncalibratedGyroBiasX();
222+
float getUncalibratedGyroBiasY();
223+
float getUncalibratedGyroBiasZ();
224+
uint8_t getUncalibratedGyroAccuracy();
225+
226+
215227
void getFastGyro(float &x, float &y, float &z);
216228
float getFastGyroX();
217229
float getFastGyroY();
@@ -309,6 +321,7 @@ class BNO080
309321
uint16_t rawAccelX, rawAccelY, rawAccelZ, accelAccuracy;
310322
uint16_t rawLinAccelX, rawLinAccelY, rawLinAccelZ, accelLinAccuracy;
311323
uint16_t rawGyroX, rawGyroY, rawGyroZ, gyroAccuracy;
324+
uint16_t rawUncalibGyroX, rawUncalibGyroY, rawUncalibGyroZ, rawBiasX, rawBiasY, rawBiasZ, UncalibGyroAccuracy;
312325
uint16_t rawMagX, rawMagY, rawMagZ, magAccuracy;
313326
uint16_t rawQuatI, rawQuatJ, rawQuatK, rawQuatReal, rawQuatRadianAccuracy, quatAccuracy;
314327
uint16_t rawFastGyroX, rawFastGyroY, rawFastGyroZ;

0 commit comments

Comments
 (0)