Skip to main content

Movement

Struct Movement 

Source
pub struct Movement<I2C> { /* private fields */ }
Expand description

Driver for the Modulino Movement module (LSM6DSOX IMU).

§Example

use modulino::Movement;

let mut movement = Movement::new(i2c)?;

// Read acceleration
let accel = movement.acceleration()?;
println!("Accel: x={:.2}g, y={:.2}g, z={:.2}g", accel.x, accel.y, accel.z);

// Read angular velocity
let gyro = movement.angular_velocity()?;
println!("Gyro: x={:.2}dps, y={:.2}dps, z={:.2}dps", gyro.x, gyro.y, gyro.z);

Implementations§

Source§

impl<I2C, E> Movement<I2C>
where I2C: I2c<Error = E>,

Source

pub fn new(i2c: I2C) -> Result<Self, E>

Create a new Movement instance with the default address (0x6A).

Source

pub fn new_with_address(i2c: I2C, address: u8) -> Result<Self, E>

Create a new Movement instance with a custom address.

Valid addresses are 0x6A or 0x6B depending on the SA0 pin configuration.

Source

pub fn address(&self) -> u8

Get the I2C address.

Source

pub fn acceleration(&mut self) -> Result<MovementValues, E>

Read acceleration values.

Returns acceleration in g (gravitational units).

Source

pub fn acceleration_magnitude(&mut self) -> Result<f32, E>

Get the magnitude of acceleration.

When at rest on Earth, this should be approximately 1.0g due to gravity.

Source

pub fn angular_velocity(&mut self) -> Result<MovementValues, E>

Read angular velocity (gyroscope) values.

Returns angular velocity in degrees per second (dps).

Source

pub fn gyro(&mut self) -> Result<MovementValues, E>

Alias for angular_velocity().

Source

pub fn data_ready(&mut self) -> Result<bool, E>

Check if new data is available.

Source

pub fn release(self) -> I2C

Release the I2C bus.

Auto Trait Implementations§

§

impl<I2C> Freeze for Movement<I2C>
where I2C: Freeze,

§

impl<I2C> RefUnwindSafe for Movement<I2C>
where I2C: RefUnwindSafe,

§

impl<I2C> Send for Movement<I2C>
where I2C: Send,

§

impl<I2C> Sync for Movement<I2C>
where I2C: Sync,

§

impl<I2C> Unpin for Movement<I2C>
where I2C: Unpin,

§

impl<I2C> UnwindSafe for Movement<I2C>
where I2C: 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>,

Source§

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>,

Source§

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.