upm
1.7.1
Sensor/Actuator repository for libmraa (v2.0.0)
|
API for the BNO055 Absolute Orientation 9DOF Fusion Hub. More...
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.
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 |
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.
bus | I2C bus to use. |
address | The address for this device. |
std::runtime_error | on initialization failure. |
void update | ( | void | ) |
Update the internal stored values from sensor data.
std::runtime_error | on failure. |
uint8_t getChipID | ( | ) |
Return the chip ID.
std::runtime_error | on failure. |
uint8_t getACCID | ( | ) |
Return the accelerometer chip ID.
std::runtime_error | on failure. |
uint8_t getMAGID | ( | ) |
Return the magnetometer chip ID.
std::runtime_error | on failure. |
uint8_t getGYRID | ( | ) |
Return the gyroscope chip ID.
std::runtime_error | on failure. |
uint16_t getSWRevID | ( | ) |
Return the fusion firmware revison.
std::runtime_error | on failure. |
uint8_t getBootLoaderID | ( | ) |
Return the bootloader ID.
std::runtime_error | on failure. |
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.
extClock | true to use external clock, false otherwise. |
std::runtime_error | on failure. |
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.
src | One of the BNO055_TEMP_SOURCES_T values. |
std::runtime_error | on failure. |
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.
mode | One of the BNO055_OPERATION_MODES_T values. |
std::runtime_error | on failure. |
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.
std::runtime_error | on failure. |
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).
mag | The calibration status of the magnetometer. |
acc | The calibration status of the accelerometer. |
mag | The calibration status of the gyroscope. |
mag | The calibration status of the overall system. |
std::runtime_error | on failure. |
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).
std::runtime_error | on failure. |
bool isFullyCalibrated | ( | ) |
Read the calibration status registers and return true or false, indicating whether all of the calibration parameters are fully calibrated.
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.
std::runtime_error | if an error occurs. |
void writeCalibrationData | ( | std::vector< uint8_t > | calibrationData | ) |
Write previously saved calibration data to the calibration registers.
calibrationData | A vector of uint8_t (bytes) representing calibration data as returned by readCalibrationData(). It's length must always be exactly BNO055_CALIBRATION_DATA_SIZE. |
std::length_error | if the vector size is not equal to BNO055_CALIBRATION_DATA_SIZE. |
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.
fahrenheit | true to return data in Fahrenheit, false for Celicus. Celsius is the default. |
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.
heading | Pointer to a floating point value that will have the current heading angle placed into it. |
roll | Pointer to a floating point value that will have the current roll angle placed into it. |
pitch | Pointer to a floating point value that will have the current pitch angle placed into it. |
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.
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.
w | Pointer to a floating point value that will have the current w component placed into it. |
x | Pointer to a floating point value that will have the current x component placed into it. |
y | Pointer to a floating point value that will have the current y component placed into it. |
z | Pointer to a floating point value that will have the current z component placed into it. |
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.
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.
x | Pointer to a floating point value that will have the current x component placed into it. |
y | Pointer to a floating point value that will have the current y component placed into it. |
z | Pointer to a floating point value that will have the current z component placed into it. |
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.
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.
x | Pointer to a floating point value that will have the current x component placed into it. |
y | Pointer to a floating point value that will have the current y component placed into it. |
z | Pointer to a floating point value that will have the current z component placed into it. |
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.
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.
x | Pointer to a floating point value that will have the current x component placed into it. |
y | Pointer to a floating point value that will have the current y component placed into it. |
z | Pointer to a floating point value that will have the current z component placed into it. |
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.
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.
x | Pointer to a floating point value that will have the current x component placed into it. |
y | Pointer to a floating point value that will have the current y component placed into it. |
z | Pointer to a floating point value that will have the current z component placed into it. |
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.
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.
x | Pointer to a floating point value that will have the current x component placed into it. |
y | Pointer to a floating point value that will have the current y component placed into it. |
z | Pointer to a floating point value that will have the current z component placed into it. |
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.
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.
range | One of the BNO055_ACC_RANGE_T values. |
bw | One of the BNO055_ACC_BW_T values. |
pwr | One of the BNO055_ACC_PWR_MODE_T values. |
std::runtime_error | on failure. |
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.
odr | One of the BNO055_MAG_ODR_T values. |
opr | One of the BNO055_MAG_OPR_T values. |
pwr | One of the BNO055_MAG_POWER_T values. |
std::runtime_error | on failure. |
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.
range | One of the BNO055_GYR_RANGE_T values. |
bw | One of the BNO055_GYR_BW_T values. |
pwr | One of the BNO055_GYR_POWER_MODE_T values. |
std::runtime_error | on failure. |
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.
mg | true for mg, false for m/s^2. |
std::runtime_error | on failure. |
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.
radians | true for radians, false for degrees. |
std::runtime_error | on failure. |
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.
radians | true for radians, false for degrees. |
std::runtime_error | on failure. |
void resetInterruptStatus | ( | ) |
Reset all interrupt status bits and interrupt output.
std::runtime_error | on failure. |
uint8_t getInterruptStatus | ( | ) |
Return the interrupt status register. This is a bitmask of the BNO055_INT_STA_BITS_T bits.
std::runtime_error | on failure. |
uint8_t getInterruptEnable | ( | ) |
Return the interrupt enables register. This is a bitmask of the BNO055_INT_STA_BITS_T bits.
std::runtime_error | on failure. |
void setInterruptEnable | ( | uint8_t | enables | ) |
Set the interrupt enable register. This is composed of a bitmask of the BNO055_INT_STA_BITS_T bits.
enables | a bitmask of BNO055_INT_STA_BITS_T bits to enable |
std::runtime_error | on failure. |
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.
std::runtime_error | on failure. |
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.
mask | A bitmask of BNO055_INT_STA_BITS_T bits to set in the interrupt mask register. |
std::runtime_error | on failure. |
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.
std::runtime_error | on failure. |
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.
std::runtime_error | on failure. |
void installISR | ( | int | gpio, |
mraa_gpio_edge_t | level, | ||
void(*)(void *) | isr, | ||
void * | arg | ||
) |
install an interrupt handler.
gpio | gpio pin to use as interrupt pin |
level | the 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. |
isr | the interrupt handler, accepting a void * argument |
arg | the argument to pass the the interrupt handler |
std::runtime_error | on failure. |
void uninstallISR | ( | ) |
uninstall a previously installed interrupt handler
|
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.
dev | The device context. |
page | The page number to set. This can only be 0 or 1. |
force | If true, force the device page state to match indicated internal page state regardless of current state. |
std::runtime_error | on failure. |
|
protected |
Read a register.
reg | The register to read |
std::runtime_error | on failure. |
|
protected |
Read contiguous registers into a buffer.
buffer | The buffer to store the results |
len | The number of registers to read |
std::runtime_error | on failure. |
|
protected |
Write to a register
reg | The register to write to |
val | The value to write |
std::runtime_error | on failure. |
|
protected |
Write data to contiguous registers
reg | The starting register to write to |
buffer | The buffer containing the data to write |
len | The number of bytes to write |
std::runtime_error | on failure. |