This is a embedded-hal driver for Bosch's inertial measurement unit (IMU) BNO055.
It is device-agnostic and uses I2c
and Delay
embedded-hal traits for its operation.
Uses and re-exports nalgebra's Quaternion for quaternion reading and Rotation3 for Euler angles.
Add dependency to Cargo.toml
:
bash
cargo add bno055
Instantiate and init the device: ```rust // ... declare and configure your I2c and Delay implementations ...
// Init BNO055 IMU let imu = bno055::Bno055::new(i2c, delay);
imu.init()?;
// Enable 9-degrees-of-freedom sensor fusion mode with fast magnetometer calibration imu.set_mode(bno055::BNO055OperationMode::NDOF)?;
Ok(imu) ```
Read orientation data: quaternion or euler angles (roll, pitch, yaw/heading)
rust
let quat = imu.quaternion()?;
// or:
let euler = imu.euler_angles()?;
BNO055 allows to change default axes to meet chip orientation with actual physical device orientation, thus providing possibility to place BNO055 chip on PCB as suitable for designer and to match chip's axes to and physical axes in software later.
```rust use bno055::{AxisRemap, BNO055AxisConfig}; // ...
// Build remap configuration example with X and Y axes swapped: let remap = AxisRemap::builder() .swapxwith(BNO055AxisConfig::AXISASY) .build() .expect("Failed to build axis remap config");
bno055.setaxisremap(remap)?; ```
Please note that AxisRemap
(and the chip itself) builder doesn't allow invalid state to be constructed,
that is, when one axis is swapped with multiple of others.
For example, swapping axis X
with both Y
and Z
at the same time is not allowed:
rust
AxisRemap::builder()
.swap_x_with(BNO055AxisConfig::AXIS_AS_Y)
.swap_x_with(BNO055AxisConfig::AXIS_AS_Z)
.build()
.unwrap(); // <- panics, .build() returned Err
It is also possible to flip sign of either axis of the chip.
Example of flipping X and Y axes:
rust
bno055
.set_axis_sign(BNO055AxisSign::X_NEGATIVE | bno055::BNO055AxisSign::Y_NEGATIVE)
.expect("Unable to communicate");
For better performance, it is advised to connect and use external 32k quartz crystal.
User could enable or disable it by calling set_external_crystal
:
rust
bno055
.set_external_crystal(true)
.expect("Failed to set to external crystal");
What is done and tested and what is not yet: