Fit0185

Struct Fit0185 

Source
pub struct Fit0185<const CS_P: char, const CS_N: u8, const IN1_P: char, const IN1_N: u8, const IN2_P: char, const IN2_N: u8, const SLP_P: char, const SLP_N: u8, const DIS_P: char, const DIS_N: u8> { /* private fields */ }
Expand description

Motor abstraction that combines a DRV8873 driver, four control pins, and a TIM2 encoder.

Implementations§

Source§

impl<const CS_P: char, const CS_N: u8, const IN1_P: char, const IN1_N: u8, const IN2_P: char, const IN2_N: u8, const SLP_P: char, const SLP_N: u8, const DIS_P: char, const DIS_N: u8> Fit0185<CS_P, CS_N, IN1_P, IN1_N, IN2_P, IN2_N, SLP_P, SLP_N, DIS_P, DIS_N>

Source

pub fn new<In1Mode, In2Mode, SlpMode, DisMode>( drv: Drv8873<CS_P, CS_N>, enc: Encoder<TIM2>, in1: Pin<IN1_P, IN1_N, In1Mode>, in2: Pin<IN2_P, IN2_N, In2Mode>, nsleep: Pin<SLP_P, SLP_N, SlpMode>, disable: Pin<DIS_P, DIS_N, DisMode>, counts_per_rev: u32, ) -> Self

Construct a new SpiMotor.

counts_per_rev is the encoder resolution at the mechanical shaft (after any gear ratio).

Source

pub fn free( self, ) -> (Drv8873<CS_P, CS_N>, Encoder<TIM2>, Pin<IN1_P, IN1_N, Output<PushPull>>, Pin<IN2_P, IN2_N, Output<PushPull>>, Pin<SLP_P, SLP_N, Output<PushPull>>, Pin<DIS_P, DIS_N, Output<PushPull>>)

Tear down this motor and return its constituent parts.

Source

pub fn init<I, PINS>( &mut self, spi_bus: &mut SpiBus<I, PINS>, ) -> Result<(), Error>
where I: Instance, PINS: Pins<I>,

Initialize and set base configuration for the DRV8873.

Source

pub fn read_fault<I, PINS>( &mut self, spi_bus: &mut SpiBus<I, PINS>, ) -> Result<Fault, Error>
where I: Instance, PINS: Pins<I>,

Read the FAULT status register.

Source

pub fn read_diag<I, PINS>( &mut self, spi_bus: &mut SpiBus<I, PINS>, ) -> Result<Diag, Error>
where I: Instance, PINS: Pins<I>,

Read the DIAG status register.

Source

pub fn drv(&mut self) -> &mut Drv8873<CS_P, CS_N>

Access the underlying DRV8873 driver for advanced SPI control.

Source

pub fn sleep(&mut self)

Put the driver into sleep mode.

This shuts down most of the internal circuitry to reduce power consumption.

Source

pub fn wake(&mut self)

Wake the driver from sleep mode.

Source

pub fn enable_outputs(&mut self)

Enable the motor and wake the driver if in sleep.

Source

pub fn disable_outputs(&mut self)

Disable the motor and coast.

Source

pub fn forward(&mut self)

Drive the motor forward.

Source

pub fn reverse(&mut self)

Drive the motor in reverse.

Source

pub fn brake(&mut self)

Apply brakes.

Source

pub fn coast(&mut self)

Coast (this sets outputs to HiZ).

Source

pub fn position_ticks(&self) -> i32

Raw encoder position in ticks (signed).

Source

pub fn position_revs(&self) -> f32

Encoder position converted to revolutions.

Source

pub fn zero(&mut self)

Reset the encoder position to zero.

Source

pub fn ticks_for_revs(&self, revs: f32) -> i32

Convert a number of revolutions into encoder ticks.

Source

pub fn target_for_delta_ticks(&self, delta_ticks: i32) -> i32

Compute a target tick position for a relative move from the current position.

Source

pub fn target_for_delta_revs(&self, delta_revs: f32) -> i32

Compute a target tick position for a relative move in revolutions.

Source

pub fn encoder(&self) -> &Encoder<TIM2>

Expose the underlying encoder.

Source

pub fn encoder_mut(&mut self) -> &mut Encoder<TIM2>

Mutable access to the encoder.

Source

pub fn apply_pid_output(&mut self, u: f32)

Apply PID output.

Auto Trait Implementations§

§

impl<const CS_P: char, const CS_N: u8, const IN1_P: char, const IN1_N: u8, const IN2_P: char, const IN2_N: u8, const SLP_P: char, const SLP_N: u8, const DIS_P: char, const DIS_N: u8> Freeze for Fit0185<CS_P, CS_N, IN1_P, IN1_N, IN2_P, IN2_N, SLP_P, SLP_N, DIS_P, DIS_N>

§

impl<const CS_P: char, const CS_N: u8, const IN1_P: char, const IN1_N: u8, const IN2_P: char, const IN2_N: u8, const SLP_P: char, const SLP_N: u8, const DIS_P: char, const DIS_N: u8> RefUnwindSafe for Fit0185<CS_P, CS_N, IN1_P, IN1_N, IN2_P, IN2_N, SLP_P, SLP_N, DIS_P, DIS_N>

§

impl<const CS_P: char, const CS_N: u8, const IN1_P: char, const IN1_N: u8, const IN2_P: char, const IN2_N: u8, const SLP_P: char, const SLP_N: u8, const DIS_P: char, const DIS_N: u8> Send for Fit0185<CS_P, CS_N, IN1_P, IN1_N, IN2_P, IN2_N, SLP_P, SLP_N, DIS_P, DIS_N>

§

impl<const CS_P: char, const CS_N: u8, const IN1_P: char, const IN1_N: u8, const IN2_P: char, const IN2_N: u8, const SLP_P: char, const SLP_N: u8, const DIS_P: char, const DIS_N: u8> !Sync for Fit0185<CS_P, CS_N, IN1_P, IN1_N, IN2_P, IN2_N, SLP_P, SLP_N, DIS_P, DIS_N>

§

impl<const CS_P: char, const CS_N: u8, const IN1_P: char, const IN1_N: u8, const IN2_P: char, const IN2_N: u8, const SLP_P: char, const SLP_N: u8, const DIS_P: char, const DIS_N: u8> Unpin for Fit0185<CS_P, CS_N, IN1_P, IN1_N, IN2_P, IN2_N, SLP_P, SLP_N, DIS_P, DIS_N>

§

impl<const CS_P: char, const CS_N: u8, const IN1_P: char, const IN1_N: u8, const IN2_P: char, const IN2_N: u8, const SLP_P: char, const SLP_N: u8, const DIS_P: char, const DIS_N: u8> UnwindSafe for Fit0185<CS_P, CS_N, IN1_P, IN1_N, IN2_P, IN2_N, SLP_P, SLP_N, DIS_P, DIS_N>

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.