@@ -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,6 +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+ }
166171 }
167172 return (false );
168173}
@@ -227,11 +232,24 @@ void BNO080::parseInputReport(void)
227232 int16_t dataLength = ((uint16_t )shtpHeader[1 ] << 8 | shtpHeader[0 ]);
228233 dataLength &= ~(1 << 15 ); // Clear the MSbit. This bit indicates if this package is a continuation of the last.
229234 // Ignore it for now. TODO catch this as an error and exit
230-
235+
231236 dataLength -= 4 ; // Remove the header bytes from the data count
232237
233238 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 ));
234239
240+ // The gyro-integrated input reports are sent via the special gyro channel and do no include the usual ID, sequence, and status fields
241+ if (shtpHeader[2 ] == CHANNEL_GYRO) {
242+ rawQuatI = (uint16_t )shtpData[1 ] << 8 | shtpData[0 ];
243+ rawQuatJ = (uint16_t )shtpData[3 ] << 8 | shtpData[2 ];
244+ rawQuatK = (uint16_t )shtpData[5 ] << 8 | shtpData[4 ];
245+ rawQuatReal = (uint16_t )shtpData[7 ] << 8 | shtpData[6 ];
246+ rawFastGyroX = (uint16_t )shtpData[9 ] << 8 | shtpData[8 ];
247+ rawFastGyroY = (uint16_t )shtpData[11 ] << 8 | shtpData[10 ];
248+ rawFastGyroZ = (uint16_t )shtpData[13 ] << 8 | shtpData[12 ];
249+
250+ return ;
251+ }
252+
235253 uint8_t status = shtpData[5 + 2 ] & 0x03 ; // Get status bits
236254 uint16_t data1 = (uint16_t )shtpData[5 + 5 ] << 8 | shtpData[5 + 4 ];
237255 uint16_t data2 = (uint16_t )shtpData[5 + 7 ] << 8 | shtpData[5 + 6 ];
@@ -492,6 +510,27 @@ uint8_t BNO080::getMagAccuracy()
492510 return (magAccuracy);
493511}
494512
513+ // Return the high refresh rate gyro component
514+ float BNO080::getFastGyroX ()
515+ {
516+ float gyro = qToFloat (rawFastGyroX, angular_velocity_Q1);
517+ return (gyro);
518+ }
519+
520+ // Return the high refresh rate gyro component
521+ float BNO080::getFastGyroY ()
522+ {
523+ float gyro = qToFloat (rawFastGyroY, angular_velocity_Q1);
524+ return (gyro);
525+ }
526+
527+ // Return the high refresh rate gyro component
528+ float BNO080::getFastGyroZ ()
529+ {
530+ float gyro = qToFloat (rawFastGyroZ, angular_velocity_Q1);
531+ return (gyro);
532+ }
533+
495534// Return the step count
496535uint16_t BNO080::getStepCount ()
497536{
@@ -793,6 +832,12 @@ void BNO080::enableMagnetometer(uint16_t timeBetweenReports)
793832 setFeatureCommand (SENSOR_REPORTID_MAGNETIC_FIELD, timeBetweenReports);
794833}
795834
835+ // Sends the packet to enable the high refresh-rate gyro-integrated rotation vector
836+ void BNO080::enableGyroIntegratedRotationVector (uint16_t timeBetweenReports)
837+ {
838+ setFeatureCommand (SENSOR_REPORTID_GYRO_INTEGRATED_ROTATION_VECTOR, timeBetweenReports);
839+ }
840+
796841// Sends the packet to enable the step counter
797842void BNO080::enableStepCounter (uint16_t timeBetweenReports)
798843{
@@ -1077,13 +1122,13 @@ boolean BNO080::receivePacket(void)
10771122 uint8_t packetMSB = _spiPort->transfer (0 );
10781123 uint8_t channelNumber = _spiPort->transfer (0 );
10791124 uint8_t sequenceNumber = _spiPort->transfer (0 ); // Not sure if we need to store this or not
1080-
1125+
10811126 // Store the header info
10821127 shtpHeader[0 ] = packetLSB;
10831128 shtpHeader[1 ] = packetMSB;
10841129 shtpHeader[2 ] = channelNumber;
10851130 shtpHeader[3 ] = sequenceNumber;
1086-
1131+
10871132 // Calculate the number of data bytes in this packet
10881133 uint16_t dataLength = ((uint16_t )packetMSB << 8 | packetLSB);
10891134 dataLength &= ~(1 << 15 ); // Clear the MSbit.
@@ -1105,7 +1150,9 @@ boolean BNO080::receivePacket(void)
11051150 }
11061151
11071152 digitalWrite (_cs, HIGH); // Release BNO080
1153+
11081154 _spiPort->endTransaction ();
1155+ // printPacket();
11091156 }
11101157 else // Do I2C
11111158 {
0 commit comments