Skip to content

Commit d978711

Browse files
authored
Merge pull request #47 from sparkfun/release-candidate
Adding AR/VR Stabilized RotationVector and AR/VR Stabilized GameRotationVector support (#46)
2 parents aaebbb5 + 9a12cc7 commit d978711

File tree

4 files changed

+39
-14
lines changed

4 files changed

+39
-14
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ Thank to all those who have helped improve the library:
2020
* fm4dd for typo - [PR 19](https://github.com/sparkfun/SparkFun_BNO080_Arduino_Library/pull/19)
2121
* tstellanova for heading accuracy correction - [PR 40](https://github.com/sparkfun/SparkFun_BNO080_Arduino_Library/pull/40)
2222
* badVibes for gyro integrated rotation vector support - [PR 41](https://github.com/sparkfun/SparkFun_BNO080_Arduino_Library/pull/41)
23+
* Filimindji for AR/VR Stabilized RotationVector and AR/VR Stabilized GameRotationVector support - [PR 46](https://github.com/sparkfun/SparkFun_BNO080_Arduino_Library/pull/46)
2324

2425
Repository Contents
2526
-------------------

keywords.txt

+2
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ printPacket KEYWORD2
3131

3232
enableRotationVector KEYWORD2
3333
enableGameRotationVector KEYWORD2
34+
enableARVRStabilizedRotationVector KEYWORD2
35+
enableARVRStabilizedGameRotationVector KEYWORD2
3436
enableAccelerometer KEYWORD2
3537
enableGyro KEYWORD2
3638
enableMagnetometer KEYWORD2

src/SparkFun_BNO080_Arduino_Library.cpp

+32-14
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ bool BNO080::dataAvailable(void)
149149
if (digitalRead(_int) == HIGH)
150150
return (false);
151151
}
152-
152+
153153
if (receivePacket() == true)
154154
{
155155
//Check to see if this packet is a sensor reporting its data to us
@@ -163,11 +163,11 @@ bool BNO080::dataAvailable(void)
163163
parseCommandReport(); //This will update responses to commands, calibrationStatus, etc.
164164
return (true);
165165
}
166-
else if(shtpHeader[2] == CHANNEL_GYRO)
167-
{
168-
parseInputReport(); //This will update the rawAccelX, etc variables depending on which feature report is found
169-
return (true);
170-
}
166+
else if(shtpHeader[2] == CHANNEL_GYRO)
167+
{
168+
parseInputReport(); //This will update the rawAccelX, etc variables depending on which feature report is found
169+
return (true);
170+
}
171171
}
172172
return (false);
173173
}
@@ -232,12 +232,12 @@ void BNO080::parseInputReport(void)
232232
int16_t dataLength = ((uint16_t)shtpHeader[1] << 8 | shtpHeader[0]);
233233
dataLength &= ~(1 << 15); //Clear the MSbit. This bit indicates if this package is a continuation of the last.
234234
//Ignore it for now. TODO catch this as an error and exit
235-
235+
236236
dataLength -= 4; //Remove the header bytes from the data count
237237

238238
timeStamp = ((uint32_t)shtpData[4] << (8 * 3)) | ((uint32_t)shtpData[3] << (8 * 2)) | ((uint32_t)shtpData[2] << (8 * 1)) | ((uint32_t)shtpData[1] << (8 * 0));
239239

240-
// The gyro-integrated input reports are sent via the special gyro channel and do no include the usual ID, sequence, and status fields
240+
// The gyro-integrated input reports are sent via the special gyro channel and do no include the usual ID, sequence, and status fields
241241
if(shtpHeader[2] == CHANNEL_GYRO) {
242242
rawQuatI = (uint16_t)shtpData[1] << 8 | shtpData[0];
243243
rawQuatJ = (uint16_t)shtpData[3] << 8 | shtpData[2];
@@ -246,7 +246,7 @@ void BNO080::parseInputReport(void)
246246
rawFastGyroX = (uint16_t)shtpData[9] << 8 | shtpData[8];
247247
rawFastGyroY = (uint16_t)shtpData[11] << 8 | shtpData[10];
248248
rawFastGyroZ = (uint16_t)shtpData[13] << 8 | shtpData[12];
249-
249+
250250
return;
251251
}
252252

@@ -295,14 +295,20 @@ void BNO080::parseInputReport(void)
295295
rawMagY = data2;
296296
rawMagZ = data3;
297297
}
298-
else if (shtpData[5] == SENSOR_REPORTID_ROTATION_VECTOR || shtpData[5] == SENSOR_REPORTID_GAME_ROTATION_VECTOR)
298+
else if (shtpData[5] == SENSOR_REPORTID_ROTATION_VECTOR ||
299+
shtpData[5] == SENSOR_REPORTID_GAME_ROTATION_VECTOR ||
300+
shtpData[5] == SENSOR_REPORTID_AR_VR_STABILIZED_ROTATION_VECTOR ||
301+
shtpData[5] == SENSOR_REPORTID_AR_VR_STABILIZED_GAME_ROTATION_VECTOR)
299302
{
300303
quatAccuracy = status;
301304
rawQuatI = data1;
302305
rawQuatJ = data2;
303306
rawQuatK = data3;
304307
rawQuatReal = data4;
305-
rawQuatRadianAccuracy = data5; //Only available on rotation vector, not game rot vector
308+
309+
//Only available on rotation vector and ar/vr stabilized rotation vector,
310+
// not game rot vector and not ar/vr stabilized rotation vector
311+
rawQuatRadianAccuracy = data5;
306312
}
307313
else if (shtpData[5] == SENSOR_REPORTID_STEP_COUNTER)
308314
{
@@ -878,12 +884,24 @@ void BNO080::enableRotationVector(uint16_t timeBetweenReports)
878884
setFeatureCommand(SENSOR_REPORTID_ROTATION_VECTOR, timeBetweenReports);
879885
}
880886

887+
//Sends the packet to enable the ar/vr stabilized rotation vector
888+
void BNO080::enableARVRStabilizedRotationVector(uint16_t timeBetweenReports)
889+
{
890+
setFeatureCommand(SENSOR_REPORTID_AR_VR_STABILIZED_ROTATION_VECTOR, timeBetweenReports);
891+
}
892+
881893
//Sends the packet to enable the rotation vector
882894
void BNO080::enableGameRotationVector(uint16_t timeBetweenReports)
883895
{
884896
setFeatureCommand(SENSOR_REPORTID_GAME_ROTATION_VECTOR, timeBetweenReports);
885897
}
886898

899+
//Sends the packet to enable the ar/vr stabilized rotation vector
900+
void BNO080::enableARVRStabilizedGameRotationVector(uint16_t timeBetweenReports)
901+
{
902+
setFeatureCommand(SENSOR_REPORTID_AR_VR_STABILIZED_GAME_ROTATION_VECTOR, timeBetweenReports);
903+
}
904+
887905
//Sends the packet to enable the accelerometer
888906
void BNO080::enableAccelerometer(uint16_t timeBetweenReports)
889907
{
@@ -1198,13 +1216,13 @@ boolean BNO080::receivePacket(void)
11981216
uint8_t packetMSB = _spiPort->transfer(0);
11991217
uint8_t channelNumber = _spiPort->transfer(0);
12001218
uint8_t sequenceNumber = _spiPort->transfer(0); //Not sure if we need to store this or not
1201-
1219+
12021220
//Store the header info
12031221
shtpHeader[0] = packetLSB;
12041222
shtpHeader[1] = packetMSB;
12051223
shtpHeader[2] = channelNumber;
12061224
shtpHeader[3] = sequenceNumber;
1207-
1225+
12081226
//Calculate the number of data bytes in this packet
12091227
uint16_t dataLength = ((uint16_t)packetMSB << 8 | packetLSB);
12101228
dataLength &= ~(1 << 15); //Clear the MSbit.
@@ -1226,7 +1244,7 @@ boolean BNO080::receivePacket(void)
12261244
}
12271245

12281246
digitalWrite(_cs, HIGH); //Release BNO080
1229-
1247+
12301248
_spiPort->endTransaction();
12311249
//printPacket();
12321250
}

src/SparkFun_BNO080_Arduino_Library.h

+4
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ const byte CHANNEL_GYRO = 5;
9595
#define SENSOR_REPORTID_RAW_GYROSCOPE 0x15
9696
#define SENSOR_REPORTID_RAW_MAGNETOMETER 0x16
9797
#define SENSOR_REPORTID_PERSONAL_ACTIVITY_CLASSIFIER 0x1E
98+
#define SENSOR_REPORTID_AR_VR_STABILIZED_ROTATION_VECTOR 0x28
99+
#define SENSOR_REPORTID_AR_VR_STABILIZED_GAME_ROTATION_VECTOR 0x29
98100

99101
//Record IDs from figure 29, page 29 reference manual
100102
//These are used to read the metadata for each sensor type
@@ -147,6 +149,8 @@ class BNO080
147149

148150
void enableRotationVector(uint16_t timeBetweenReports);
149151
void enableGameRotationVector(uint16_t timeBetweenReports);
152+
void enableARVRStabilizedRotationVector(uint16_t timeBetweenReports);
153+
void enableARVRStabilizedGameRotationVector(uint16_t timeBetweenReports);
150154
void enableAccelerometer(uint16_t timeBetweenReports);
151155
void enableLinearAccelerometer(uint16_t timeBetweenReports);
152156
void enableGyro(uint16_t timeBetweenReports);

0 commit comments

Comments
 (0)