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,

source

pub fn load_firmware(&mut self) -> Result<(), Error<I>>

source

pub fn boot_firmware(&mut self) -> Result<(), Error<I>>

source§

impl<I> Mpu6050<I>
where I: I2c,

source

pub fn new(i2c: I, address: Address) -> Result<Self, InitError<I>>

Construct a new i2c driver for the MPU-6050

source

pub fn release(self) -> I

Returns the underlying I2C peripheral, consuming this driver.

source

pub fn initialize_dmp( &mut self, delay: &mut impl DelayNs ) -> Result<(), Error<I>>

Load DMP firmware and perform all appropriate initialization.

source

pub fn reset(&mut self, clock: &mut impl DelayNs) -> Result<(), Error<I>>

Perform power reset of the MPU

source

pub fn reset_signal_path( &mut self, clock: &mut impl DelayNs ) -> Result<(), Error<I>>

Perform reset of the signal path

source

pub fn set_clock_source( &mut self, clock_source: ClockSource ) -> Result<(), Error<I>>

Pick the clock-source

source

pub fn disable_interrupts(&mut self) -> Result<(), Error<I>>

source

pub fn interrupt_fifo_oflow_en(&mut self) -> Result<(), Error<I>>

Enables a FIFO buffer overflow to generate an interrupt

source

pub fn interrupt_i2c_mst_int_en(&mut self) -> Result<(), Error<I>>

Enables any of the i2c master interrupt sources to generate an interrupt

source

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

source

pub fn interrupt_read_clear(&mut self) -> Result<u8, Error<I>>

Read the interrupt status register and clear it.

source

pub fn calibrate_accel( &mut self, loops: u8, delay: &mut impl DelayNs ) -> Result<(), Error<I>>

👎Deprecated

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.

source

pub fn calibrate_gyro( &mut self, loops: u8, delay: &mut impl DelayNs ) -> Result<(), Error<I>>

👎Deprecated

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.

source

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.

source

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

source

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.

source

pub fn get_accel_calibration(&mut self) -> Result<Accel, Error<I>>

source

pub fn get_gyro_calibration(&mut self) -> Result<Gyro, Error<I>>

source

pub fn set_accel_calibration(&mut self, values: &Accel) -> Result<(), Error<I>>

source

pub fn set_gyro_calibration(&mut self, values: &Gyro) -> Result<(), Error<I>>

source

pub fn set_accel_full_scale( &mut self, scale: AccelFullScale ) -> Result<(), Error<I>>

source

pub fn set_gyro_full_scale( &mut self, scale: GyroFullScale ) -> Result<(), Error<I>>

source

pub fn set_sample_rate_divider(&mut self, div: u8) -> Result<(), Error<I>>

source

pub fn set_digital_lowpass_filter( &mut self, filter: DigitalLowPassFilter ) -> Result<(), Error<I>>

source

pub fn reset_fifo(&mut self) -> Result<(), Error<I>>

source

pub fn enable_fifo(&mut self) -> Result<(), Error<I>>

source

pub fn enable_dmp(&mut self) -> Result<(), Error<I>>

Set the DMP bit. To perform full DMP initialization, see initialize_dmp()

source

pub fn disable_dmp(&mut self) -> Result<(), Error<I>>

source

pub fn reset_dmp(&mut self) -> Result<(), Error<I>>

Reset the DMP processor

source

pub fn read_fifo<'a>(&mut self, buf: &'a mut [u8]) -> Result<&'a [u8], Error<I>>

Read the FIFO

source

pub fn get_fifo_enabled(&mut self) -> Result<Fifo, Error<I>>

source

pub fn set_fifo_enabled(&mut self, fifo: Fifo) -> Result<(), Error<I>>

source

pub fn get_fifo_count(&mut self) -> Result<usize, Error<I>>

source

pub fn disable_sleep(&mut self) -> Result<(), Error<I>>

source

pub fn accel(&mut self) -> Result<Accel, Error<I>>

source

pub fn gyro(&mut self) -> Result<Gyro, Error<I>>

Auto Trait Implementations§

§

impl<I> RefUnwindSafe for Mpu6050<I>
where I: RefUnwindSafe,

§

impl<I> Send for Mpu6050<I>
where I: Send,

§

impl<I> Sync for Mpu6050<I>
where I: Sync,

§

impl<I> Unpin for Mpu6050<I>
where I: Unpin,

§

impl<I> UnwindSafe for Mpu6050<I>
where I: UnwindSafe,

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.