@@ -417,6 +417,13 @@ uint16_t BNO080::parseInputReport(void)
417417 calibrationStatus = shtpData[5 + 5 ]; // R0 - Status (0 = success, non-zero = fail)
418418 }
419419 }
420+ else if (shtpData[5 ] == SENSOR_REPORTID_GRAVITY)
421+ {
422+ gravityAccuracy = status;
423+ gravityX = data1;
424+ gravityY = data2;
425+ gravityZ = data3;
426+ }
420427 else
421428 {
422429 // This sensor report ID is unhandled.
@@ -761,6 +768,40 @@ uint8_t BNO080::getUncalibratedGyroAccuracy()
761768 return (UncalibGyroAccuracy);
762769}
763770
771+ // Gets the full gravity vector
772+ // x,y,z output floats
773+ void BNO080::getGravity (float &x, float &y, float &z, uint8_t &accuracy)
774+ {
775+ x = qToFloat (gravityX, gravity_Q1);
776+ y = qToFloat (gravityX, gravity_Q1);
777+ z = qToFloat (gravityX, gravity_Q1);
778+ accuracy = gravityAccuracy;
779+ }
780+
781+ float BNO080::getGravityX ()
782+ {
783+ float x = qToFloat (gravityX, gravity_Q1);
784+ return x;
785+ }
786+
787+ // Return the gravity component
788+ float BNO080::getGravityY ()
789+ {
790+ float y = qToFloat (gravityY, gravity_Q1);
791+ return y;
792+ }
793+
794+ // Return the gravity component
795+ float BNO080::getGravityZ ()
796+ {
797+ float z = qToFloat (gravityZ, gravity_Q1);
798+ return z;
799+ }
800+
801+ uint8_t BNO080::getGravityAccuracy ()
802+ {
803+ return (gravityAccuracy);
804+ }
764805
765806// Gets the full mag vector
766807// x,y,z output floats
@@ -1185,6 +1226,12 @@ void BNO080::enableLinearAccelerometer(uint16_t timeBetweenReports)
11851226 setFeatureCommand (SENSOR_REPORTID_LINEAR_ACCELERATION, timeBetweenReports);
11861227}
11871228
1229+ // Sends the packet to enable the gravity vector
1230+ void BNO080::enableGravity (uint16_t timeBetweenReports)
1231+ {
1232+ setFeatureCommand (SENSOR_REPORTID_GRAVITY, timeBetweenReports);
1233+ }
1234+
11881235// Sends the packet to enable the gyro
11891236void BNO080::enableGyro (uint16_t timeBetweenReports)
11901237{
@@ -1300,6 +1347,21 @@ boolean BNO080::calibrationComplete()
13001347 return (false );
13011348}
13021349
1350+ void BNO080::tareNow (bool zAxis, uint8_t rotationVectorBasis)
1351+ {
1352+ sendTareCommand (TARE_NOW, zAxis ? TARE_AXIS_Z : TARE_AXIS_ALL, rotationVectorBasis);
1353+ }
1354+
1355+ void BNO080::saveTare ()
1356+ {
1357+ sendTareCommand (TARE_PERSIST);
1358+ }
1359+
1360+ void BNO080::clearTare ()
1361+ {
1362+ sendTareCommand (TARE_SET_REORIENTATION);
1363+ }
1364+
13031365// Given a sensor's report ID, this tells the BNO080 to begin reporting the values
13041366void BNO080::setFeatureCommand (uint8_t reportID, uint16_t timeBetweenReports)
13051367{
@@ -1399,6 +1461,23 @@ void BNO080::sendCalibrateCommand(uint8_t thingToCalibrate)
13991461 sendCommand (COMMAND_ME_CALIBRATE);
14001462}
14011463
1464+ void BNO080::sendTareCommand (uint8_t command, uint8_t axis, uint8_t rotationVectorBasis)
1465+ {
1466+ for (uint8_t x = 3 ; x < 12 ; x++) // Clear this section of the shtpData array
1467+ shtpData[x] = 0 ;
1468+
1469+ shtpData[3 ] = command;
1470+
1471+ if (command == TARE_NOW)
1472+ {
1473+ shtpData[4 ] = axis; // axis setting
1474+ shtpData[5 ] = rotationVectorBasis; // rotation vector
1475+ }
1476+
1477+ // Using this shtpData packet, send a command
1478+ sendCommand (COMMAND_TARE);
1479+ }
1480+
14021481// Request ME Calibration Status from BNO080
14031482// See page 51 of reference manual
14041483void BNO080::requestCalibrationStatus ()
@@ -1768,4 +1847,4 @@ void BNO080::printHeader(void)
17681847 }
17691848 _debugPort->println ();
17701849 }
1771- }
1850+ }
0 commit comments