pub struct Mpu6050<I> { /* private fields */ }
Expand description
Handles all operations on/with Mpu6050
Implementations
sourceimpl<I, E> Mpu6050<I>where
I: Write<Error = E> + WriteRead<Error = E>,
impl<I, E> Mpu6050<I>where
I: Write<Error = E> + WriteRead<Error = E>,
sourcepub fn new(i2c: I) -> Self
pub fn new(i2c: I) -> Self
Side effect free constructor with default sensitivies, no calibration
sourcepub fn new_with_sens(i2c: I, arange: AccelRange, grange: GyroRange) -> Self
pub fn new_with_sens(i2c: I, arange: AccelRange, grange: GyroRange) -> Self
custom sensitivity
sourcepub fn new_with_addr(i2c: I, slave_addr: u8) -> Self
pub fn new_with_addr(i2c: I, slave_addr: u8) -> Self
Same as new
, but the chip address can be specified (e.g. 0x69, if the A0 pin is pulled up)
sourcepub fn new_with_addr_and_sens(
i2c: I,
slave_addr: u8,
arange: AccelRange,
grange: GyroRange
) -> Self
pub fn new_with_addr_and_sens(
i2c: I,
slave_addr: u8,
arange: AccelRange,
grange: GyroRange
) -> Self
Combination of new_with_sens
and new_with_addr
sourcepub fn set_clock_source(&mut self, source: CLKSEL) -> Result<(), Mpu6050Error<E>>
pub fn set_clock_source(&mut self, source: CLKSEL) -> Result<(), Mpu6050Error<E>>
From Register map: “An internal 8MHz oscillator, gyroscope based clock,or external sources can be selected as the MPU-60X0 clock source. When the internal 8 MHz oscillator or an external source is chosen as the clock source, the MPU-60X0 can operate in low power modes with the gyroscopes disabled. Upon power up, the MPU-60X0clock source defaults to the internal oscillator. However, it is highly recommended that the device beconfigured to use one of the gyroscopes (or an external clocksource) as the clock reference for improved stability. The clock source can be selected according to the following table….”
sourcepub fn get_clock_source(&mut self) -> Result<CLKSEL, Mpu6050Error<E>>
pub fn get_clock_source(&mut self) -> Result<CLKSEL, Mpu6050Error<E>>
get current clock source
sourcepub fn init<D: DelayMs<u8>>(
&mut self,
delay: &mut D
) -> Result<(), Mpu6050Error<E>>
pub fn init<D: DelayMs<u8>>(
&mut self,
delay: &mut D
) -> Result<(), Mpu6050Error<E>>
Init wakes MPU6050 and verifies register addr, e.g. in i2c
sourcepub fn setup_motion_detection(&mut self) -> Result<(), Mpu6050Error<E>>
pub fn setup_motion_detection(&mut self) -> Result<(), Mpu6050Error<E>>
setup motion detection sources:
- https://github.com/kriswiner/MPU6050/blob/a7e0c8ba61a56c5326b2bcd64bc81ab72ee4616b/MPU6050IMU.ino#L486
- https://arduino.stackexchange.com/a/48430
sourcepub fn get_motion_detected(&mut self) -> Result<bool, Mpu6050Error<E>>
pub fn get_motion_detected(&mut self) -> Result<bool, Mpu6050Error<E>>
get whether or not motion has been detected (INT_STATUS, MOT_INT)
sourcepub fn set_accel_hpf(&mut self, mode: ACCEL_HPF) -> Result<(), Mpu6050Error<E>>
pub fn set_accel_hpf(&mut self, mode: ACCEL_HPF) -> Result<(), Mpu6050Error<E>>
set accel high pass filter mode
sourcepub fn get_accel_hpf(&mut self) -> Result<ACCEL_HPF, Mpu6050Error<E>>
pub fn get_accel_hpf(&mut self) -> Result<ACCEL_HPF, Mpu6050Error<E>>
get accel high pass filter mode
sourcepub fn set_gyro_range(&mut self, range: GyroRange) -> Result<(), Mpu6050Error<E>>
pub fn set_gyro_range(&mut self, range: GyroRange) -> Result<(), Mpu6050Error<E>>
Set gyro range, and update sensitivity accordingly
sourcepub fn get_gyro_range(&mut self) -> Result<GyroRange, Mpu6050Error<E>>
pub fn get_gyro_range(&mut self) -> Result<GyroRange, Mpu6050Error<E>>
get current gyro range
sourcepub fn set_accel_range(
&mut self,
range: AccelRange
) -> Result<(), Mpu6050Error<E>>
pub fn set_accel_range(
&mut self,
range: AccelRange
) -> Result<(), Mpu6050Error<E>>
set accel range, and update sensitivy accordingly
sourcepub fn get_accel_range(&mut self) -> Result<AccelRange, Mpu6050Error<E>>
pub fn get_accel_range(&mut self) -> Result<AccelRange, Mpu6050Error<E>>
get current accel_range
sourcepub fn reset_device<D: DelayMs<u8>>(
&mut self,
delay: &mut D
) -> Result<(), Mpu6050Error<E>>
pub fn reset_device<D: DelayMs<u8>>(
&mut self,
delay: &mut D
) -> Result<(), Mpu6050Error<E>>
reset device
sourcepub fn set_sleep_enabled(&mut self, enable: bool) -> Result<(), Mpu6050Error<E>>
pub fn set_sleep_enabled(&mut self, enable: bool) -> Result<(), Mpu6050Error<E>>
enable, disable sleep of sensor
sourcepub fn get_sleep_enabled(&mut self) -> Result<bool, Mpu6050Error<E>>
pub fn get_sleep_enabled(&mut self) -> Result<bool, Mpu6050Error<E>>
get sleep status
sourcepub fn set_temp_enabled(&mut self, enable: bool) -> Result<(), Mpu6050Error<E>>
pub fn set_temp_enabled(&mut self, enable: bool) -> Result<(), Mpu6050Error<E>>
enable, disable temperature measurement of sensor TEMP_DIS actually saves “disabled status” 1 is disabled! -> enable=true : bit=!enable
sourcepub fn get_temp_enabled(&mut self) -> Result<bool, Mpu6050Error<E>>
pub fn get_temp_enabled(&mut self) -> Result<bool, Mpu6050Error<E>>
get temperature sensor status TEMP_DIS actually saves “disabled status” 1 is disabled! -> 1 == 0 : false, 0 == 0 : true
sourcepub fn set_accel_x_self_test(
&mut self,
enable: bool
) -> Result<(), Mpu6050Error<E>>
pub fn set_accel_x_self_test(
&mut self,
enable: bool
) -> Result<(), Mpu6050Error<E>>
set accel x self test
sourcepub fn get_accel_x_self_test(&mut self) -> Result<bool, Mpu6050Error<E>>
pub fn get_accel_x_self_test(&mut self) -> Result<bool, Mpu6050Error<E>>
get accel x self test
sourcepub fn set_accel_y_self_test(
&mut self,
enable: bool
) -> Result<(), Mpu6050Error<E>>
pub fn set_accel_y_self_test(
&mut self,
enable: bool
) -> Result<(), Mpu6050Error<E>>
set accel y self test
sourcepub fn get_accel_y_self_test(&mut self) -> Result<bool, Mpu6050Error<E>>
pub fn get_accel_y_self_test(&mut self) -> Result<bool, Mpu6050Error<E>>
get accel y self test
sourcepub fn set_accel_z_self_test(
&mut self,
enable: bool
) -> Result<(), Mpu6050Error<E>>
pub fn set_accel_z_self_test(
&mut self,
enable: bool
) -> Result<(), Mpu6050Error<E>>
set accel z self test
sourcepub fn get_accel_z_self_test(&mut self) -> Result<bool, Mpu6050Error<E>>
pub fn get_accel_z_self_test(&mut self) -> Result<bool, Mpu6050Error<E>>
get accel z self test
sourcepub fn get_acc_angles(&mut self) -> Result<Vector2<f32>, Mpu6050Error<E>>
pub fn get_acc_angles(&mut self) -> Result<Vector2<f32>, Mpu6050Error<E>>
Roll and pitch estimation from raw accelerometer readings NOTE: no yaw! no magnetometer present on MPU6050 https://www.nxp.com/docs/en/application-note/AN3461.pdf equation 28, 29
sourcepub fn get_temp(&mut self) -> Result<f32, Mpu6050Error<E>>
pub fn get_temp(&mut self) -> Result<f32, Mpu6050Error<E>>
Sensor Temp in degrees celcius
sourcepub fn write_byte(&mut self, reg: u8, byte: u8) -> Result<(), Mpu6050Error<E>>
pub fn write_byte(&mut self, reg: u8, byte: u8) -> Result<(), Mpu6050Error<E>>
Writes byte to register
sourcepub fn write_bit(
&mut self,
reg: u8,
bit_n: u8,
enable: bool
) -> Result<(), Mpu6050Error<E>>
pub fn write_bit(
&mut self,
reg: u8,
bit_n: u8,
enable: bool
) -> Result<(), Mpu6050Error<E>>
Enables bit n at register address reg
sourcepub fn write_bits(
&mut self,
reg: u8,
start_bit: u8,
length: u8,
data: u8
) -> Result<(), Mpu6050Error<E>>
pub fn write_bits(
&mut self,
reg: u8,
start_bit: u8,
length: u8,
data: u8
) -> Result<(), Mpu6050Error<E>>
Write bits data at reg from start_bit to start_bit+length
sourcepub fn read_bits(
&mut self,
reg: u8,
start_bit: u8,
length: u8
) -> Result<u8, Mpu6050Error<E>>
pub fn read_bits(
&mut self,
reg: u8,
start_bit: u8,
length: u8
) -> Result<u8, Mpu6050Error<E>>
Read bits at register reg, starting with bit start_bit, until start_bit+length
sourcepub fn read_bytes(
&mut self,
reg: u8,
buf: &mut [u8]
) -> Result<(), Mpu6050Error<E>>
pub fn read_bytes(
&mut self,
reg: u8,
buf: &mut [u8]
) -> Result<(), Mpu6050Error<E>>
Reads series of bytes into buf from specified reg
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
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self
from the equivalent element of its
superset. Read morefn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self
is actually part of its subset T
(and can be converted to it).fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset
but without any property checks. Always succeeds.fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self
to the equivalent element of its superset.