diff --git a/src/SparkFun_BNO080_Arduino_Library.cpp b/src/SparkFun_BNO080_Arduino_Library.cpp index 88cb77b..cf6e4d7 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; @@ -221,7 +228,7 @@ float BNO080::getQuatRadianAccuracy() //Return the acceleration component uint8_t BNO080::getQuatAccuracy() { - return(accelAccuracy); + return(quatAccuracy); } //Return the acceleration component @@ -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; };