1
Fork 0
Find a file
dependabot-preview[bot] 6e46ec1301
Update libm requirement from 0.1.3 to 0.2.1
Updates the requirements on [libm](https://github.com/rust-lang/libm) to permit the latest version.
- [Release notes](https://github.com/rust-lang/libm/releases)
- [Changelog](https://github.com/rust-lang/libm/blob/master/CHANGELOG.md)
- [Commits](https://github.com/rust-lang/libm/compare/0.1.3...0.2.1)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2020-02-11 14:24:53 +00:00
.cargo build example in base cargo.toml with dev-dependencies 2019-05-20 16:20:34 +02:00
.circleci multiple jobs 2019-06-07 10:54:04 +02:00
examples documentation tests - fixed 2019-06-07 10:06:17 +02:00
src documentation tests - fixed 2019-06-07 10:06:17 +02:00
.gitignore make sure no target folder can be committed 2019-04-23 11:05:52 +02:00
Cargo.toml Update libm requirement from 0.1.3 to 0.2.1 2020-02-11 14:24:53 +00:00
LICENSE Update LICENSE 2019-04-16 00:45:44 +02:00
Makefile new make targets: install, rustup_cross 2019-06-07 10:33:02 +02:00
README.md Fix _unresolved type Error_ in example code 2019-06-27 05:59:13 -07:00

mpu6050 crates.io CircleCI

no_std driver for the MPU6050 6-axis IMU

Datasheet | Register Map Sheet

Visualization options for testing and development in viz branch

Basic usage

linux_embedded_hal example

use mpu6050::*;
use linux_embedded_hal::{I2cdev, Delay};
use i2cdev::linux::LinuxI2CError;

fn main() -> Result<(), Mpu6050Error<LinuxI2CError>> {
    let i2c = I2cdev::new("/dev/i2c-1")
        .map_err(Mpu6050Error::I2c)?;

    let delay = Delay;

    let mut mpu = Mpu6050::new(i2c, delay);
    mpu.init()?;
    mpu.soft_calib(Steps(100))?;
    mpu.calc_variance(Steps(50))?;

    println!("Calibrated with bias: {:?}", mpu.get_bias().unwrap());
    println!("Calculated variance: {:?}", mpu.get_variance().unwrap());

    loop {
        // get roll and pitch estimate
        let acc = mpu.get_acc_angles()?;
        println!("r/p: {}", acc);
        
        // get roll and pitch estimate - averaged accross n readings (steps)
        let acc = mpu.get_acc_angles_avg(Steps(5))?;
        println!("r/p avg: {}", acc);

        // get temp
        let temp = mpu.get_temp()?;
        println!("temp: {}c", temp);

        // get temp - averages across n readings (steps)
        let temp = mpu.get_temp_avg(Steps(5))?;
        println!("temp avg: {}c", temp);

        // get gyro data, scaled with sensitivity 
        let gyro = mpu.get_gyro()?;
        println!("gyro: {}", gyro);
        
        // get gyro data, scaled with sensitivity - averaged across n readings (steps) 
        let gyro = mpu.get_gyro_avg(Steps(5))?;
        println!("gyro avg: {}", gyro);
        
        // get accelerometer data, scaled with sensitivity
        let acc = mpu.get_acc()?;
        println!("acc: {}", acc);
        
        // get accelerometer data, scaled with sensitivity - averages across n readings (steps)
        let acc = mpu.get_acc_avg(Steps(5))?;
        println!("acc avg: {}", acc);		
    }
}

Compile linux example (Raspberry Pi 3B)

Requirements:

$ apt-get install -qq gcc-arm-linux-gnueabihf libc6-armhf-cross libc6-dev-armhf-cross

Rustup:

$ rustup target add armv7-unknown-linux-gnueabihf

To configure the linker use .cargo/config file

cross-compile with

$ cargo build --examples --target=armv7-unknown-linux-gnueabihf

TODO

  • init with default settings
  • init with custom settings
    • custom sensitivity
    • custom device initialization
  • device verification
  • basic feature support as described here
  • read gyro data
  • read acc data
  • software calibration
  • software measurement variance estimation
  • roll, pitch estimation accelerometer only
  • read temp data
  • rename constants to better match datasheet
  • complementary filter for roll, pitch estimate, possible on device?
  • sample rate devider with register 25? or timer/clock control with PWR_MGMT_2
  • plotting csv datafor testing? -> See viz branch