Struct MotorDriver

Source
pub struct MotorDriver<DRIVER: Driver, SLEEP, FAULT: InputPin> { /* private fields */ }
Expand description

Represents a motor driver, providing access to various modes of operation.

This struct facilitates the creation of four different modes:

Implementations§

Source§

impl<IN1, IN2, IN3, IN4, SLEEP, FAULT> MotorDriver<SplitDriver<IN1, IN2, IN3, IN4>, Option<SLEEP>, FAULT>
where IN1: OutputPin, IN2: OutputPin, IN3: OutputPin, IN4: OutputPin, SLEEP: OutputPin, FAULT: InputPin,

Source

pub fn new_split( in1: IN1, in2: IN2, in3: IN3, in4: IN4, sleep: Option<SLEEP>, fault: Option<FAULT>, ) -> SplitDriverType<IN1, IN2, IN3, IN4, SLEEP, FAULT>
where IN1: OutputPin, IN2: OutputPin, IN3: OutputPin, IN4: OutputPin,

Creates a new MotorDriver instance with split control mode.

In split mode, each bridge of the motor driver can be controlled independently.

§Example
use drv8833_driver::driver::MotorDriver;

let in1 = PinDriver::output(peripherals.pins.gpio5)?;
let in2 = PinDriver::output(peripherals.pins.gpio4)?;
let in3 = PinDriver::output(peripherals.pins.gpio18)?;
let in4 = PinDriver::output(peripherals.pins.gpio19)?;
let sleep = PinDriver::output(peripherals.pins.gpio3)?;

let mut motor = MotorDriver::new_split(
    in1, in2, in3, in4, Some(sleep), None::<PinDriver<AnyInputPin, Input>>,
);
Source§

impl<IN1, IN2, IN3, IN4, SLEEP, FAULT> MotorDriver<PwmSplitDriver<IN1, IN2, IN3, IN4>, Option<SLEEP>, FAULT>
where IN1: SetDutyCycle, IN2: SetDutyCycle, IN3: SetDutyCycle, IN4: SetDutyCycle, SLEEP: OutputPin, FAULT: InputPin,

Source

pub fn new_pwm_split( in1: IN1, in2: IN2, in3: IN3, in4: IN4, sleep: Option<SLEEP>, fault: Option<FAULT>, ) -> PwmSplitDriverType<IN1, IN2, IN3, IN4, SLEEP, FAULT>

Creates a new MotorDriver instance in PWM split control mode.

In this mode, each bridge pin is controlled individually via PWM signals. Note that using this mode may require a significant number of PWM channels, especially if multiple modules are in use. If your device has limited PWM channels available, you may prefer using MotorDriver::new_pwm_parallel, which consumes fewer PWM channels but sacrifices individual control over both bridges.

§Example:
use drv8833_driver::driver::MotorDriver;

let sleep = PinDriver::output(peripherals.pins.gpio3)?;
let timer = LedcTimerDriver::new(peripherals.ledc.timer0, &TimerConfig::default())?;

let in1 = LedcDriver::new(peripherals.ledc.channel0, &timer, peripherals.pins.gpio5)?;
let in2 = LedcDriver::new(peripherals.ledc.channel1, &timer, peripherals.pins.gpio4)?;
let in3 = LedcDriver::new(peripherals.ledc.channel2, &timer, peripherals.pins.gpio18)?;
let in4 = LedcDriver::new(peripherals.ledc.channel3, &timer, peripherals.pins.gpio19)?;

let mut motor = MotorDriver::new_pwm_split(
    in1, in2, in3, in4, Some(sleep), None::<PinDriver<AnyInputPin, Input>>,
);
Source§

impl<IN1, IN2, IN3, IN4, SLEEP, FAULT> MotorDriver<ParallelDriver<IN1, IN2, IN3, IN4>, Option<SLEEP>, FAULT>
where IN1: OutputPin, IN2: OutputPin, IN3: OutputPin, IN4: OutputPin, SLEEP: OutputPin, FAULT: InputPin,

Source

pub fn new_parallel( in1: IN1, in2: IN2, in3: IN3, in4: IN4, sleep: Option<SLEEP>, fault: Option<FAULT>, ) -> ParallelDriverType<IN1, IN2, IN3, IN4, SLEEP, FAULT>
where IN1: OutputPin, IN2: OutputPin, IN3: OutputPin, IN4: OutputPin,

Creates a new instance of MotorDriver in parallel control mode.

In this mode, both bridges are driven with the same inputs, causing them to behave identically. The primary advantage of this mode is that it effectively doubles the current output when the bridges are physically connected in parallel, with IN1 connected to IN3 and IN2 connected to IN4.

§Example:
use drv8833_driver::driver::MotorDriver;

let in1 = PinDriver::output(peripherals.pins.gpio5)?;
let in2 = PinDriver::output(peripherals.pins.gpio4)?;
let in3 = PinDriver::output(peripherals.pins.gpio18)?;
let in4 = PinDriver::output(peripherals.pins.gpio19)?;
let sleep = PinDriver::output(peripherals.pins.gpio3)?;

let mut motor = MotorDriver::new_parallel(
    in1, in2, in3, in4, Some(sleep), None::<PinDriver<AnyInputPin, Input>>,
);
Source§

impl<IN1, IN2, IN3, IN4, PWM, FAULT> MotorDriver<PwmParallelDriver<IN1, IN2, IN3, IN4, Arc<Mutex<PWM>>>, Arc<Mutex<PWM>>, FAULT>
where IN1: OutputPin, IN2: OutputPin, IN3: OutputPin, IN4: OutputPin, FAULT: InputPin,

Source

pub fn new_pwm_parallel( in1: IN1, in2: IN2, in3: IN3, in4: IN4, pwm: PWM, fault: Option<FAULT>, ) -> PwmParallelDriverType<IN1, IN2, IN3, IN4, PWM, FAULT>
where IN1: OutputPin, IN2: OutputPin, IN3: OutputPin, IN4: OutputPin,

Creates a new MotorDriver instance with PWM parallel control mode.

In PWM parallel mode, a single PWM channel is used to control all four bridge inputs. This allows simultaneous control of all inputs. It’s useful for scenarios where a single motor needs increased current, achieved by connecting IN1 with IN3 and IN2 with IN4.

§Example
use drv8833_driver::driver::Motor;

let in1 = PinDriver::output(peripherals.pins.gpio5)?;
let in2 = PinDriver::output(peripherals.pins.gpio4)?;
let in3 = PinDriver::output(peripherals.pins.gpio18)?;
let in4 = PinDriver::output(peripherals.pins.gpio19)?;

let timer = LedcTimerDriver::new(peripherals.ledc.timer3, &TimerConfig::default())?;
let sleep = LedcDriver::new(peripherals.ledc.channel0, &timer, peripherals.pins.gpio3)?;

let mut motor = Motor::new_pwm_parallel(
    in1, in2, in3, in4, sleep, None::<PinDriver<AnyInputPin, Input>>,
);
Source§

impl<IN1, IN2, IN3, IN4, PWM, FAULT> MotorDriver<SplitDriver<IN1, IN2, IN3, IN4>, PWM, FAULT>
where IN1: OutputPin, IN2: OutputPin, IN3: OutputPin, IN4: OutputPin, FAULT: InputPin,

Source

pub fn new_pwm_split_single( in1: IN1, in2: IN2, in3: IN3, in4: IN4, pwm: PWM, fault: Option<FAULT>, ) -> PwmSplitSingleDriverType<IN1, IN2, IN3, IN4, PWM, FAULT>
where IN1: OutputPin, IN2: OutputPin, IN3: OutputPin, IN4: OutputPin,

Creates a new MotorDriver instance with PWM split single control mode.

In this mode, the PWM signal is applied to the eep PIN instead of each IN pin, thus conserving PWM channels.

§Example
use drv8833_driver::driver::Motor;

let in1 = PinDriver::output(peripherals.pins.gpio5)?;
let in2 = PinDriver::output(peripherals.pins.gpio4)?;
let in3 = PinDriver::output(peripherals.pins.gpio18)?;
let in4 = PinDriver::output(peripherals.pins.gpio19)?;

let timer = LedcTimerDriver::new(peripherals.ledc.timer1, &TimerConfig::default())?;
let pwm = LedcDriver::new(peripherals.ledc.channel1, &timer, peripherals.pins.gpio3)?;

let mut motor = Motor::new_pwm_split_single(
    in1, in2, in3, in4, pwm, None::<PinDriver<AnyInputPin, Input>>,
);
Source§

impl<DRIVER, SLEEP, FAULT> MotorDriver<DRIVER, SLEEP, FAULT>
where DRIVER: Driver, SLEEP: SetDutyCycle, FAULT: InputPin,

Source

pub fn set_duty_cycle(&mut self, percent: u8) -> Result<(), MotorDriverError>

Source§

impl<DRIVER, SLEEP, FAULT> MotorDriver<DRIVER, Option<SLEEP>, FAULT>
where DRIVER: Driver, SLEEP: OutputPin, FAULT: InputPin,

Source

pub fn sleep(&mut self) -> Result<(), MotorDriverError>

Puts the device into a low power sleep state, In this state, the H-bridges are disabled, the gate drive charge pump is stopped, all internal logic is reset, and all internal clocks are stopped. All inputs are ignored until MotorDriver::wakeup is called.

Source

pub fn wakeup(&mut self) -> Result<(), MotorDriverError>

Wake up the device from sleep mode.

Source§

impl<DRIVER, PWM, FAULT> MotorDriver<DRIVER, PWM, FAULT>
where DRIVER: Driver, FAULT: InputPin,

Source

pub fn is_faulty(&mut self) -> Result<bool, MotorDriverError>

Logic low when in fault condition (over-temperature, over-current)

Trait Implementations§

Source§

impl<DRIVER: Driver, SLEEP, FAULT: InputPin> Deref for MotorDriver<DRIVER, SLEEP, FAULT>

Source§

type Target = DRIVER

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl<DRIVER: Driver, SLEEP, FAULT: InputPin> DerefMut for MotorDriver<DRIVER, SLEEP, FAULT>

Source§

fn deref_mut(&mut self) -> &mut Self::Target

Mutably dereferences the value.

Auto Trait Implementations§

§

impl<DRIVER, SLEEP, FAULT> Freeze for MotorDriver<DRIVER, SLEEP, FAULT>
where DRIVER: Freeze, SLEEP: Freeze, FAULT: Freeze,

§

impl<DRIVER, SLEEP, FAULT> RefUnwindSafe for MotorDriver<DRIVER, SLEEP, FAULT>
where DRIVER: RefUnwindSafe, SLEEP: RefUnwindSafe, FAULT: RefUnwindSafe,

§

impl<DRIVER, SLEEP, FAULT> Send for MotorDriver<DRIVER, SLEEP, FAULT>
where DRIVER: Send, SLEEP: Send, FAULT: Send,

§

impl<DRIVER, SLEEP, FAULT> Sync for MotorDriver<DRIVER, SLEEP, FAULT>
where DRIVER: Sync, SLEEP: Sync, FAULT: Sync,

§

impl<DRIVER, SLEEP, FAULT> Unpin for MotorDriver<DRIVER, SLEEP, FAULT>
where DRIVER: Unpin, SLEEP: Unpin, FAULT: Unpin,

§

impl<DRIVER, SLEEP, FAULT> UnwindSafe for MotorDriver<DRIVER, SLEEP, FAULT>
where DRIVER: UnwindSafe, SLEEP: UnwindSafe, FAULT: 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<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
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.