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:
MotorDriver::new_split
: Enables control over each bridge (A and B) independently.MotorDriver::new_parallel
: Treats both bridges as a single unit, effectively doubling the current when connected in parallel.MotorDriver::new_pwm_split
: Allows individual control over each bridge using PWM signals.MotorDriver::new_pwm_split_single
: Allows individual control over each bridge while using a single PWM signal over the eep pin.MotorDriver::new_pwm_parallel
: Controls both bridges simultaneously with a single PWM signal.
Implementations§
Source§impl<IN1, IN2, IN3, IN4, SLEEP, FAULT> MotorDriver<SplitDriver<IN1, IN2, IN3, IN4>, Option<SLEEP>, FAULT>
impl<IN1, IN2, IN3, IN4, SLEEP, FAULT> MotorDriver<SplitDriver<IN1, IN2, IN3, IN4>, Option<SLEEP>, FAULT>
Sourcepub fn new_split(
in1: IN1,
in2: IN2,
in3: IN3,
in4: IN4,
sleep: Option<SLEEP>,
fault: Option<FAULT>,
) -> SplitDriverType<IN1, IN2, IN3, IN4, SLEEP, FAULT>
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>
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,
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,
Sourcepub 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>
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>
impl<IN1, IN2, IN3, IN4, SLEEP, FAULT> MotorDriver<ParallelDriver<IN1, IN2, IN3, IN4>, Option<SLEEP>, FAULT>
Sourcepub fn new_parallel(
in1: IN1,
in2: IN2,
in3: IN3,
in4: IN4,
sleep: Option<SLEEP>,
fault: Option<FAULT>,
) -> ParallelDriverType<IN1, IN2, IN3, IN4, SLEEP, FAULT>
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>
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>
impl<IN1, IN2, IN3, IN4, PWM, FAULT> MotorDriver<PwmParallelDriver<IN1, IN2, IN3, IN4, Arc<Mutex<PWM>>>, Arc<Mutex<PWM>>, FAULT>
Sourcepub fn new_pwm_parallel(
in1: IN1,
in2: IN2,
in3: IN3,
in4: IN4,
pwm: PWM,
fault: Option<FAULT>,
) -> PwmParallelDriverType<IN1, IN2, IN3, IN4, PWM, FAULT>
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>
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>
impl<IN1, IN2, IN3, IN4, PWM, FAULT> MotorDriver<SplitDriver<IN1, IN2, IN3, IN4>, PWM, FAULT>
Sourcepub 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>
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>
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>
impl<DRIVER, SLEEP, FAULT> MotorDriver<DRIVER, SLEEP, FAULT>
pub fn set_duty_cycle(&mut self, percent: u8) -> Result<(), MotorDriverError>
Source§impl<DRIVER, SLEEP, FAULT> MotorDriver<DRIVER, Option<SLEEP>, FAULT>
impl<DRIVER, SLEEP, FAULT> MotorDriver<DRIVER, Option<SLEEP>, FAULT>
Sourcepub fn sleep(&mut self) -> Result<(), MotorDriverError>
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.
Sourcepub fn wakeup(&mut self) -> Result<(), MotorDriverError>
pub fn wakeup(&mut self) -> Result<(), MotorDriverError>
Wake up the device from sleep mode.
Source§impl<DRIVER, PWM, FAULT> MotorDriver<DRIVER, PWM, FAULT>
impl<DRIVER, PWM, FAULT> MotorDriver<DRIVER, PWM, FAULT>
Sourcepub fn is_faulty(&mut self) -> Result<bool, MotorDriverError>
pub fn is_faulty(&mut self) -> Result<bool, MotorDriverError>
Logic low when in fault condition (over-temperature, over-current)