pub struct StepDir<S, R, D> { /* private fields */ }Expand description
A stepper behind a step/direction driver chip such as an A4988 or a DRV8825.
Each step sets the direction line and holds it for the pulse width, since the
chip reads the direction on the step line’s rising edge and needs it settled
first. Then it pulses the step line high for the pulse width, brings it low, and
waits the step interval. Microstepping, current limiting, and enable are the
chip’s own pins and settings, outside this driver. As an [Actuator] the command
is a signed step count.
§Examples
use pamoja_actuators::stepper::StepDir;
use pamoja_core::Actuator;
use pamoja_hal::digital::PinState::{High, Low};
use pamoja_hal::script::{block_on, DelayLog, PinScript};
let mut motor = StepDir::new(PinScript::new([]), PinScript::new([]), DelayLog::new());
block_on(motor.apply(-1))?;
assert_eq!(motor.position(), -1);
let ((step, direction), _) = motor.release();
assert_eq!(direction.driven(), [Low]);
assert_eq!(step.driven(), [High, Low]);Implementations§
Source§impl<S, R, D> StepDir<S, R, D>
impl<S, R, D> StepDir<S, R, D>
Sourcepub fn new(step: S, direction: R, delay: D) -> Self
pub fn new(step: S, direction: R, delay: D) -> Self
Wraps the step and direction lines, without driving them.
§Arguments
step- the line the chip counts rising edges on.direction- the line the chip reads the direction from; high is forward.delay- the timer that shapes the pulses and paces the steps.
§Returns
The driver, with DEFAULT_PULSE_MICROS pulses at DEFAULT_STEP_MICROS
a step, counting from zero.
Sourcepub fn with_pulse_width(self, micros: u32) -> Self
pub fn with_pulse_width(self, micros: u32) -> Self
Sourcepub fn with_step_interval(self, micros: u32) -> Self
pub fn with_step_interval(self, micros: u32) -> Self
Source§impl<S, R, D, E> StepDir<S, R, D>where
S: OutputPin<Error = E>,
R: OutputPin<Error = E>,
D: DelayNs,
impl<S, R, D, E> StepDir<S, R, D>where
S: OutputPin<Error = E>,
R: OutputPin<Error = E>,
D: DelayNs,
Sourcepub fn step(&mut self, direction: Direction) -> Result<(), DriverError<E>>
pub fn step(&mut self, direction: Direction) -> Result<(), DriverError<E>>
Takes one step and waits the step interval.
§Arguments
direction- which way to step.
§Errors
Returns DriverError::Bus if a line cannot be driven.
Sourcepub fn steps(&mut self, count: i32) -> Result<(), DriverError<E>>
pub fn steps(&mut self, count: i32) -> Result<(), DriverError<E>>
Takes count steps, backward when negative.
§Arguments
count- the signed number of steps.
§Errors
Returns DriverError::Bus if a line cannot be driven; the steps already
taken stay counted.