Crates.io | drogue-mpu-6050 |
lib.rs | drogue-mpu-6050 |
version | 0.1.0 |
source | src |
created_at | 2020-10-19 18:23:57.813237 |
updated_at | 2020-10-19 18:23:57.813237 |
description | InvenSense MPU-6050 i2c Driver |
homepage | |
repository | https://github.com/drogue-iot/drogue-mpu-6050 |
max_upload_size | |
id | 303036 |
size | 42,228 |
drogue-mpu-6050
i2c Driver for the InvenSense MPU-6050 motion-processor.
This driver can load the appropriate firmware for quaternion-based DMP processing on-chip.
Initialize your i2c bus per usual:
let scl3 = gpioc.pc0.into_open_drain_output(&mut gpioc.moder, &mut gpioc.otyper).into_af4(&mut gpioc.moder, &mut gpioc.afrl);
let sda3 = gpioc.pc1.into_open_drain_output(&mut gpioc.moder, &mut gpioc.otyper).into_af4(&mut gpioc.moder, &mut gpioc.afrl);
let i2c = I2c::i2c3(device.I2C3, (scl3, sda3), KiloHertz(100), clocks, &mut rcc.apb1r1);
The MPU driver requires an embedded-time
capable clock.
let sensor = Mpu6050::new(i2c, Address::default(), &CLOCK).unwrap();
Once your clock is ticking, you may then manipulate the MPU.
For ease, the initialize_dmp()
method is provided to set up reasonable configurations and load the DMP firmware into the processor.
let sensor: &mut Mpu6050<'_, _, _> = ctx.resources.sensor;
sensor.initialize_dmp().unwrap();
If using the advanced on-chip DMP logic, the FIFO will contain 28-byte packets of quaternion and other data.
The first 16 bytes are quaternions, which can be constructed using the Quaternion
class.
let len = sensor.get_fifo_count().unwrap();
if len >= 28 {
let buf = sensor.read_fifo(&mut buf).unwrap();
let q = Quaternion::from_bytes(&buf[0..16]).unwrap().normalize();
....
}
A quaternion may also be converted into a Euler
or YawPitchRoll
measurement.