1
Fork 0

Update example with averaging

This commit is contained in:
Julian Gaal 2019-04-24 16:08:35 +02:00 committed by GitHub
parent c7c9accec7
commit 8f39d8ce56
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -23,8 +23,8 @@ fn main() -> Result<(), Error<LinuxI2CError>> {
let mut mpu = Mpu6050::new(i2c, delay);
mpu.init()?;
mpu.soft_calib(100)?;
mpu.calc_variance(50)?;
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());
@ -34,18 +34,34 @@ fn main() -> Result<(), Error<LinuxI2CError>> {
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);
}
```
*Note*: this example uses API of version on local master branch. Some functions may not be available on published crate yet.