Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add BNO055 IMU #12

Merged
merged 14 commits into from
Jan 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,6 @@ Cargo.lock
.DS_Store

imu/hexmove/ref/*

# dev
ref/
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ members = [
"imu/bindings",
"imu/hexmove",
"imu/hiwonder",
"imu/bno055",
]
resolver = "2"

Expand Down
24 changes: 24 additions & 0 deletions imu/bno055/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
[package]

name = "linux_bno055"
readme = "README.md"
description = "Interface for interacting with BNO055 IMUs"
version = "0.0.5"
authors.workspace = true
edition.workspace = true
repository.workspace = true
license.workspace = true

[lib]

name = "linux_bno055"
crate-type = ["rlib"]

[dependencies]

i2cdev = "0.6"
byteorder = "1.5"
bitflags = "2.6"
log = "0.4"
num-derive = "0.4"
num-traits = "0.2"
7 changes: 7 additions & 0 deletions imu/bno055/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# BNO055 IMU

This crate contains the code for interacting with the BNO055 IMU.

Code based on the [embedded-hal implementation of the BNO055](https://github.com/eupn/bno055).


76 changes: 76 additions & 0 deletions imu/bno055/src/bin/read_bno055.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
use linux_bno055::Bno055;
use std::{thread, time::Duration};

fn main() -> Result<(), Box<dyn std::error::Error>> {
// Create a new BNO055 instance
let mut imu = Bno055::new("/dev/i2c-1")?;

println!("Reading IMU data...");
println!("Press Ctrl+C to exit");

loop {
// Read quaternion data
if let Ok(quat) = imu.get_quaternion() {
println!(
"Quaternion: w: {:.3}, x: {:.3}, y: {:.3}, z: {:.3}",
quat.w, quat.x, quat.y, quat.z
);
}

// Read euler angles
if let Ok(euler) = imu.get_euler_angles() {
println!(
"Euler Angles: roll: {:.3}°, pitch: {:.3}°, yaw: {:.3}°",
euler.roll, euler.pitch, euler.yaw
);
}

// Read raw sensor data
if let Ok(accel) = imu.get_accelerometer() {
println!(
"Accelerometer: x: {:.3} m/s², y: {:.3} m/s², z: {:.3} m/s²",
accel.x, accel.y, accel.z
);
}

if let Ok(gyro) = imu.get_gyroscope() {
println!(
"Gyroscope: x: {:.3} °/s, y: {:.3} °/s, z: {:.3} °/s",
gyro.x, gyro.y, gyro.z
);
}

if let Ok(mag) = imu.get_magnetometer() {
println!(
"Magnetometer: x: {:.3} µT, y: {:.3} µT, z: {:.3} µT",
mag.x, mag.y, mag.z
);
}

// Read linear acceleration
if let Ok(accel) = imu.get_linear_acceleration() {
println!(
"Linear Acceleration: x: {:.3} m/s², y: {:.3} m/s², z: {:.3} m/s²",
accel.x, accel.y, accel.z
);
}

// Read temperature and calibration status
if let Ok(temp) = imu.get_temperature() {
println!("Temperature: {}°C", temp);
}

if let Ok(cal) = imu.get_calibration_status() {
println!(
"Calibration - Sys: {}, Gyro: {}, Accel: {}, Mag: {}",
(cal >> 6) & 0x03,
(cal >> 4) & 0x03,
(cal >> 2) & 0x03,
cal & 0x03
);
}

println!("---");
thread::sleep(Duration::from_millis(100));
}
}
Loading
Loading