A library of the 9-Axis Sensor BNO055 from Bosch Sensortec.
Requires the I2C-Master library - Link
Revision 7:ccb2dcdfac08, committed 2019-07-11
- Comitter:
- joelvonrotz
- Date:
- Thu Jul 11 12:10:54 2019 +0000
- Parent:
- 6:3dcf44b8289a
- Commit message:
- Completed Doxy Doc
Changed in this revision
bno055.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/bno055.cpp Thu Jul 11 11:31:55 2019 +0000 +++ b/bno055.cpp Thu Jul 11 12:10:54 2019 +0000 @@ -215,6 +215,8 @@ /** * @brief Returns the currently used Power Mode * + * The data is also accessible through the <em>mode</em>-struct (object.mode.power). + * * @return uint8_t Currently used Power Mode */ uint8_t BNO055::getPowerMode(void) @@ -226,6 +228,31 @@ return mode.power; } +/** + * @brief Sets the desired Operation Mode + * + * All of the information aren't definitive or could be straight up wrong. It is therefore highly recommended to read the datasheet of the BNO055. + * + * <table> + * <caption>Operation Modes</caption> + * <tr><th>Type <th>Description + * <tr><td>OPERATION_MODE_CONFIGMODE <td>Used when configuring the system + * <tr><td>OPERATION_MODE_ACCONLY <td>Enables Accelerometer only + * <tr><td>OPERATION_MODE_MAGONLY <td>Enables Magnetometer only + * <tr><td>OPERATION_MODE_GYROONLY <td>Enables Gyroscope only + * <tr><td>OPERATION_MODE_ACCMAG <td>Enables Accelerometer and Magnetometer only + * <tr><td>OPERATION_MODE_ACCGYRO <td>Enables Accelerometer and Gyroscope only + * <tr><td>OPERATION_MODE_MAGGYRO <td>Enables Magnetometer and Gyroscope only + * <tr><td>OPERATION_MODE_AMG <td>Enables all three sensors + * <tr><td>OPERATION_MODE_IMU <td>Enables Accelerometer & Gyroscope and relative position + * <tr><td>OPERATION_MODE_COMPASS <td>Enables Accelerometer & Magnetometer and absolute position + * <tr><td>OPERATION_MODE_M4G <td>"Magnet for Gyroscope" is similar to <em>IMU</em>, but instead using the gyroscope, it uses the magnetometer + * <tr><td>OPERATION_MODE_NDOF_FMC_OFF <td>"9 degrees of freedom" but without fast magnetometer calibration. + * <tr><td>OPERATION_MODE_NDOF <td>"9 degrees of freedom" - Magnetometer is calibrated very fast and increased data output + * </table> + * + * @param new_opr_mode + */ void BNO055::setOperationMode(bno055_opr_mode_t new_opr_mode) { //trying to write a mode, that is already being used, doesn't make any sense and can be ignored. @@ -252,6 +279,13 @@ } } +/** + * @brief Returns the current Operation Mode + * + * The data is also accessible through the <em>mode</em>-struct (object.mode.operation). + * + * @return uint8_t The current Operation Mode + */ uint8_t BNO055::getOperationMode(void) { mode.operation = m_i2c_master.i2c_read(m_bno055_address, OPR_MODE); @@ -261,6 +295,15 @@ return mode.operation; } +/** + * @brief Set I2C-Registermap Page + * + * The BNO055 contains two Register Map pages: Page 0 and Page 1. This function is used to switch between those two. + * + * Possible Options are: PAGE_0 & PAGE_1 + * + * @param new_page Desired new page number + */ void BNO055::setPage(bno055_page_t new_page) { page = new_page; @@ -272,6 +315,13 @@ m_i2c_master.i2c_write(m_bno055_address, PAGE_ID, page); } +/** + * @brief Returns the current Registermap-Page + * + * The data is also accessible through the <em>page</em>-struct (object.page). + * + * @return uint8_t The Current Page + */ uint8_t BNO055::getPage(void) { page = m_i2c_master.i2c_read(m_bno055_address, PAGE_ID); @@ -283,6 +333,13 @@ return page; } +/** + * @brief Returns the System Status + * + * The data is also accessible through the <em>system</em>-struct (object.system.status). + * + * @return uint8_t System Status + */ uint8_t BNO055::getSystemStatus(void) { system.status = m_i2c_master.i2c_read(m_bno055_address, SYS_STATUS); @@ -292,6 +349,13 @@ return system.status; } +/** + * @brief Returns the System Error + * + * The data is also accessible through the <em>system</em>-struct (object.system.error). + * + * @return uint8_t System Error + */ uint8_t BNO055::getSystemError(void) { system.error = m_i2c_master.i2c_read(m_bno055_address, SYS_ERR); @@ -301,6 +365,13 @@ return system.error; } +/** + * @brief Configure External Oscillator Input + * + * The external oscillator increases data accuracy. + * + * @param enabled <strong>TRUE</strong> enables external oscillator input, <strong>FALSE</strong> disabled input + */ void BNO055::useExternalOscillator(bool enabled) { char data = static_cast<char>(enabled) << 7; @@ -317,6 +388,9 @@ m_i2c_master.i2c_writeBits(m_bno055_address, SYS_TRIGGER, data, MASK_EXT_CLOCK); } +/** + * @brief Resets the System via Software + */ void BNO055::resetSW(void) { #ifdef DEBUGGING_ENABLED @@ -336,6 +410,11 @@ m_i2c_master.i2c_writeBits(m_bno055_address, SYS_TRIGGER, 0x00, MASK_SYSTEM_RESET); } +/** + * @brief Resets the System via Reset-Pin + * + * Resets the System with the referenced Reset-Pin during object-construction + */ void BNO055::resetHW(void) { #ifdef DEBUGGING_ENABLED @@ -351,6 +430,13 @@ } +/** + * @brief Remaps the three Axes to respect the new Orientation + * + * use <code>REMAP_OPTION_PX</code> with X defining one of the 8 orientation options (see datasheet) + * + * @param orientation_placement Orientation of the IC + */ void BNO055::setOrientation(bno055_remap_options_t orientation_placement) { axis.map = (orientation_placement >> SHIFT_1BYTE) & 0xFF; @@ -365,6 +451,11 @@ m_i2c_master.i2c_writeBits(m_bno055_address, AXIS_MAP_SIGN, axis.sign, MASK_SIGN_AXIS); } +/** + * @brief Returns the current Orientation + * + * The data is accessible through the <em>axis</em>-struct (object.axis.map & object.axis.sign). + */ void BNO055::getOrientation(void) { m_i2c_master.i2c_readSeries(m_bno055_address, AXIS_MAP_CONFIG,register_data,LENGTH_2_BYTES); @@ -378,6 +469,17 @@ axis.sign = register_data[1]; } +/** + * @brief Assign Axis to different Axes + * + * But it's not possible to map the two axes on the same axis. It will not return anything, even if it's correct. + * + * Possible values are: <code>X_AXIS, Y_AXIS, Z_AXIS</code> + * + * @param x_axis New Axis which will be applied to the X-Axis + * @param y_axis New Axis which will be applied to the Y-Axis + * @param z_axis New Axis which will be applied to the Z-Axis + */ void BNO055::assignAxis(bno055_axis_t x_axis, bno055_axis_t y_axis, bno055_axis_t z_axis) { //check if multiple axis have the same remap-axis. If true, then this part can be skipped, as @@ -399,6 +501,15 @@ } } +/** + * @brief Inverts the Axis + * + * Possible values are: <code>POSITIVE & NEGATIVE</code> + * + * @param x_sign New Sign for the X-Axis + * @param y_sign New Sign for the Y-Axis + * @param z_sign New Sign for the Z-Axis + */ void BNO055::setAxisSign(bno055_axis_sign_t x_sign, bno055_axis_sign_t y_sign, bno055_axis_sign_t z_sign) { axis.sign = x_sign + (y_sign << 1) + (z_sign << 2); @@ -408,6 +519,12 @@ m_i2c_master.i2c_writeBits(m_bno055_address, AXIS_MAP_SIGN, axis.sign, MASK_SIGN_AXIS); } +/** + * @brief Gets the System's Calibration Status + * + * The data is accessible through the <em>calibration</em>-struct (object.calibration.status, object.calibration.system, object.calibration.gyro, object.calibration.acceleration, object.calibration.magneto) + * + */ void BNO055::getCalibrationStatus(void) { calibration.status = m_i2c_master.i2c_read(m_bno055_address, CALIB_STAT); @@ -426,6 +543,11 @@ #endif } +/** + * @brief Gets the Interrupt-flags + * + * The data is accessible through the <em>interrupt</em>-struct (object.interrupt.xxx) + */ void BNO055::getInterruptFlag(void) { setPage(PAGE_1); @@ -451,6 +573,11 @@ setPage(PAGE_0); } +/** + * @brief Returns the enabled Interrupt + * + * @return uint8_t The value containing the enabled interrupts (see datasheet) + */ uint8_t BNO055::getEnabledInterrupts(void) { setPage(PAGE_1); @@ -464,6 +591,15 @@ return data_interrupt_enable; } +/** + * @brief Configure the Interrupts + * + * @param accel_no_motion <code>ENABLE</code> to enable interrupt, <code>DISABLE</code> to disable interrupt + * @param accel_any_motion <code>ENABLE</code> to enable interrupt, <code>DISABLE</code> to disable interrupt + * @param accel_high_g <code>ENABLE</code> to enable interrupt, <code>DISABLE</code> to disable interrupt + * @param gyro_high_rate <code>ENABLE</code> to enable interrupt, <code>DISABLE</code> to disable interrupt + * @param gyro_any_motion <code>ENABLE</code> to enable interrupt, <code>DISABLE</code> to disable interrupt + */ void BNO055::setEnableInterrupts(bno055_enable_t accel_no_motion, bno055_enable_t accel_any_motion, bno055_enable_t accel_high_g, @@ -482,8 +618,17 @@ setPage(PAGE_0); } - - +/** + * @brief Sets the Interrupt Mask + * + * This function enables or disabled the changing of the Interrupt-pin. + * + * @param accel_no_motion <code>ENABLE</code> to enable interrupt-calling, <code>DISABLE</code> to disable it + * @param accel_any_motion <code>ENABLE</code> to enable interrupt-calling, <code>DISABLE</code> to disable it + * @param accel_high_g <code>ENABLE</code> to enable interrupt-calling, <code>DISABLE</code> to disable it + * @param gyro_high_rate <code>ENABLE</code> to enable interrupt-calling, <code>DISABLE</code> to disable it + * @param gyro_any_motion <code>ENABLE</code> to enable interrupt-calling, <code>DISABLE</code> to disable it + */ void BNO055::setInterruptMask(bno055_enable_t accel_no_motion, bno055_enable_t accel_any_motion, bno055_enable_t accel_high_g, @@ -502,6 +647,11 @@ setPage(PAGE_0); } +/** + * @brief Returns current Interrupt Mask + * + * @return uint8_t Current Interrupt Mask (see datasheet) + */ uint8_t BNO055::getInterruptMask(void) { setPage(PAGE_1); @@ -516,6 +666,7 @@ return data_interrupt_mask; } + void BNO055::configAccelerationInterrupt(bno055_config_int_axis_t high_axis, bno055_config_int_axis_t am_nm_axis, bno055_any_motion_sample_t am_dur @@ -550,7 +701,11 @@ } //ACCELERATION - +/** + * @brief Returns Acceleration Data + * + * Data is accessible through the <em>accel</em>-struct (object.accel.x, object.accel.y, object.accel.z), after calling this function + */ void BNO055::getAcceleration(void) { if(format.acceleration == ACCELERATION) @@ -568,7 +723,11 @@ } //MAGNETOMETER - +/** + * @brief Returns Magnetometer Data + * + * Data is accessible through the <em>magneto</em>-struct (object.magneto.x, object.magneto.y, object.magneto.z), after calling this function + */ void BNO055::getMagnetometer(void) { get(MAG_DATA_VECTOR, magneto, MICRO_TESLA_FORMAT, false); @@ -579,7 +738,11 @@ } //GYROSCOPE - +/** + * @brief Returns Gyroscope Data + * + * Data is accessible through the <em>gyro</em>-struct (object.gyro.x, object.gyro.y, object.gyro.z), after calling this function + */ void BNO055::getGyroscope(void) { if(format.gyroscope == DEGREE_PER_SEC) @@ -596,7 +759,11 @@ } //EULER-DEGREES - +/** + * @brief Returns Euler Degree Data + * + * Data is accessible through the <em>euler</em>-struct (object.euler.x, object.euler.y, object.euler.z), after calling this function + */ void BNO055::getEulerDegrees(void) { if(format.euler == DEGREES) @@ -613,7 +780,11 @@ } //QUATERNION - +/** + * @brief Returns Quaternion Data + * + * Data is accessible through the <em>quaternion</em>-struct (object.quaternion.x, object.quaternion.y, object.quaternion.z), after calling this function + */ void BNO055::getQuaternion(void) { get(QUA_DATA_VECTOR, quaternion, QUATERNION_FORMAT); @@ -624,7 +795,11 @@ } //LINEAR ACCELERATION - +/** + * @brief Returns Linear Acceleration Data + * + * Data is accessible through the <em>linear_accel</em>-struct (object.linear_accel.x, object.linear_accel.y, object.linear_accel.z), after calling this function + */ void BNO055::getLinearAcceleration(void) { if(format.acceleration == ACCELERATION) @@ -641,7 +816,11 @@ } //GRAVITY VECTOR - +/** + * @brief Returns Gravity Vector Data + * + * Data is accessible through the <em>gravity_vector</em>-struct (object.gravity_vector.x, object.gravity_vector.y, object.gravity_vector.z), after calling this function + */ void BNO055::getGravityVector(void) { if(format.acceleration == ACCELERATION) @@ -658,7 +837,11 @@ } //TEMPERATURE - +/** + * @brief Returns Temperature Data + * + * Data is accessible through the <em>temperature</em>-struct (object.temperature), after calling this function + */ void BNO055::getTemperature(void) { m_i2c_master.i2c_readSeries(m_bno055_address, TEMP, register_data, LENGTH_1_BYTES);