upm  1.7.1
Sensor/Actuator repository for libmraa (v2.0.0)
Public Member Functions | Protected Member Functions | Protected Attributes

API for the BNO055 Absolute Orientation 9DOF Fusion Hub. More...

Detailed Description

The BNO055 is a System in Package (SiP), integrating a triaxial 14-bit accelerometer, a triaxial 16-bit gyroscope with a range of +/- 2000 degrees per second, a triaxial geomagnetic sensor and a 32-bit cortex M0+ microcontroller running Bosch Sensortec sensor fusion software, in a single package.

This sensor handles the hard problem of combining various sensor information into a reliable measurement of sensor orientation (refered to as 'sensor fusion'). The onboard MCU runs this software and can provide fusion output in the form of Euler Angles, Quaternions, Linear Acceleration, and Gravity Vectors in 3 axes.

The focus on this driver has been on supporting the fusion components. Less support is available for use of this device as a generic accelerometer, gyroscope and magnetometer, however enough infrastructure is available to add any missing functionality.

This device requires calibration in order to operate accurately. Methods are provided to retrieve calibration data (once calibrated) to be stored somewhere else, like in a file. A method is provided to load this data as well. Calibration data is lost on a power cycle. See one of the examples for a description of how to calibrate the device, but in essence:

There is a calibration status register available (getCalibrationStatus()) that returns the calibration status of the accelerometer (ACC), magnetometer (MAG), gyroscope (GYR), and overall system (SYS). Each of these values range from 0 (uncalibrated) to 3 (fully calibrated). Calibration involves certain motions to get all 4 values at 3. The motions are as follows (though see the datasheet for more information):

GYR: Simply let the sensor sit flat for a few seconds.

ACC: Move the sensor in various positions. Start flat, then rotate slowly by 45 degrees, hold for a few seconds, then continue rotating another 45 degrees and hold, etc. 6 or more movements of this type may be required. You can move through any axis you desire, but make sure that the device is lying at least once perpendicular to the x, y, and z axis.

MAG: Move slowly in a figure 8 pattern in the air, until the calibration values reaches 3.

SYS: This will usually reach 3 when the other items have also reached 3. If not, continue slowly moving the device though various axes until it does.

// Instantiate an BNO055 using default parameters (bus 0, addr
// 0x28). The default running mode is NDOF absolute orientation
// mode.
upm::BNO055 sensor;
// First we need to calibrate....
cout << "First we need to calibrate. 4 numbers will be output every" << endl;
cout << "second for each sensor. 0 means uncalibrated, and 3 means" << endl;
cout << "fully calibrated." << endl;
cout << "See the UPM documentation on this sensor for instructions on" << endl;
cout << "what actions are required to calibrate." << endl;
cout << endl;
// do the calibration...
while (shouldRun && !sensor.isFullyCalibrated()) {
int mag, acc, gyr, sys;
sensor.getCalibrationStatus(&mag, &acc, &gyr, &sys);
cout << "Magnetometer: " << mag << " Accelerometer: " << acc << " Gyroscope: " << gyr
<< " System: " << sys << endl;
upm_delay(1);
}
cout << endl;
cout << "Calibration complete." << endl;
cout << endl;
// now output various fusion data every 250 milliseconds
while (shouldRun) {
float w, x, y, z;
sensor.update();
sensor.getEulerAngles(&x, &y, &z);
cout << "Euler: Heading: " << x << " Roll: " << y << " Pitch: " << z << " degrees" << endl;
sensor.getQuaternions(&w, &x, &y, &z);
cout << "Quaternion: W: " << w << " X: " << x << " Y: " << y << " Z: " << z << endl;
sensor.getLinearAcceleration(&x, &y, &z);
cout << "Linear Acceleration: X: " << x << " Y: " << y << " Z: " << z << " m/s^2" << endl;
sensor.getGravityVectors(&x, &y, &z);
cout << "Gravity Vector: X: " << x << " Y: " << y << " Z: " << z << " m/s^2" << endl;
cout << endl;
upm_delay_us(250000);
}

Public Member Functions

 BNO055 (int bus=BNO055_DEFAULT_I2C_BUS, uint8_t addr=BNO055_DEFAULT_ADDR)
 
virtual ~BNO055 ()
 
void update ()
 
uint8_t getChipID ()
 
uint8_t getACCID ()
 
uint8_t getMAGID ()
 
uint8_t getGYRID ()
 
uint16_t getSWRevID ()
 
uint8_t getBootLoaderID ()
 
void setClockExternal (bool extClock)
 
void setTemperatureSource (BNO055_TEMP_SOURCES_T src)
 
void setOperationMode (BNO055_OPERATION_MODES_T mode)
 
void resetSystem ()
 
void getCalibrationStatus (int *mag, int *acc, int *gyr, int *sys)
 
std::vector< int > getCalibrationStatus ()
 
bool isFullyCalibrated ()
 
std::vector< uint8_t > readCalibrationData ()
 
void writeCalibrationData (std::vector< uint8_t > calibrationData)
 
float getTemperature (bool fahrenheit=false)
 
void getEulerAngles (float *heading, float *roll, float *pitch)
 
std::vector< float > getEulerAngles ()
 
void getQuaternions (float *w, float *x, float *y, float *z)
 
std::vector< float > getQuaternions ()
 
void getLinearAcceleration (float *x, float *y, float *z)
 
std::vector< float > getLinearAcceleration ()
 
void getGravityVectors (float *x, float *y, float *z)
 
std::vector< float > getGravityVectors ()
 
void getAccelerometer (float *x, float *y, float *z)
 
std::vector< float > getAccelerometer ()
 
void getMagnetometer (float *x, float *y, float *z)
 
std::vector< float > getMagnetometer ()
 
void getGyroscope (float *x, float *y, float *z)
 
std::vector< float > getGyroscope ()
 
void setAccelerationConfig (BNO055_ACC_RANGE_T range, BNO055_ACC_BW_T bw, BNO055_ACC_PWR_MODE_T pwr)
 
void setMagnetometerConfig (BNO055_MAG_ODR_T odr, BNO055_MAG_OPR_T opr, BNO055_MAG_POWER_T pwr)
 
void setGyroscopeConfig (BNO055_GYR_RANGE_T range, BNO055_GYR_BW_T bw, BNO055_GYR_POWER_MODE_T pwr)
 
void setAccelerometerUnits (bool mg=false)
 
void setGyroscopeUnits (bool radians=false)
 
void setEulerUnits (bool radians=false)
 
void resetInterruptStatus ()
 
uint8_t getInterruptStatus ()
 
uint8_t getInterruptEnable ()
 
void setInterruptEnable (uint8_t enables)
 
uint8_t getInterruptMask ()
 
void setInterruptMask (uint8_t mask)
 
BNO055_SYS_STATUS_T getSystemStatus ()
 
BNO055_SYS_ERR_T getSystemError ()
 
void installISR (int gpio, mraa_gpio_edge_t level, void(*isr)(void *), void *arg)
 
void uninstallISR ()
 

Protected Member Functions

void setPage (uint8_t page, bool force=false)
 
uint8_t readReg (uint8_t reg)
 
void readRegs (uint8_t reg, uint8_t *buffer, int len)
 
void writeReg (uint8_t reg, uint8_t val)
 
void writeRegs (uint8_t reg, uint8_t *buffer, int len)
 

Protected Attributes

bno055_context m_bno055
 

Constructor & Destructor Documentation

BNO055 ( int  bus = BNO055_DEFAULT_I2C_BUS,
uint8_t  addr = BNO055_DEFAULT_ADDR 
)

BNO055 constructor.

By default, the constructor sets the acceleration units to m/s^2, gyro and Euler units to degrees, and temperature to celsius. It then enters the NDOF fusion mode.

In addition, the internal clock is used so that compatibility with other implementations is assured. If you are using a device with an external clock, call setClockExternal(true) to enable it.

Parameters
busI2C bus to use.
addressThe address for this device.
Exceptions
std::runtime_erroron initialization failure.
~BNO055 ( )
virtual

BNO055 Destructor.

Here is the call graph for this function:

Member Function Documentation

void update ( void  )

Update the internal stored values from sensor data.

Exceptions
std::runtime_erroron failure.

Here is the call graph for this function:

uint8_t getChipID ( )

Return the chip ID.

Returns
The chip ID (BNO055_CHIPID).
Exceptions
std::runtime_erroron failure.

Here is the call graph for this function:

uint8_t getACCID ( )

Return the accelerometer chip ID.

Returns
The chip ID.
Exceptions
std::runtime_erroron failure.

Here is the call graph for this function:

uint8_t getMAGID ( )

Return the magnetometer chip ID.

Returns
The chip ID.
Exceptions
std::runtime_erroron failure.

Here is the call graph for this function:

uint8_t getGYRID ( )

Return the gyroscope chip ID.

Returns
The chip ID.
Exceptions
std::runtime_erroron failure.

Here is the call graph for this function:

uint16_t getSWRevID ( )

Return the fusion firmware revison.

Returns
The firmware revison.
Exceptions
std::runtime_erroron failure.

Here is the call graph for this function:

uint8_t getBootLoaderID ( )

Return the bootloader ID.

Returns
The bootloader ID.
Exceptions
std::runtime_erroron failure.

Here is the call graph for this function:

void setClockExternal ( bool  extClock)

Enable or disables the use of the external clock. The Adafruit device does contain an external clock which might be more stable. By default, the internal clock is used.

Parameters
extClocktrue to use external clock, false otherwise.
Exceptions
std::runtime_erroron failure.

Here is the call graph for this function:

void setTemperatureSource ( BNO055_TEMP_SOURCES_T  src)

Select the temperature source. This can be the accelerometer or the gyroscope. By default, the accelerometer temperature is used as the source.

Parameters
srcOne of the BNO055_TEMP_SOURCES_T values.
Exceptions
std::runtime_erroron failure.

Here is the call graph for this function:

void setOperationMode ( BNO055_OPERATION_MODES_T  mode)

Set the operating mode for the device. This places the device into a config mode, one of 7 non-fusion modes, or one of 5 fusion modes. All stored sensor data is cleared when switching modes. The device must be in config mode for most configuration operations. See the datasheet for details.

Parameters
modeOne of the BNO055_OPERATION_MODES_T values.
Exceptions
std::runtime_erroron failure.

Here is the call graph for this function:

void resetSystem ( )

Reboot the sensor. This is equivalent to a power on reset. All calibration data will be lost, and the device must be recalibrated.

Exceptions
std::runtime_erroron failure.

Here is the call graph for this function:

void getCalibrationStatus ( int *  mag,
int *  acc,
int *  gyr,
int *  sys 
)

Read the calibration status registers and return them. The values range from 0 (uncalibrated) to 3 (fully calibrated).

Parameters
magThe calibration status of the magnetometer.
accThe calibration status of the accelerometer.
magThe calibration status of the gyroscope.
magThe calibration status of the overall system.
Exceptions
std::runtime_erroron failure.

Here is the call graph for this function:

vector< int > getCalibrationStatus ( )

Read the calibration status registers and return them as an integer vector. The values range from 0 (uncalibrated) to 3 (fully calibrated).

Returns
An integer vector containing the values in the order: mag, acc, gyr, and sys.
Exceptions
std::runtime_erroron failure.
bool isFullyCalibrated ( )

Read the calibration status registers and return true or false, indicating whether all of the calibration parameters are fully calibrated.

Returns
True if all 4 calibration parameters are fully calibrated, else false.

Here is the call graph for this function:

std::vector< uint8_t > readCalibrationData ( )

Read the calibration data and return it as a string. This data can then be saved for later reuse by writeCalibrationData() to restore calibration data after a reset. The sensor must be fully calibrated before calibration data can be read.

Returns
A vector of uint8_t's representing the calibration data. This vector will always be exactly BNO055_CALIBRATION_DATA_SIZE in size.
Exceptions
std::runtime_errorif an error occurs.

Here is the call graph for this function:

void writeCalibrationData ( std::vector< uint8_t >  calibrationData)

Write previously saved calibration data to the calibration registers.

Parameters
calibrationDataA vector of uint8_t (bytes) representing calibration data as returned by readCalibrationData(). It's length must always be exactly BNO055_CALIBRATION_DATA_SIZE.
Exceptions
std::length_errorif the vector size is not equal to BNO055_CALIBRATION_DATA_SIZE.

Here is the call graph for this function:

float getTemperature ( bool  fahrenheit = false)

Return the current measured temperature. Note, this is not ambient temperature - this is the temperature of the selected source on the chip. update() must have been called prior to calling this method.

Parameters
fahrenheittrue to return data in Fahrenheit, false for Celicus. Celsius is the default.
Returns
The temperature in degrees Celsius or Fahrenheit.

Here is the call graph for this function:

void getEulerAngles ( float *  heading,
float *  roll,
float *  pitch 
)

Return current orientation fusion data in the form of Euler Angles. By default, the returned values are in degrees. update() must have been called prior to calling this method.

Parameters
headingPointer to a floating point value that will have the current heading angle placed into it.
rollPointer to a floating point value that will have the current roll angle placed into it.
pitchPointer to a floating point value that will have the current pitch angle placed into it.

Here is the call graph for this function:

vector< float > getEulerAngles ( )

Return current orientation fusion data in the form of Euler Angles as a floating point vector. By default, the returned values are in degrees. update() must have been called prior to calling this method.

Returns
A floating point vector containing heading, roll, and pitch, in that order.
void getQuaternions ( float *  w,
float *  x,
float *  y,
float *  z 
)

Return current orientation fusion data in the form of Quaternions. update() must have been called prior to calling this method.

Parameters
wPointer to a floating point value that will have the current w component placed into it.
xPointer to a floating point value that will have the current x component placed into it.
yPointer to a floating point value that will have the current y component placed into it.
zPointer to a floating point value that will have the current z component placed into it.

Here is the call graph for this function:

vector< float > getQuaternions ( )

Return current orientation fusion data in the form of Quaternions, as a floating point vector. update() must have been called prior to calling this method.

Returns
A floating point vector containing w, x, y, and z in that order.
void getLinearAcceleration ( float *  x,
float *  y,
float *  z 
)

Return current orientation fusion data in the form of Linear Acceleration. By default the returned values are in meters per-second squared (m/s^2). update() must have been called prior to calling this method.

Parameters
xPointer to a floating point value that will have the current x component placed into it.
yPointer to a floating point value that will have the current y component placed into it.
zPointer to a floating point value that will have the current z component placed into it.

Here is the call graph for this function:

vector< float > getLinearAcceleration ( )

Return current orientation fusion data in the form of Linear Acceleration, as a floating point vector. update() must have been called prior to calling this method.

Returns
A floating point vector containing x, y, and z in that order.
void getGravityVectors ( float *  x,
float *  y,
float *  z 
)

Return current orientation fusion data in the form of a Gravity Vector per-axis. By default the returned values are in meters per-second squared (m/s^2). update() must have been called prior to calling this method.

Parameters
xPointer to a floating point value that will have the current x component placed into it.
yPointer to a floating point value that will have the current y component placed into it.
zPointer to a floating point value that will have the current z component placed into it.

Here is the call graph for this function:

vector< float > getGravityVectors ( )

Return current orientation fusion data in the form of a Gravity Vector per-axis as a floating point vector. update() must have been called prior to calling this method.

Returns
A floating point vector containing x, y, and z in that order.
void getAccelerometer ( float *  x,
float *  y,
float *  z 
)

Return uncompensated accelerometer data (non-fusion). In fusion modes, this data will be of little value. By default the returned values are in meters per-second squared (m/s^2). update() must have been called prior to calling this method.

Parameters
xPointer to a floating point value that will have the current x component placed into it.
yPointer to a floating point value that will have the current y component placed into it.
zPointer to a floating point value that will have the current z component placed into it.

Here is the call graph for this function:

vector< float > getAccelerometer ( )

Return current uncompensated accelerometer (non-fusion) data in the form of a floating point vector. By default the returned values are in meters per-second squared (m/s^2). update() must have been called prior to calling this method.

Returns
A floating point vector containing x, y, and z in that order.
void getMagnetometer ( float *  x,
float *  y,
float *  z 
)

Return uncompensated magnetometer data (non-fusion). In fusion modes, this data will be of little value. The returned values are in micro-teslas (uT). update() must have been called prior to calling this method.

Parameters
xPointer to a floating point value that will have the current x component placed into it.
yPointer to a floating point value that will have the current y component placed into it.
zPointer to a floating point value that will have the current z component placed into it.

Here is the call graph for this function:

vector< float > getMagnetometer ( )

Return current uncompensated magnetometer (non-fusion) data in the form of a floating point vector. The returned values are in micro-teslas (uT). update() must have been called prior to calling this method.

Returns
A floating point vector containing x, y, and z in that order.
void getGyroscope ( float *  x,
float *  y,
float *  z 
)

Return uncompensated gyroscope data (non-fusion). In fusion modes, this data will be of little value. By default the returned values are in meters per-second squared (m/s^2). update() must have been called prior to calling this method.

Parameters
xPointer to a floating point value that will have the current x component placed into it.
yPointer to a floating point value that will have the current y component placed into it.
zPointer to a floating point value that will have the current z component placed into it.

Here is the call graph for this function:

vector< float > getGyroscope ( )

Return current uncompensated gyroscope (non-fusion) data in the form of a floating point vector. By default the returned values are in meters per-second squared (m/s^2). update() must have been called prior to calling this method.

Returns
A floating point vector containing x, y, and z in that order.
void setAccelerationConfig ( BNO055_ACC_RANGE_T  range,
BNO055_ACC_BW_T  bw,
BNO055_ACC_PWR_MODE_T  pwr 
)

Set the bandwidth, range, and power modes of the accelerometer. In fusion modes, these values will be ignored.

Parameters
rangeOne of the BNO055_ACC_RANGE_T values.
bwOne of the BNO055_ACC_BW_T values.
pwrOne of the BNO055_ACC_PWR_MODE_T values.
Exceptions
std::runtime_erroron failure.

Here is the call graph for this function:

void setMagnetometerConfig ( BNO055_MAG_ODR_T  odr,
BNO055_MAG_OPR_T  opr,
BNO055_MAG_POWER_T  pwr 
)

Set the output data rate, operating mode and power mode of the magnetometer. In fusion modes, these values will be ignored.

Parameters
odrOne of the BNO055_MAG_ODR_T values.
oprOne of the BNO055_MAG_OPR_T values.
pwrOne of the BNO055_MAG_POWER_T values.
Exceptions
std::runtime_erroron failure.

Here is the call graph for this function:

void setGyroscopeConfig ( BNO055_GYR_RANGE_T  range,
BNO055_GYR_BW_T  bw,
BNO055_GYR_POWER_MODE_T  pwr 
)

Set the range, bandwidth and power modes of the gyroscope. In fusion modes, these values will be ignored.

Parameters
rangeOne of the BNO055_GYR_RANGE_T values.
bwOne of the BNO055_GYR_BW_T values.
pwrOne of the BNO055_GYR_POWER_MODE_T values.
Exceptions
std::runtime_erroron failure.

Here is the call graph for this function:

void setAccelerometerUnits ( bool  mg = false)

Set the unit of measurement for the accelerometer related sensor values. The choices are mg (milligravities) or meters per-second squared (m/s^2). The default is m/s^2.

Parameters
mgtrue for mg, false for m/s^2.
Exceptions
std::runtime_erroron failure.

Here is the call graph for this function:

void setGyroscopeUnits ( bool  radians = false)

Set the unit of measurement for the gyroscope related sensor values. The choices are degrees and radians. The default is degrees.

Parameters
radianstrue for radians, false for degrees.
Exceptions
std::runtime_erroron failure.

Here is the call graph for this function:

void setEulerUnits ( bool  radians = false)

Set the unit of measurement for the Euler Angle related sensor values. The choices are degrees and radians. The default is degrees.

Parameters
radianstrue for radians, false for degrees.
Exceptions
std::runtime_erroron failure.

Here is the call graph for this function:

void resetInterruptStatus ( )

Reset all interrupt status bits and interrupt output.

Exceptions
std::runtime_erroron failure.

Here is the call graph for this function:

uint8_t getInterruptStatus ( )

Return the interrupt status register. This is a bitmask of the BNO055_INT_STA_BITS_T bits.

Returns
a bitmask of BNO055_INT_STA_BITS_T bits.
Exceptions
std::runtime_erroron failure.

Here is the call graph for this function:

uint8_t getInterruptEnable ( )

Return the interrupt enables register. This is a bitmask of the BNO055_INT_STA_BITS_T bits.

Returns
a bitmask of BNO055_INT_STA_BITS_T bits currently set in the enable register.
Exceptions
std::runtime_erroron failure.

Here is the call graph for this function:

void setInterruptEnable ( uint8_t  enables)

Set the interrupt enable register. This is composed of a bitmask of the BNO055_INT_STA_BITS_T bits.

Parameters
enablesa bitmask of BNO055_INT_STA_BITS_T bits to enable
Exceptions
std::runtime_erroron failure.

Here is the call graph for this function:

uint8_t getInterruptMask ( )

Return the interrupt mask register. This is a bitmask of the BNO055_INT_STA_BITS_T bits. The interrupt mask is used to mask off enabled interrupts from generating a hardware interrupt. The interrupt status register can still be used to detect masked interrupts if they are enabled.

Returns
a bitmask of BNO055_INT_STA_BITS_T bits currently set in the interrupt mask register.
Exceptions
std::runtime_erroron failure.

Here is the call graph for this function:

void setInterruptMask ( uint8_t  mask)

Set the interrupt mask register. This is a bitmask of the BNO055_INT_STA_BITS_T bits. The interrupt mask is used to mask off enabled interrupts from generating a hardware interrupt. The interrupt status register can still be used to detect masked interrupts if they are enabled.

Parameters
maskA bitmask of BNO055_INT_STA_BITS_T bits to set in the interrupt mask register.
Exceptions
std::runtime_erroron failure.

Here is the call graph for this function:

BNO055_SYS_STATUS_T getSystemStatus ( )

Return the value of the system status register. This method can be used to determine the overall status of the device.

Returns
One of the BNO055_SYS_STATUS_T values.
Exceptions
std::runtime_erroron failure.

Here is the call graph for this function:

BNO055_SYS_ERR_T getSystemError ( )

Return the value of the system error register. This mathod can be used to determine a variety of system related error conditions.

Returns
One of the BNO055_SYS_ERR_T values.
Exceptions
std::runtime_erroron failure.

Here is the call graph for this function:

void installISR ( int  gpio,
mraa_gpio_edge_t  level,
void(*)(void *)  isr,
void *  arg 
)

install an interrupt handler.

Parameters
gpiogpio pin to use as interrupt pin
levelthe interrupt trigger level (one of mraa_gpio_edge_t values). Make sure that you have configured the interrupt pin properly for whatever level you choose.
isrthe interrupt handler, accepting a void * argument
argthe argument to pass the the interrupt handler
Exceptions
std::runtime_erroron failure.

Here is the call graph for this function:

void uninstallISR ( )

uninstall a previously installed interrupt handler

Here is the call graph for this function:

void setPage ( uint8_t  page,
bool  force = false 
)
protected

Set the current internal device register page. This is a low level function and should not be used unless you know what you are doing.

Parameters
devThe device context.
pageThe page number to set. This can only be 0 or 1.
forceIf true, force the device page state to match indicated internal page state regardless of current state.
Exceptions
std::runtime_erroron failure.

Here is the call graph for this function:

uint8_t readReg ( uint8_t  reg)
protected

Read a register.

Parameters
regThe register to read
Returns
The value of the register
Exceptions
std::runtime_erroron failure.

Here is the call graph for this function:

void readRegs ( uint8_t  reg,
uint8_t *  buffer,
int  len 
)
protected

Read contiguous registers into a buffer.

Parameters
bufferThe buffer to store the results
lenThe number of registers to read
Exceptions
std::runtime_erroron failure.

Here is the call graph for this function:

void writeReg ( uint8_t  reg,
uint8_t  val 
)
protected

Write to a register

Parameters
regThe register to write to
valThe value to write
Exceptions
std::runtime_erroron failure.

Here is the call graph for this function:

void writeRegs ( uint8_t  reg,
uint8_t *  buffer,
int  len 
)
protected

Write data to contiguous registers

Parameters
regThe starting register to write to
bufferThe buffer containing the data to write
lenThe number of bytes to write
Exceptions
std::runtime_erroron failure.

Here is the call graph for this function:

Collaboration diagram for BNO055:
Collaboration graph
[legend]

The documentation for this class was generated from the following files: