Update example with averaging
This commit is contained in:
parent
c7c9accec7
commit
8f39d8ce56
1 changed files with 19 additions and 3 deletions
22
README.md
22
README.md
|
@ -23,8 +23,8 @@ fn main() -> Result<(), Error<LinuxI2CError>> {
|
||||||
|
|
||||||
let mut mpu = Mpu6050::new(i2c, delay);
|
let mut mpu = Mpu6050::new(i2c, delay);
|
||||||
mpu.init()?;
|
mpu.init()?;
|
||||||
mpu.soft_calib(100)?;
|
mpu.soft_calib(Steps(100))?;
|
||||||
mpu.calc_variance(50)?;
|
mpu.calc_variance(Steps(50))?;
|
||||||
|
|
||||||
println!("Calibrated with bias: {:?}", mpu.get_bias().unwrap());
|
println!("Calibrated with bias: {:?}", mpu.get_bias().unwrap());
|
||||||
println!("Calculated variance: {:?}", mpu.get_variance().unwrap());
|
println!("Calculated variance: {:?}", mpu.get_variance().unwrap());
|
||||||
|
@ -34,18 +34,34 @@ fn main() -> Result<(), Error<LinuxI2CError>> {
|
||||||
let acc = mpu.get_acc_angles()?;
|
let acc = mpu.get_acc_angles()?;
|
||||||
println!("r/p: {:?}", acc);
|
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
|
// get temp
|
||||||
let temp = mpu.get_temp()?;
|
let temp = mpu.get_temp()?;
|
||||||
println!("temp: {}c", 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
|
// get gyro data, scaled with sensitivity
|
||||||
let gyro = mpu.get_gyro()?;
|
let gyro = mpu.get_gyro()?;
|
||||||
println!("gyro: {:?}", 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
|
// get accelerometer data, scaled with sensitivity
|
||||||
let acc = mpu.get_acc()?;
|
let acc = mpu.get_acc()?;
|
||||||
println!("acc: {:?}", 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.
|
*Note*: this example uses API of version on local master branch. Some functions may not be available on published crate yet.
|
||||||
|
|
Loading…
Reference in a new issue