Struct mpu6050_dmp::sensor::Mpu6050
source · pub struct Mpu6050<I>where
I: I2c,{ /* private fields */ }
Expand description
InvenSense MPU-6050 Driver
Implementations§
source§impl<I> Mpu6050<I>where
I: I2c,
impl<I> Mpu6050<I>where
I: I2c,
pub fn load_firmware(&mut self) -> Result<(), Error<I>>
pub fn boot_firmware(&mut self) -> Result<(), Error<I>>
source§impl<I> Mpu6050<I>where
I: I2c,
impl<I> Mpu6050<I>where
I: I2c,
sourcepub fn new(i2c: I, address: Address) -> Result<Self, InitError<I>>
pub fn new(i2c: I, address: Address) -> Result<Self, InitError<I>>
Construct a new i2c driver for the MPU-6050
sourcepub fn initialize_dmp(
&mut self,
delay: &mut impl DelayNs
) -> Result<(), Error<I>>
pub fn initialize_dmp( &mut self, delay: &mut impl DelayNs ) -> Result<(), Error<I>>
Load DMP firmware and perform all appropriate initialization.
sourcepub fn reset(&mut self, clock: &mut impl DelayNs) -> Result<(), Error<I>>
pub fn reset(&mut self, clock: &mut impl DelayNs) -> Result<(), Error<I>>
Perform power reset of the MPU
sourcepub fn reset_signal_path(
&mut self,
clock: &mut impl DelayNs
) -> Result<(), Error<I>>
pub fn reset_signal_path( &mut self, clock: &mut impl DelayNs ) -> Result<(), Error<I>>
Perform reset of the signal path
sourcepub fn set_clock_source(
&mut self,
clock_source: ClockSource
) -> Result<(), Error<I>>
pub fn set_clock_source( &mut self, clock_source: ClockSource ) -> Result<(), Error<I>>
Pick the clock-source
pub fn disable_interrupts(&mut self) -> Result<(), Error<I>>
sourcepub fn interrupt_fifo_oflow_en(&mut self) -> Result<(), Error<I>>
pub fn interrupt_fifo_oflow_en(&mut self) -> Result<(), Error<I>>
Enables a FIFO buffer overflow to generate an interrupt
sourcepub fn interrupt_i2c_mst_int_en(&mut self) -> Result<(), Error<I>>
pub fn interrupt_i2c_mst_int_en(&mut self) -> Result<(), Error<I>>
Enables any of the i2c master interrupt sources to generate an interrupt
sourcepub fn interrupt_data_ready_en(&mut self) -> Result<(), Error<I>>
pub fn interrupt_data_ready_en(&mut self) -> Result<(), Error<I>>
Enables the Data Ready interrupt, which occurs each time a write operation to all of the sensor registers has been completed
sourcepub fn interrupt_read_clear(&mut self) -> Result<u8, Error<I>>
pub fn interrupt_read_clear(&mut self) -> Result<u8, Error<I>>
Read the interrupt status register and clear it.
sourcepub fn calibrate_accel(
&mut self,
loops: u8,
delay: &mut impl DelayNs
) -> Result<(), Error<I>>
👎Deprecated
pub fn calibrate_accel( &mut self, loops: u8, delay: &mut impl DelayNs ) -> Result<(), Error<I>>
Super simple averaging calibration of the accelerometers.
Probably should be called before initializing the DMP.
Deprecated because the new calibration framework (calibrate
) works way better.
sourcepub fn calibrate_gyro(
&mut self,
loops: u8,
delay: &mut impl DelayNs
) -> Result<(), Error<I>>
👎Deprecated
pub fn calibrate_gyro( &mut self, loops: u8, delay: &mut impl DelayNs ) -> Result<(), Error<I>>
Super simple averaging calibration of the gyroscopes.
Probably should be called before initializing the DMP.
Deprecated because the new calibration framework (calibrate
) works way better.
sourcepub fn calibrate(
&mut self,
delay: &mut impl DelayNs,
parameters: &CalibrationParameters
) -> Result<(Accel, Gyro), Error<I>>
pub fn calibrate( &mut self, delay: &mut impl DelayNs, parameters: &CalibrationParameters ) -> Result<(Accel, Gyro), Error<I>>
Through calibration, taken from https://wired.chillibasket.com/2015/01/calibrating-mpu6050/
This is supposed to be run once, printing the results, and reusing them by setting the
calibration using set_accel_calibration
and set_gyro_calibration
with offsets hardcoded
as constants in the application code (or storing and retrieving them to-from persistent
storage, if available).
If calibration parameters are not “reasonable” this function might never return.
sourcepub fn collect_mean_values(
&mut self,
delay: &mut impl DelayNs,
accel_scale: AccelFullScale,
gravity: ReferenceGravity
) -> Result<(Accel, Gyro), Error<I>>
pub fn collect_mean_values( &mut self, delay: &mut impl DelayNs, accel_scale: AccelFullScale, gravity: ReferenceGravity ) -> Result<(Accel, Gyro), Error<I>>
A building block for performing calibration: collect several samples return their average
sourcepub fn calibration_loop(
&mut self,
delay: &mut impl DelayNs,
parameters: &CalibrationParameters,
actions: CalibrationActions
) -> Result<(CalibrationActions, Accel, Gyro), Error<I>>
pub fn calibration_loop( &mut self, delay: &mut impl DelayNs, parameters: &CalibrationParameters, actions: CalibrationActions ) -> Result<(CalibrationActions, Accel, Gyro), Error<I>>
Perform a full device calibration (note that this function might never terminate).
A higher level building block for performing calibration,
this function should be called repeatedly, until is_empty()
returns true
on the
returned CalibrationActions
.
At each iteration the calibration gets “better”, and it is considered completed when there are no more actions to perform.
This is an example of how a calibration loop can be written:
let calibration_parameters =
CalibrationParameters::new(ACCEL_SCALE, GYRO_SCALE, ReferenceGravity::ZN);
let mut actions = CalibrationActions::all();
let mut accel_error: Accel;
let mut gyro_error: Gyro;
while !actions.is_empty() {
(actions, accel_error, gyro_error) = mpu
.calibration_loop(&mut delay, &calibration_parameters, actions)
.unwrap();
uprintln!(
serial,
"errors: [a {} {} {}] [g {} {} {}] [done: {}]",
accel_error.x(),
accel_error.y(),
accel_error.z(),
gyro_error.x(),
gyro_error.y(),
gyro_error.z(),
actions.is_empty(),
);
}
let accel_offset = mpu.get_accel_calibration().unwrap();
let gyro_offset = mpu.get_gyro_calibration().unwrap();
uprintln!(
serial,
"offsets: [a {} {} {}] [g {} {} {}]",
accel_offset.x(),
accel_offset.y(),
accel_offset.z(),
gyro_offset.x(),
gyro_offset.y(),
gyro_offset.z(),
);
When the loop is done the offsets can be collected and hardcoded in the initialization of the application that will use this device with exactly these settings.
pub fn get_accel_calibration(&mut self) -> Result<Accel, Error<I>>
pub fn get_gyro_calibration(&mut self) -> Result<Gyro, Error<I>>
pub fn set_accel_calibration(&mut self, values: &Accel) -> Result<(), Error<I>>
pub fn set_gyro_calibration(&mut self, values: &Gyro) -> Result<(), Error<I>>
pub fn set_accel_full_scale( &mut self, scale: AccelFullScale ) -> Result<(), Error<I>>
pub fn set_gyro_full_scale( &mut self, scale: GyroFullScale ) -> Result<(), Error<I>>
pub fn set_sample_rate_divider(&mut self, div: u8) -> Result<(), Error<I>>
pub fn set_digital_lowpass_filter( &mut self, filter: DigitalLowPassFilter ) -> Result<(), Error<I>>
pub fn reset_fifo(&mut self) -> Result<(), Error<I>>
pub fn enable_fifo(&mut self) -> Result<(), Error<I>>
sourcepub fn enable_dmp(&mut self) -> Result<(), Error<I>>
pub fn enable_dmp(&mut self) -> Result<(), Error<I>>
Set the DMP bit.
To perform full DMP initialization, see initialize_dmp()