Fully featured I2C and SPI driver for CEVA (Hilcrest)'s BNO080 and FSM300 Inertial Measurement Units.

Dependents:   BNO080-Examples BNO080-Examples

Embed: (wiki syntax)

« Back to documentation index

BNO080SPI Class Reference

Version of the BNO080 driver which uses the SPI interface. More...

#include <BNO080.h>

Inherits BNO080Base.

Inherited by BNO080Async.

Public Types

enum  Report {
  TOTAL_ACCELERATION = SENSOR_REPORTID_ACCELEROMETER, LINEAR_ACCELERATION = SENSOR_REPORTID_LINEAR_ACCELERATION, GRAVITY_ACCELERATION = SENSOR_REPORTID_GRAVITY, GYROSCOPE = SENSOR_REPORTID_GYROSCOPE_CALIBRATED,
  MAG_FIELD = SENSOR_REPORTID_MAGNETIC_FIELD_CALIBRATED, MAG_FIELD_UNCALIBRATED = SENSOR_REPORTID_MAGNETIC_FIELD_UNCALIBRATED, ROTATION = SENSOR_REPORTID_ROTATION_VECTOR, GEOMAGNETIC_ROTATION = SENSOR_REPORTID_GEOMAGNETIC_ROTATION_VECTOR,
  GAME_ROTATION = SENSOR_REPORTID_GAME_ROTATION_VECTOR, TAP_DETECTOR = SENSOR_REPORTID_TAP_DETECTOR, STABILITY_CLASSIFIER = SENSOR_REPORTID_STABILITY_CLASSIFIER, STEP_DETECTOR = SENSOR_REPORTID_STEP_DETECTOR,
  STEP_COUNTER = SENSOR_REPORTID_STEP_COUNTER, SIGNIFICANT_MOTION = SENSOR_REPORTID_SIGNIFICANT_MOTION, SHAKE_DETECTOR = SENSOR_REPORTID_SHAKE_DETECTOR
}
 

List of all sensor reports that the IMU supports.

More...
enum  Stability {
  UNKNOWN = 0, ON_TABLE = 1, STATIONARY = 2, STABLE = 3,
  MOTION = 4
}
 

Enum to represent the different stability types.

More...

Public Member Functions

 BNO080SPI (Stream *debugPort, PinName rstPin, PinName intPin, PinName wakePin, PinName misoPin, PinName mosiPin, PinName sclkPin, PinName csPin, int spiSpeed=3000000)
 Construct a BNO080 driver for the SPI bus, providing pins and parameters.
virtual bool begin ()
 Resets and connects to the IMU.
void tare (bool zOnly=false)
 Tells the IMU to use its current rotation vector as the "zero" rotation vector and to reorient all outputs accordingly.
bool enableCalibration (bool calibrateAccel, bool calibrateGyro, bool calibrateMag)
 Tells the IMU to begin a dynamic sensor calibration.
bool saveCalibration ()
 Saves the calibration started with startCalibration() and ends the calibration.
void setSensorOrientation (Quaternion orientation)
 Sets the orientation quaternion, telling the sensor how it's mounted in relation to world space.
bool setPermanentOrientation (Quaternion orientation)
 Sets the orientation quaternion, telling the sensor how it's mounted in relation to world space.
virtual void lockMutex ()
 No-op on synchronous driver.
virtual void unlockMutex ()
 No-op on synchronous driver.
virtual bool updateData ()
 Checks for new data packets queued on the IMU.
uint8_t getReportStatus (Report report)
 Gets the status of a report as a 2 bit number.
const char * getReportStatusString (Report report)
 Get a string for printout describing the status of a sensor.
bool hasNewData (Report report)
 Checks if a specific report has gotten new data since the last call to this function.
void enableReport (Report report, uint16_t timeBetweenReports)
 Enable a data report from the IMU.
void disableReport (Report report)
 Disable a data report from the IMU.
uint32_t getSerialNumber ()
 Gets the serial number (used to uniquely identify each individual device).
float getRange (Report report)
 Gets the range of a report as reported by the IMU.
float getResolution (Report report)
 Gets the resolution of a report as reported by the IMU.
float getPower (Report report)
 Get the power used by a report when it's operating, according to the IMU.
float getMinPeriod (Report report)
 Gets the smallest polling period that a report supports.
float getMaxPeriod (Report report)
 Gets the larges polling period that a report supports.
void printMetadataSummary (Report report)
 Prints a summary of a report's metadata to the debug stream.

Data Fields

TVector3 totalAcceleration
 Readout from Accleration report.
TVector3 linearAcceleration
 Readout from Linear Acceleration report.
TVector3 gravityAcceleration
 Readout from Gravity report.
TVector3 gyroRotation
 Readout from Calibrated Gyroscope report Represents the angular velocities of the chip in rad/s in the X, Y, and Z axes.
TVector3 magField
 Readout from the Magnetic Field Calibrated report.
TVector3 magFieldUncalibrated
 Readout from the Magnetic Field Uncalibrated report.
TVector3 hardIronOffset
 Auxiliary readout from the Magnetic Field Uncalibrated report.
Quaternion rotationVector
 Readout from the Rotation Vector report.
float rotationAccuracy
 Auxiliary accuracy readout from the Rotation Vector report.
Quaternion gameRotationVector
 Readout from the Game Rotation Vector report.
Quaternion geomagneticRotationVector
 Readout from the Geomagnetic Rotation Vector report.
float geomagneticRotationAccuracy
 Auxiliary accuracy readout from the Geomagnetic Rotation Vector report.
bool tapDetected
 Tap readout from the Tap Detector report.
bool doubleTap
 Whether the last tap detected was a single or double tap.
Stability stability
 Readout from the stability classifier.
bool stepDetected
 Readout from the Step Detector report.
uint16_t stepCount
 Readout from the Step Counter report.
bool significantMotionDetected
 Readout from the Significant Motion Detector report.
bool shakeDetected
 Readout from the Shake Detector report.
uint8_t majorSoftwareVersion
 Version info read from the IMU when it starts up.
bool xAxisShake
 The axis/axes that shaking was detected in in the latest shaking report.

Protected Member Functions

bool receivePacket (std::chrono::milliseconds timeout=200ms) override
 Reads a packet from the IMU and stores it in the class variables.
bool sendPacket (uint8_t channelNumber, uint8_t dataLength) override
 Sends the current shtpData contents to the BNO.
bool receiveCompletePacket (size_t bytesRead, std::chrono::milliseconds timeout=200ms)
 Assuming that at least a packet header has been read into the RX buffer, receive the remainder of the packet.
void spiTransferAndWait (const uint8_t *tx_buffer, int tx_length, uint8_t *rx_buffer, int rx_length)
 Start an SPI transfer and suspend the current thread until it is complete.
void spiTransferAndWait (const uint8_t *tx_buffer, int tx_length, uint8_t *rx_buffer, int rx_length)
 Start an SPI transfer and wait for it to complete.
uint16_t getMetaVersion ()
 Gets the version of the metadata stored in the buffer.
void processPacket ()
 Processes the packet currently stored in the buffer, and updates class variables to reflect the data it contains.
void parseSensorDataPacket ()
 Processes the sensor data packet currently stored in the buffer.
virtual bool waitForPacket (int channel, uint8_t reportID, std::chrono::milliseconds timeout=125ms)
 Call to wait for a packet with the given parameters to come in.
float qToFloat (int16_t fixedPointValue, uint8_t qPoint)
 Given a Q value, converts fixed point floating to regular floating point number.
float qToFloat_dword (uint32_t fixedPointValue, int16_t qPoint)
 Given a Q value, converts fixed point floating to regular floating point number.
int16_t floatToQ (float qFloat, uint8_t qPoint)
 Given a floating point value and a Q point, convert to Q See https://en.wikipedia.org/wiki/Q_(number_format)
int32_t floatToQ_dword (float qFloat, uint16_t qPoint)
 Given a floating point value and a Q point, convert to Q See https://en.wikipedia.org/wiki/Q_(number_format)
void sendCommand (uint8_t command)
 Tell the sensor to do a command.
void setFeatureCommand (uint8_t reportID, uint16_t timeBetweenReports, uint32_t specificConfig=0)
 Given a sensor's report ID, this tells the BNO080 to begin reporting the values.
bool readFRSRecord (uint16_t recordID, uint32_t *readBuffer, uint16_t readLength)
 Read a record from the FRS (Flash Record System) on the IMU.
bool writeFRSRecord (uint16_t recordID, uint32_t *buffer, uint16_t length)
 Write a record to the FRS (Flash Record System) on the IMU.
void printPacket (uint8_t *buffer)
 Prints the current shtp packet stored in the buffer.
virtual void clearSendBuffer ()
 Erases the current SHTP TX packet buffer.
bool loadReportMetadata (Report report)
 Loads the metadata for this report into the metadata buffer.
int16_t getQ1 (Report report)
 Gets the Q point from a report's metadata, which essentially defines where the decimal point goes in the sensor's output.

Protected Attributes

SPI _spiPort
 I2C port object.
int _spiSpeed
 user defined port speed
Stream * _debugPort
 Serial stream to print debug info to.
InterruptIn _int
 Interrupt pin -- signals to the host that the IMU has data to send.
uint8_t * txShtpHeader = txPacketBuffer
 Each SHTP packet starts with a header of 4 uint8_ts.
uint8_t * txShtpData = txPacketBuffer + SHTP_HEADER_SIZE
 Stores data contained in each packet.
uint16_t rxPacketLength
 Length of packet that was received into buffer. Does NOT include header bytes.
uint8_t sequenceNumber [6]
 Current sequence number for each channel, incremented after transmission.
uint8_t commandSequenceNumber
 Commands have a seqNum as well. These are inside command packet, the header uses its own seqNum per channel.
uint16_t bufferMetadataRecord
 Record ID of the metadata record currently stored in the metadataRecord[] buffer.
uint32_t metadataRecord [METADATA_BUFFER_LEN]
 Buffer for current metadata record.
uint8_t reportStatus [STATUS_ARRAY_LEN]
 stores status of each sensor, indexed by report ID
bool reportHasBeenUpdated [STATUS_ARRAY_LEN]
 stores whether a sensor has been updated since the last call to hasNewData()

Detailed Description

Version of the BNO080 driver which uses the SPI interface.

WARNING: The SPI interface, unlike the I2C interface, of this chip has some god-awful timing requirements that are difficult to satisfy.

In order for the chip to produce data, you must call updateData() at at more than twice the frequency of the fastest sensor poll rate you have set. Otherwise, for reasons that I don't exactly understand, the IMU will have some kind of internal watchdog timeout error and shut itself down. Also, you have about 500ms after calling begin() to configure reports and start receiving data, or the same thing happens.

If this timing error happens to you, the symptoms are strange: the IMU will just stop sending data, several seconds later. No error or anything, just no data. To recover from the error, you would have to call begin() again and reconfigure it from scratch.

Definition at line 847 of file BNO080.h.


Member Enumeration Documentation

enum Report [inherited]

List of all sensor reports that the IMU supports.

Enumerator:
TOTAL_ACCELERATION 

Total acceleration of the IMU in world space.

See BNO datasheet section 2.1.1

LINEAR_ACCELERATION 

Acceleration of the IMU not including the acceleration of gravity.

See BNO datasheet section 2.1.1

GRAVITY_ACCELERATION 

Acceleration of gravity felt by the IMU.

See BNO datasheet section 2.1.1

GYROSCOPE 

(calibrated) gyroscope reading of the rotational speed of the IMU.

See BNO datasheet section 2.1.2

MAG_FIELD 

(calibrated) reading of Earth's magnetic field levels.

See BNO datasheet section 2.1.3

MAG_FIELD_UNCALIBRATED 

Uncalibrated reading of magnetic field levels, without any hard iron offsets applied See BNO datasheet section 2.1.3.

ROTATION 

Fused reading of the IMU's rotation in space using all three sensors.

This is the most accurate reading of absolute orientation that the IMU can provide. See BNO datasheet section 2.2.4

GEOMAGNETIC_ROTATION 

Fused reading of rotation from accelerometer and magnetometer readings.

This report is designed to decrease power consumption (by turning off the gyroscope) in exchange for reduced responsiveness.

GAME_ROTATION 

Fused reading of the IMU's rotation in space.

Unlike the regular rotation vector, the Game Rotation Vector is not referenced against the magnetic field and the "zero yaw" point is arbitrary. See BNO datasheet section 2.2.2

TAP_DETECTOR 

Detects a user tapping on the device containing the IMU.

See BNO datasheet section 2.4.2

STABILITY_CLASSIFIER 

Detects whether the device is on a table, being held stably, or being moved.

See BNO datasheet section 2.4.1

STEP_DETECTOR 

Detects a user taking a step with the IMU worn on their person.

See BNO datasheet section 2.4.3

STEP_COUNTER 

Detects how many steps a user has taken.

See BNO datasheet section 2.4.4

SIGNIFICANT_MOTION 

Detects when the IMU has made a "significant" motion, defined as moving a few steps and/or accelerating significantly.

NOTE: this report automatically disables itself after sending a report, so you'll have to reenable it each time a motion i s detected. See BNO datasheet section 2.4.6

SHAKE_DETECTOR 

Detects when the IMU is being shaken.

See BNO datasheet section 2.4.7

Definition at line 133 of file BNO080.h.

enum Stability [inherited]

Enum to represent the different stability types.

See BNO datasheet section 2.4.1 and SH-2 section 6.5.31.2 for details.

Enumerator:
UNKNOWN 

Unknown stability type.

ON_TABLE 

At rest on a stable surface with very little motion.

STATIONARY 

Motion is stable, but the duration requirement for stability has not been met.

Can only occur during gyroscope calibration (why? beats me!)

STABLE 

Stable (has been below the acceleration threshold for the required duration)

MOTION 

IMU is moving.

Definition at line 332 of file BNO080.h.


Constructor & Destructor Documentation

BNO080SPI ( Stream *  debugPort,
PinName  rstPin,
PinName  intPin,
PinName  wakePin,
PinName  misoPin,
PinName  mosiPin,
PinName  sclkPin,
PinName  csPin,
int  spiSpeed = 3000000 
)

Construct a BNO080 driver for the SPI bus, providing pins and parameters.

This doesn't actually initialize the chip, you will need to call begin() for that.

NOTE: while some schematics tell you to connect the BOOTN pin to the processor, this driver does not use or require it. Just tie it to VCC per the datasheet.

Parameters:
debugPortSerial port to write output to. Cannot be nullptr.
rstPinHardware reset pin, resets the IMU
intPinHardware interrupt pin, this is used for the IMU to signal the host that it has a message to send
wakePinHardware wake pin, this is used by the processor to signal the BNO to wake up and receive a message
misoPinSPI MISO pin
mosiPinSPI MOSI pin
sclkPinSPI SCLK pin
csPinSPI CS pin
spiSpeedSPI frequency. The BNO's max is 3MHz.

Definition at line 1495 of file BNO080.cpp.


Member Function Documentation

bool begin (  ) [virtual, inherited]

Resets and connects to the IMU.

Verifies that it's connected, and reads out its version info into the class variables above.

If this function is failing, it would be a good idea to turn on BNO_DEBUG in the cpp file to get detailed output.

Note: this function takes several hundred ms to execute, mainly due to waiting for the BNO to boot.

Returns:
whether or not initialization was successful

Reimplemented in BNO080Async.

Definition at line 94 of file BNO080.cpp.

void clearSendBuffer (  ) [protected, virtual, inherited]

Erases the current SHTP TX packet buffer.

In BNO080Async, this blocks until the buffer is available.

Definition at line 1217 of file BNO080.cpp.

void disableReport ( Report  report ) [inherited]

Disable a data report from the IMU.

Parameters:
reportThe report to disable.

Definition at line 428 of file BNO080.cpp.

bool enableCalibration ( bool  calibrateAccel,
bool  calibrateGyro,
bool  calibrateMag 
) [inherited]

Tells the IMU to begin a dynamic sensor calibration.

To calibrate the IMU, call this function and move the IMU according to the instructions in the "BNO080 Sensor Calibration Procedure" app note (http://www.hillcrestlabs.com/download/59de9014566d0727bd002ae7).

To tell when the calibration is complete, look at the status bits for Game Rotation Vector (for accel and gyro) and Magnetic Field (for the magnetometer).

The gyro and accelerometer should only need to be calibrated once, but the magnetometer will need to be recalibrated every time the orientation of ferrous metals around the IMU changes (e.g. when it is put into a new enclosure).

The new calibration will not be saved in flash until you call saveCalibration().

NOTE: calling this with all false values will cancel any calibration in progress. However, the calibration data being created will remain in use until the next chip reset (I think!)

Parameters:
calibrateAccelWhether to calibrate the accelerometer.
calibrateGyroWhether to calibrate the gyro.
calibrateMagWhether to calibrate the magnetometer.
Returns:
whether the operation succeeded

Definition at line 216 of file BNO080.cpp.

void enableReport ( Report  report,
uint16_t  timeBetweenReports 
) [inherited]

Enable a data report from the IMU.

Look at the comments above to see what the reports do. This function checks your polling period against the report's max speed in the IMU's metadata, and reports an error if you're trying to poll too fast.

Parameters:
timeBetweenReportstime in milliseconds between data updates.

Definition at line 409 of file BNO080.cpp.

int16_t floatToQ ( float  qFloat,
uint8_t  qPoint 
) [protected, inherited]

Given a floating point value and a Q point, convert to Q See https://en.wikipedia.org/wiki/Q_(number_format)

Parameters:
qFloat
qPoint
Returns:

Definition at line 850 of file BNO080.cpp.

int32_t floatToQ_dword ( float  qFloat,
uint16_t  qPoint 
) [protected, inherited]

Given a floating point value and a Q point, convert to Q See https://en.wikipedia.org/wiki/Q_(number_format)

This version is used for the signed 32-bit values in metadata records.

Parameters:
qFloat
qPoint
Returns:

Definition at line 856 of file BNO080.cpp.

float getMaxPeriod ( Report  report ) [inherited]

Gets the larges polling period that a report supports.

Some reports don't have a max period, in which case this function will return -1.0.

Returns:
Period in seconds, or -1.0 on error.

Definition at line 477 of file BNO080.cpp.

uint16_t getMetaVersion (  ) [protected, inherited]

Gets the version of the metadata stored in the buffer.

We might see version 3 and 4 records, and they have different layouts.

Returns:

Definition at line 622 of file BNO080.h.

float getMinPeriod ( Report  report ) [inherited]

Gets the smallest polling period that a report supports.

Returns:
Period in seconds.

Definition at line 470 of file BNO080.cpp.

float getPower ( Report  report ) [inherited]

Get the power used by a report when it's operating, according to the IMU.

Parameters:
report
Returns:
Power used in mA.

Definition at line 461 of file BNO080.cpp.

int16_t getQ1 ( Report  report ) [protected, inherited]

Gets the Q point from a report's metadata, which essentially defines where the decimal point goes in the sensor's output.

The 1/2/3 Q values are used in different places in the metadata, see SH-2 section 5.1 for details.

Parameters:
report
Returns:

Definition at line 509 of file BNO080.cpp.

float getRange ( Report  report ) [inherited]

Gets the range of a report as reported by the IMU.

Units are the same as the report's output data.

Returns:

Definition at line 446 of file BNO080.cpp.

uint8_t getReportStatus ( Report  report ) [inherited]

Gets the status of a report as a 2 bit number.

per SH-2 section 6.5.1, this is interpreted as:
0 - unreliable
1 - accuracy low
2 - accuracy medium
3 - accuracy high
of course, these are only updated if a given report is enabled.

Parameters:
report
Returns:

Definition at line 367 of file BNO080.cpp.

const char * getReportStatusString ( Report  report ) [inherited]

Get a string for printout describing the status of a sensor.

Returns:

Definition at line 378 of file BNO080.cpp.

float getResolution ( Report  report ) [inherited]

Gets the resolution of a report as reported by the IMU.

Units are the same as the report's output data.

Parameters:
report
Returns:

Definition at line 454 of file BNO080.cpp.

uint32_t getSerialNumber (  ) [inherited]

Gets the serial number (used to uniquely identify each individual device).

NOTE: this function should work according to the datasheet, but the device I was testing with appears to have an empty serial number record as shipped, and I could never get anything out of it. Your mileage may vary.

Returns:
The serial number, or 0 on error.

Definition at line 434 of file BNO080.cpp.

bool hasNewData ( Report  report ) [inherited]

Checks if a specific report has gotten new data since the last call to this function.

Parameters:
reportThe report to check.
Returns:
Whether the report has received new data.

Definition at line 395 of file BNO080.cpp.

bool loadReportMetadata ( BNO080Base::Report  report ) [protected, inherited]

Loads the metadata for this report into the metadata buffer.

Parameters:
report
Returns:
Whether the operation succeeded.

Definition at line 1222 of file BNO080.cpp.

virtual void lockMutex (  ) [virtual, inherited]

No-op on synchronous driver.

For compatibility with BNO080Async

Reimplemented in BNO080Async.

Definition at line 488 of file BNO080.h.

void parseSensorDataPacket (  ) [protected, inherited]

Processes the sensor data packet currently stored in the buffer.

Only called from processPacket()

Definition at line 572 of file BNO080.cpp.

void printMetadataSummary ( Report  report ) [inherited]

Prints a summary of a report's metadata to the debug stream.

Should be useful for debugging and setting up reports since lots of this data isn't given in the datasheets.

Note: to save string constant space, this function is only available when BNO_DEBUG is 1.

Definition at line 490 of file BNO080.cpp.

void printPacket ( uint8_t *  buffer ) [protected, inherited]

Prints the current shtp packet stored in the buffer.

Parameters:
length

Definition at line 1174 of file BNO080.cpp.

void processPacket (  ) [protected, inherited]

Processes the packet currently stored in the buffer, and updates class variables to reflect the data it contains.

Definition at line 530 of file BNO080.cpp.

float qToFloat ( int16_t  fixedPointValue,
uint8_t  qPoint 
) [protected, inherited]

Given a Q value, converts fixed point floating to regular floating point number.

Parameters:
fixedPointValue
qPoint
Returns:

Definition at line 834 of file BNO080.cpp.

float qToFloat_dword ( uint32_t  fixedPointValue,
int16_t  qPoint 
) [protected, inherited]

Given a Q value, converts fixed point floating to regular floating point number.

This version is used for the unsigned 32-bit values in metadata records.

Parameters:
fixedPointValue
qPoint
Returns:

Definition at line 841 of file BNO080.cpp.

bool readFRSRecord ( uint16_t  recordID,
uint32_t *  readBuffer,
uint16_t  readLength 
) [protected, inherited]

Read a record from the FRS (Flash Record System) on the IMU.

FRS records are composed of 32-bit words, with the size of each record determined by the record type.

Will block until the entire record has been read.

Parameters:
recordIDRecord ID to read. See SH-2 figures 28 and 29 for a list of these. Sometimes also called the "FRS Type" by the datasheet (???).
readBufferBuffer to read data into.
readLengthAmount of words to read from the record. Must be <= the length of the record.
Returns:
whether the request succeeded

Definition at line 915 of file BNO080.cpp.

bool receiveCompletePacket ( size_t  bytesRead,
std::chrono::milliseconds  timeout = 200ms 
) [protected]

Assuming that at least a packet header has been read into the RX buffer, receive the remainder of the packet.

Parameters:
bytesReadThe number of bytes (including the header) of the packet that have already been read.
Returns:

Definition at line 1597 of file BNO080.cpp.

bool receivePacket ( std::chrono::milliseconds  timeout = 200ms ) [override, protected, virtual]

Reads a packet from the IMU and stores it in the class variables.

Parameters:
timeouthow long to wait for there to be a packet
Returns:
whether a packet was recieved.

Implements BNO080Base.

Definition at line 1575 of file BNO080.cpp.

bool saveCalibration (  ) [inherited]

Saves the calibration started with startCalibration() and ends the calibration.

You will want to call this once the status bits read as "accuracy high".

WARNING: if you paid for a factory calibrated IMU, then this WILL OVERWRITE THE FACTORY CALIBRATION in whatever sensors are being calibrated. Use with caution!

Returns:
whether the operation succeeded

Definition at line 260 of file BNO080.cpp.

void sendCommand ( uint8_t  command ) [protected, inherited]

Tell the sensor to do a command.

See SH-2 Reference Manual section 6.3.8 page 42, Command request The caller is expected to set shtpData 3 though 11 prior to calling

Definition at line 864 of file BNO080.cpp.

bool sendPacket ( uint8_t  channelNumber,
uint8_t  dataLength 
) [override, protected, virtual]

Sends the current shtpData contents to the BNO.

It's a good idea to disable interrupts before you call this.

Parameters:
channelNumberthe channel to send on
dataLengthHow many bits of shtpData to send
Returns:

Implements BNO080Base.

Definition at line 1507 of file BNO080.cpp.

void setFeatureCommand ( uint8_t  reportID,
uint16_t  timeBetweenReports,
uint32_t  specificConfig = 0 
) [protected, inherited]

Given a sensor's report ID, this tells the BNO080 to begin reporting the values.

Parameters:
reportID
timeBetweenReports
specificConfigthe specific config word. Useful for personal activity classifier.

Definition at line 887 of file BNO080.cpp.

bool setPermanentOrientation ( Quaternion  orientation ) [inherited]

Sets the orientation quaternion, telling the sensor how it's mounted in relation to world space.

See page 40 of the BNO080 datasheet.

Unlike setSensorOrientation(), this setting will persist across sensor restarts. However, it will also take a few hundred milliseconds to write.

Parameters:
orientationquaternion mapping from IMU space to world space.
Returns:
true if the operation succeeded, false if it failed.

Definition at line 328 of file BNO080.cpp.

void setSensorOrientation ( Quaternion  orientation ) [inherited]

Sets the orientation quaternion, telling the sensor how it's mounted in relation to world space.

See page 40 of the BNO080 datasheet.

NOTE: this driver provides the macro SQRT_2 to help with entering values from that table.

NOTE 2: this setting does not persist and will have to be re-applied every time the chip is reset. Use setPermanentOrientation() for that.

Parameters:
orientationquaternion mapping from IMU space to world space.

Definition at line 296 of file BNO080.cpp.

void spiTransferAndWait ( const uint8_t *  tx_buffer,
int  tx_length,
uint8_t *  rx_buffer,
int  rx_length 
) [protected]

Start an SPI transfer and wait for it to complete.

BNO080Async swaps in a threaded implementation here. API same as SPI::write().

Definition at line 921 of file BNO080.h.

void spiTransferAndWait ( const uint8_t *  tx_buffer,
int  tx_length,
uint8_t *  rx_buffer,
int  rx_length 
) [protected]

Start an SPI transfer and suspend the current thread until it is complete.

Used by functions in BNO080SPI. Note: should only be called by one thread at a time.

Parameters:
tx_buffer
tx_length
rx_buffer
rx_length

Definition at line 1685 of file BNO080.cpp.

void tare ( bool  zOnly = false ) [inherited]

Tells the IMU to use its current rotation vector as the "zero" rotation vector and to reorient all outputs accordingly.

Parameters:
zOnlyIf true, only the rotation about the Z axis (the heading) will be tared.

Definition at line 195 of file BNO080.cpp.

virtual void unlockMutex (  ) [virtual, inherited]

No-op on synchronous driver.

For compatibility with BNO080Async

Reimplemented in BNO080Async.

Definition at line 494 of file BNO080.h.

bool updateData (  ) [virtual, inherited]

Checks for new data packets queued on the IMU.

If there are packets queued, receives all of them and updates the class variables with the results.

Note that with some backends (SPI), sending commands will also update data, which can cause updateData() to return false even though new data has been received. hasNewData() is a more reliable way to determine if a sensor has new data.

Returns:
True iff new data packets of any kind were received. If you need more fine-grained data change reporting, check out hasNewData().

Reimplemented in BNO080Async.

Definition at line 341 of file BNO080.cpp.

bool waitForPacket ( int  channel,
uint8_t  reportID,
std::chrono::milliseconds  timeout = 125ms 
) [protected, virtual, inherited]

Call to wait for a packet with the given parameters to come in.

Note: on BNO080Async, the received packet data will stay in the RX buffer until either the public IMU function that was called returns, or you call sendPacket() or waitForPacket() again.

Parameters:
channelChannel of the packet
reportIDReport ID (first data byte) of the packet
timeouthow long to wait for the packet
Returns:
true if the packet has been received, false if it timed out

Definition at line 801 of file BNO080.cpp.

bool writeFRSRecord ( uint16_t  recordID,
uint32_t *  buffer,
uint16_t  length 
) [protected, inherited]

Write a record to the FRS (Flash Record System) on the IMU.

FRS records are composed of 32-bit words, with the size of each record determined by the record type.

Will block until the entire record has been written.

Parameters:
recordIDRecord ID to write. See SH-2 figures 28 and 29 for a list of these. Sometimes also called the "FRS Type" by the datasheet (???).
bufferBuffer to write data into.
lengthAmount of words to write to the record. Must be <= the length of the record.
Returns:
whether the request succeeded

Definition at line 1024 of file BNO080.cpp.


Field Documentation

Stream* _debugPort [protected, inherited]

Serial stream to print debug info to.

Used for errors, and debugging output if debugging is enabled.

Definition at line 55 of file BNO080.h.

InterruptIn _int [protected, inherited]

Interrupt pin -- signals to the host that the IMU has data to send.

Definition at line 60 of file BNO080.h.

SPI _spiPort [protected]

I2C port object.

Provides physical layer communications with the chip.

Definition at line 853 of file BNO080.h.

int _spiSpeed [protected]

user defined port speed

Definition at line 859 of file BNO080.h.

uint16_t bufferMetadataRecord [protected, inherited]

Record ID of the metadata record currently stored in the metadataRecord[] buffer.

Used so that we can avoid requerying the FRS record if we need to make multiple metadata reads in succession.

Definition at line 107 of file BNO080.h.

uint8_t commandSequenceNumber [protected, inherited]

Commands have a seqNum as well. These are inside command packet, the header uses its own seqNum per channel.

Definition at line 99 of file BNO080.h.

bool doubleTap [inherited]

Whether the last tap detected was a single or double tap.

Definition at line 325 of file BNO080.h.

Quaternion gameRotationVector [inherited]

Readout from the Game Rotation Vector report.

Represents the rotation of the IMU in radians. Unlike the regular rotation vector, the Game Rotation Vector is not referenced against the magnetic field and the "zero yaw" point is arbitrary.

Definition at line 302 of file BNO080.h.

float geomagneticRotationAccuracy [inherited]

Auxiliary accuracy readout from the Geomagnetic Rotation Vector report.

Represents the estimated accuracy of the rotation vector in radians.

Definition at line 314 of file BNO080.h.

Quaternion geomagneticRotationVector [inherited]

Readout from the Geomagnetic Rotation Vector report.

Represents the geomagnetic rotation of the IMU (relative to magnetic north) in radians.

Definition at line 308 of file BNO080.h.

Readout from Gravity report.

Represents the force of gravity in m/s^2 felt by the BNO's accelerometer.

Definition at line 259 of file BNO080.h.

TVector3 gyroRotation [inherited]

Readout from Calibrated Gyroscope report Represents the angular velocities of the chip in rad/s in the X, Y, and Z axes.

Definition at line 265 of file BNO080.h.

TVector3 hardIronOffset [inherited]

Auxiliary readout from the Magnetic Field Uncalibrated report.

Represents the hard iron offsets that the chip is using in each axis in uT.

Definition at line 283 of file BNO080.h.

Readout from Linear Acceleration report.

Represents acceleration felt in m/s^2 by the BNO's accelerometer not including the force of gravity.

Definition at line 253 of file BNO080.h.

TVector3 magField [inherited]

Readout from the Magnetic Field Calibrated report.

Represents the magnetic field read by the chip in uT in the X, Y, and Z axes

Definition at line 271 of file BNO080.h.

Readout from the Magnetic Field Uncalibrated report.

Represents the magnetic field read by the chip in uT in the X, Y, and Z axes, without hard iron offsets applied

Definition at line 277 of file BNO080.h.

uint8_t majorSoftwareVersion [inherited]

Version info read from the IMU when it starts up.

Definition at line 235 of file BNO080.h.

uint32_t metadataRecord[METADATA_BUFFER_LEN] [protected, inherited]

Buffer for current metadata record.

Definition at line 113 of file BNO080.h.

bool reportHasBeenUpdated[STATUS_ARRAY_LEN] [protected, inherited]

stores whether a sensor has been updated since the last call to hasNewData()

Definition at line 125 of file BNO080.h.

uint8_t reportStatus[STATUS_ARRAY_LEN] [protected, inherited]

stores status of each sensor, indexed by report ID

Definition at line 122 of file BNO080.h.

float rotationAccuracy [inherited]

Auxiliary accuracy readout from the Rotation Vector report.

Represents the estimated accuracy of the rotation vector in radians.

Definition at line 295 of file BNO080.h.

Quaternion rotationVector [inherited]

Readout from the Rotation Vector report.

Represents the rotation of the IMU (relative to magnetic north) in radians.

Definition at line 289 of file BNO080.h.

uint16_t rxPacketLength [protected, inherited]

Length of packet that was received into buffer. Does NOT include header bytes.

Definition at line 93 of file BNO080.h.

uint8_t sequenceNumber[6] [protected, inherited]

Current sequence number for each channel, incremented after transmission.

Definition at line 96 of file BNO080.h.

bool shakeDetected [inherited]

Readout from the Shake Detector report.

This flag is set to true whenever shaking is detected, and you should manually clear it when you have processed the event.

Definition at line 379 of file BNO080.h.

bool significantMotionDetected [inherited]

Readout from the Significant Motion Detector report.

This flag is set to true whenever significant motion is detected, and you should manually clear it when you have processed the event.

Definition at line 373 of file BNO080.h.

Stability stability [inherited]

Readout from the stability classifier.

Current stability status of the IMU.

Definition at line 355 of file BNO080.h.

uint16_t stepCount [inherited]

Readout from the Step Counter report.

This count increases as the user takes steps, but can also decrease if the IMU decides that a motion was not a step.

Definition at line 367 of file BNO080.h.

bool stepDetected [inherited]

Readout from the Step Detector report.

This flag is set to true whenever a step is detected, and you should manually clear it when you have processed the step.

Definition at line 361 of file BNO080.h.

bool tapDetected [inherited]

Tap readout from the Tap Detector report.

This flag is set to true whenever a tap is detected, and you should manually clear it when you have processed the tap.

Definition at line 320 of file BNO080.h.

Readout from Accleration report.

Represents total acceleration in m/s^2 felt by the BNO's accelerometer.

Definition at line 247 of file BNO080.h.

uint8_t* txShtpData = txPacketBuffer + SHTP_HEADER_SIZE [protected, inherited]

Stores data contained in each packet.

Packets can contain an arbitrary amount of data, but rarely get over a hundred bytes unless you have a million sensor reports enabled. The only long packets we actually care about are batched sensor data packets.

Definition at line 89 of file BNO080.h.

uint8_t* txShtpHeader = txPacketBuffer [protected, inherited]

Each SHTP packet starts with a header of 4 uint8_ts.

Definition at line 83 of file BNO080.h.

bool xAxisShake [inherited]

The axis/axes that shaking was detected in in the latest shaking report.

Definition at line 383 of file BNO080.h.