From 1b659571119013a96ed3e083742355e17cfeca4e Mon Sep 17 00:00:00 2001 From: Steven Ruppert Date: Thu, 3 May 2018 17:48:13 -0600 Subject: [PATCH 1/2] Add linear (minus gravity) accelerometer reports Copypasta from the regular accelerometer report. Probably works. --- src/SparkFun_BNO080_Arduino_Library.cpp | 44 ++++++++++++++++++++++++- src/SparkFun_BNO080_Arduino_Library.h | 8 +++++ 2 files changed, 51 insertions(+), 1 deletion(-) diff --git a/src/SparkFun_BNO080_Arduino_Library.cpp b/src/SparkFun_BNO080_Arduino_Library.cpp index 88cb77b..22e77db 100644 --- a/src/SparkFun_BNO080_Arduino_Library.cpp +++ b/src/SparkFun_BNO080_Arduino_Library.cpp @@ -135,6 +135,13 @@ void BNO080::parseInputReport(void) rawAccelY = data2; rawAccelZ = data3; } + else if(shtpData[5] == SENSOR_REPORTID_LINEAR_ACCELERATION) + { + accelLinAccuracy = status; + rawLinAccelX = data1; + rawLinAccelY = data2; + rawLinAccelZ = data3; + } else if(shtpData[5] == SENSOR_REPORTID_GYROSCOPE) { gyroAccuracy = status; @@ -251,6 +258,35 @@ uint8_t BNO080::getAccelAccuracy() return(accelAccuracy); } +// linear acceleration, i.e. minus gravity + +//Return the acceleration component +float BNO080::getLinAccelX() +{ + float accel = qToFloat(rawLinAccelX, linear_accelerometer_Q1); + return(accel); +} + +//Return the acceleration component +float BNO080::getLinAccelY() +{ + float accel = qToFloat(rawLinAccelY, linear_accelerometer_Q1); + return(accel); +} + +//Return the acceleration component +float BNO080::getLinAccelZ() +{ + float accel = qToFloat(rawLinAccelZ, linear_accelerometer_Q1); + return(accel); +} + +//Return the acceleration component +uint8_t BNO080::getLinAccelAccuracy() +{ + return(accelLinAccuracy); +} + //Return the gyro component float BNO080::getGyroX() { @@ -536,6 +572,12 @@ void BNO080::enableAccelerometer(uint16_t timeBetweenReports) setFeatureCommand(SENSOR_REPORTID_ACCELEROMETER, timeBetweenReports); } +//Sends the packet to enable the accelerometer +void BNO080::enableLinearAccelerometer(uint16_t timeBetweenReports) +{ + setFeatureCommand(SENSOR_REPORTID_LINEAR_ACCELERATION, timeBetweenReports); +} + //Sends the packet to enable the gyro void BNO080::enableGyro(uint16_t timeBetweenReports) { @@ -883,4 +925,4 @@ void BNO080::printPacket(void) _debugPort->println(); } -} \ No newline at end of file +} diff --git a/src/SparkFun_BNO080_Arduino_Library.h b/src/SparkFun_BNO080_Arduino_Library.h index 628b218..ff7c7be 100644 --- a/src/SparkFun_BNO080_Arduino_Library.h +++ b/src/SparkFun_BNO080_Arduino_Library.h @@ -152,6 +152,7 @@ class BNO080 { void enableRotationVector(uint16_t timeBetweenReports); void enableGameRotationVector(uint16_t timeBetweenReports); void enableAccelerometer(uint16_t timeBetweenReports); + void enableLinearAccelerometer(uint16_t timeBetweenReports); void enableGyro(uint16_t timeBetweenReports); void enableMagnetometer(uint16_t timeBetweenReports); void enableStepCounter(uint16_t timeBetweenReports); @@ -173,6 +174,11 @@ class BNO080 { float getAccelZ(); uint8_t getAccelAccuracy(); + float getLinAccelX(); + float getLinAccelY(); + float getLinAccelZ(); + uint8_t getLinAccelAccuracy(); + float getGyroX(); float getGyroY(); float getGyroZ(); @@ -228,6 +234,7 @@ class BNO080 { //These are the raw sensor values pulled from the user requested Input Report uint16_t rawAccelX, rawAccelY, rawAccelZ, accelAccuracy; + uint16_t rawLinAccelX, rawLinAccelY, rawLinAccelZ, accelLinAccuracy; uint16_t rawGyroX, rawGyroY, rawGyroZ, gyroAccuracy; uint16_t rawMagX, rawMagY, rawMagZ, magAccuracy; uint16_t rawQuatI, rawQuatJ, rawQuatK, rawQuatReal, rawQuatRadianAccuracy, quatAccuracy; @@ -240,6 +247,7 @@ class BNO080 { //See the read metadata example for more info int16_t rotationVector_Q1 = 14; int16_t accelerometer_Q1 = 8; + int16_t linear_accelerometer_Q1 = 8; int16_t gyro_Q1 = 9; int16_t magnetometer_Q1 = 4; }; From 3e9795d079f0be7de2f392a7e1061abd706e4d1d Mon Sep 17 00:00:00 2001 From: Steven Ruppert Date: Thu, 3 May 2018 19:13:13 -0600 Subject: [PATCH 2/2] getQuatAccuracy: actually return quatAccuracy whoops. --- src/SparkFun_BNO080_Arduino_Library.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/SparkFun_BNO080_Arduino_Library.cpp b/src/SparkFun_BNO080_Arduino_Library.cpp index 22e77db..cf6e4d7 100644 --- a/src/SparkFun_BNO080_Arduino_Library.cpp +++ b/src/SparkFun_BNO080_Arduino_Library.cpp @@ -228,7 +228,7 @@ float BNO080::getQuatRadianAccuracy() //Return the acceleration component uint8_t BNO080::getQuatAccuracy() { - return(accelAccuracy); + return(quatAccuracy); } //Return the acceleration component