Skip to content

Commit b1ab503

Browse files
committed
addition of uncalibrated gyroscope reports
Add the uncalibrated gyroscope report with the full set of related functions
1 parent 24603cc commit b1ab503

File tree

2 files changed

+93
-1
lines changed

2 files changed

+93
-1
lines changed

src/SparkFun_BNO080_Arduino_Library.cpp

Lines changed: 80 additions & 1 deletion
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;
@@ -690,6 +706,62 @@ uint8_t BNO080::getGyroAccuracy()
690706
return (gyroAccuracy);
691707
}
692708

709+
//Gets the full uncalibrated gyro vector
710+
//x,y,z,bx,by,bz output floats
711+
void BNO080::getUncalibratedGyro(float &x, float &y, float &z, float &bx, float &by, float &bz, uint8_t &accuracy)
712+
{
713+
x = qToFloat(rawUncalibGyroX, gyro_Q1);
714+
y = qToFloat(rawUncalibGyroY, gyro_Q1);
715+
z = qToFloat(rawUncalibGyroZ, gyro_Q1);
716+
bx = qToFloat(rawBiasX, gyro_Q1);
717+
by = qToFloat(rawBiasY, gyro_Q1);
718+
bz = qToFloat(rawBiasZ, gyro_Q1);
719+
accuracy = UncalibGyroAccuracy;
720+
}
721+
//Return the gyro component
722+
float BNO080::getUncalibratedGyroX()
723+
{
724+
float gyro = qToFloat(rawUncalibGyroX, gyro_Q1);
725+
return (gyro);
726+
}
727+
//Return the gyro component
728+
float BNO080::getUncalibratedGyroY()
729+
{
730+
float gyro = qToFloat(rawUncalibGyroY, gyro_Q1);
731+
return (gyro);
732+
}
733+
//Return the gyro component
734+
float BNO080::getUncalibratedGyroZ()
735+
{
736+
float gyro = qToFloat(rawUncalibGyroZ, gyro_Q1);
737+
return (gyro);
738+
}
739+
//Return the gyro component
740+
float BNO080::getUncalibratedGyroBiasX()
741+
{
742+
float gyro = qToFloat(rawBiasX, gyro_Q1);
743+
return (gyro);
744+
}
745+
//Return the gyro component
746+
float BNO080::getUncalibratedGyroBiasY()
747+
{
748+
float gyro = qToFloat(rawBiasY, gyro_Q1);
749+
return (gyro);
750+
}
751+
//Return the gyro component
752+
float BNO080::getUncalibratedGyroBiasZ()
753+
{
754+
float gyro = qToFloat(rawBiasZ, gyro_Q1);
755+
return (gyro);
756+
}
757+
758+
//Return the gyro component
759+
uint8_t BNO080::getUncalibratedGyroAccuracy()
760+
{
761+
return (UncalibGyroAccuracy);
762+
}
763+
764+
693765
//Gets the full mag vector
694766
//x,y,z output floats
695767
void BNO080::getMag(float &x, float &y, float &z, uint8_t &accuracy)
@@ -1071,6 +1143,7 @@ uint8_t BNO080::resetReason()
10711143
//See https://en.wikipedia.org/wiki/Q_(number_format)
10721144
float BNO080::qToFloat(int16_t fixedPointValue, uint8_t qPoint)
10731145
{
1146+
10741147
float qFloat = fixedPointValue;
10751148
qFloat *= pow(2, qPoint * -1);
10761149
return (qFloat);
@@ -1118,6 +1191,12 @@ void BNO080::enableGyro(uint16_t timeBetweenReports)
11181191
setFeatureCommand(SENSOR_REPORTID_GYROSCOPE, timeBetweenReports);
11191192
}
11201193

1194+
//Sends the packet to enable the uncalibrated gyro
1195+
void BNO080::enableUncalibratedGyro(uint16_t timeBetweenReports)
1196+
{
1197+
setFeatureCommand(SENSOR_REPORTID_UNCALIBRATED_GYRO, timeBetweenReports);
1198+
}
1199+
11211200
//Sends the packet to enable the magnetometer
11221201
void BNO080::enableMagnetometer(uint16_t timeBetweenReports)
11231202
{

src/SparkFun_BNO080_Arduino_Library.h

Lines changed: 13 additions & 0 deletions
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
@@ -156,6 +157,7 @@ class BNO080
156157
void enableAccelerometer(uint16_t timeBetweenReports);
157158
void enableLinearAccelerometer(uint16_t timeBetweenReports);
158159
void enableGyro(uint16_t timeBetweenReports);
160+
void enableUncalibratedGyro(uint16_t timeBetweenReports);
159161
void enableMagnetometer(uint16_t timeBetweenReports);
160162
void enableTapDetector(uint16_t timeBetweenReports);
161163
void enableStepCounter(uint16_t timeBetweenReports);
@@ -197,6 +199,16 @@ class BNO080
197199
float getGyroZ();
198200
uint8_t getGyroAccuracy();
199201

202+
void getUncalibratedGyro(float &x, float &y, float &z, float &bx, float &by, float &bz, uint8_t &accuracy);
203+
float getUncalibratedGyroX();
204+
float getUncalibratedGyroY();
205+
float getUncalibratedGyroZ();
206+
float getUncalibratedGyroBiasX();
207+
float getUncalibratedGyroBiasY();
208+
float getUncalibratedGyroBiasZ();
209+
uint8_t getUncalibratedGyroAccuracy();
210+
211+
200212
void getFastGyro(float &x, float &y, float &z);
201213
float getFastGyroX();
202214
float getFastGyroY();
@@ -283,6 +295,7 @@ class BNO080
283295
uint16_t rawAccelX, rawAccelY, rawAccelZ, accelAccuracy;
284296
uint16_t rawLinAccelX, rawLinAccelY, rawLinAccelZ, accelLinAccuracy;
285297
uint16_t rawGyroX, rawGyroY, rawGyroZ, gyroAccuracy;
298+
uint16_t rawUncalibGyroX, rawUncalibGyroY, rawUncalibGyroZ, rawBiasX, rawBiasY, rawBiasZ, UncalibGyroAccuracy;
286299
uint16_t rawMagX, rawMagY, rawMagZ, magAccuracy;
287300
uint16_t rawQuatI, rawQuatJ, rawQuatK, rawQuatReal, rawQuatRadianAccuracy, quatAccuracy;
288301
uint16_t rawFastGyroX, rawFastGyroY, rawFastGyroZ;

0 commit comments

Comments
 (0)