Skip to content

Commit 3140681

Browse files
authored
Merge pull request #4 from blendmaster/linearaccel
Add "Linear Accelerometer" (minus gravity) report
2 parents b1a7177 + 3e9795d commit 3140681

File tree

2 files changed

+52
-2
lines changed

2 files changed

+52
-2
lines changed

src/SparkFun_BNO080_Arduino_Library.cpp

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,13 @@ void BNO080::parseInputReport(void)
135135
rawAccelY = data2;
136136
rawAccelZ = data3;
137137
}
138+
else if(shtpData[5] == SENSOR_REPORTID_LINEAR_ACCELERATION)
139+
{
140+
accelLinAccuracy = status;
141+
rawLinAccelX = data1;
142+
rawLinAccelY = data2;
143+
rawLinAccelZ = data3;
144+
}
138145
else if(shtpData[5] == SENSOR_REPORTID_GYROSCOPE)
139146
{
140147
gyroAccuracy = status;
@@ -221,7 +228,7 @@ float BNO080::getQuatRadianAccuracy()
221228
//Return the acceleration component
222229
uint8_t BNO080::getQuatAccuracy()
223230
{
224-
return(accelAccuracy);
231+
return(quatAccuracy);
225232
}
226233

227234
//Return the acceleration component
@@ -251,6 +258,35 @@ uint8_t BNO080::getAccelAccuracy()
251258
return(accelAccuracy);
252259
}
253260

261+
// linear acceleration, i.e. minus gravity
262+
263+
//Return the acceleration component
264+
float BNO080::getLinAccelX()
265+
{
266+
float accel = qToFloat(rawLinAccelX, linear_accelerometer_Q1);
267+
return(accel);
268+
}
269+
270+
//Return the acceleration component
271+
float BNO080::getLinAccelY()
272+
{
273+
float accel = qToFloat(rawLinAccelY, linear_accelerometer_Q1);
274+
return(accel);
275+
}
276+
277+
//Return the acceleration component
278+
float BNO080::getLinAccelZ()
279+
{
280+
float accel = qToFloat(rawLinAccelZ, linear_accelerometer_Q1);
281+
return(accel);
282+
}
283+
284+
//Return the acceleration component
285+
uint8_t BNO080::getLinAccelAccuracy()
286+
{
287+
return(accelLinAccuracy);
288+
}
289+
254290
//Return the gyro component
255291
float BNO080::getGyroX()
256292
{
@@ -536,6 +572,12 @@ void BNO080::enableAccelerometer(uint16_t timeBetweenReports)
536572
setFeatureCommand(SENSOR_REPORTID_ACCELEROMETER, timeBetweenReports);
537573
}
538574

575+
//Sends the packet to enable the accelerometer
576+
void BNO080::enableLinearAccelerometer(uint16_t timeBetweenReports)
577+
{
578+
setFeatureCommand(SENSOR_REPORTID_LINEAR_ACCELERATION, timeBetweenReports);
579+
}
580+
539581
//Sends the packet to enable the gyro
540582
void BNO080::enableGyro(uint16_t timeBetweenReports)
541583
{
@@ -883,4 +925,4 @@ void BNO080::printPacket(void)
883925
_debugPort->println();
884926
}
885927

886-
}
928+
}

src/SparkFun_BNO080_Arduino_Library.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ class BNO080 {
152152
void enableRotationVector(uint16_t timeBetweenReports);
153153
void enableGameRotationVector(uint16_t timeBetweenReports);
154154
void enableAccelerometer(uint16_t timeBetweenReports);
155+
void enableLinearAccelerometer(uint16_t timeBetweenReports);
155156
void enableGyro(uint16_t timeBetweenReports);
156157
void enableMagnetometer(uint16_t timeBetweenReports);
157158
void enableStepCounter(uint16_t timeBetweenReports);
@@ -173,6 +174,11 @@ class BNO080 {
173174
float getAccelZ();
174175
uint8_t getAccelAccuracy();
175176

177+
float getLinAccelX();
178+
float getLinAccelY();
179+
float getLinAccelZ();
180+
uint8_t getLinAccelAccuracy();
181+
176182
float getGyroX();
177183
float getGyroY();
178184
float getGyroZ();
@@ -228,6 +234,7 @@ class BNO080 {
228234

229235
//These are the raw sensor values pulled from the user requested Input Report
230236
uint16_t rawAccelX, rawAccelY, rawAccelZ, accelAccuracy;
237+
uint16_t rawLinAccelX, rawLinAccelY, rawLinAccelZ, accelLinAccuracy;
231238
uint16_t rawGyroX, rawGyroY, rawGyroZ, gyroAccuracy;
232239
uint16_t rawMagX, rawMagY, rawMagZ, magAccuracy;
233240
uint16_t rawQuatI, rawQuatJ, rawQuatK, rawQuatReal, rawQuatRadianAccuracy, quatAccuracy;
@@ -240,6 +247,7 @@ class BNO080 {
240247
//See the read metadata example for more info
241248
int16_t rotationVector_Q1 = 14;
242249
int16_t accelerometer_Q1 = 8;
250+
int16_t linear_accelerometer_Q1 = 8;
243251
int16_t gyro_Q1 = 9;
244252
int16_t magnetometer_Q1 = 4;
245253
};

0 commit comments

Comments
 (0)