pub struct FourWire<A, B, C, Dp, D> { /* private fields */ }Expand description
A four-wire stepper driven coil by coil, through a transistor array such as a ULN2003 or an H-bridge.
Each step energizes the coils the Drive pattern names, pin A for the
pattern’s high bit down to pin D for its low bit, then waits the step interval.
The Position counts steps from where the motor was when the driver was
built. As an [Actuator] the command is a signed step count.
§Examples
use pamoja_actuators::stepper::{Drive, FourWire};
use pamoja_core::Actuator;
use pamoja_hal::digital::PinState::{High, Low};
use pamoja_hal::script::{block_on, DelayLog, PinScript};
let pins = (PinScript::new([]), PinScript::new([]), PinScript::new([]), PinScript::new([]));
let mut motor = FourWire::new(pins, DelayLog::new(), Drive::FullStep);
block_on(motor.apply(2))?;
assert_eq!(motor.position(), 2);
// Each step advances to the next full-step pattern: 0110 then 0011, so coil A
// stays off and coil B is on for the first step only.
let ((a, b, _, _), _) = motor.release();
assert_eq!(a.driven(), [Low, Low]);
assert_eq!(b.driven(), [High, Low]);Implementations§
Source§impl<A, B, C, Dp, D> FourWire<A, B, C, Dp, D>
impl<A, B, C, Dp, D> FourWire<A, B, C, Dp, D>
Sourcepub fn new(coils: (A, B, C, Dp), delay: D, drive: Drive) -> Self
pub fn new(coils: (A, B, C, Dp), delay: D, drive: Drive) -> Self
Wraps the four coil lines, without driving them.
§Arguments
coils- the lines for coils A, B, C, and D, in the motor’s phase order.delay- the timer that paces the steps.drive- the coil pattern to step through.
§Returns
The driver, at DEFAULT_STEP_MICROS a step, counting from zero.
Sourcepub fn with_step_interval(self, micros: u32) -> Self
pub fn with_step_interval(self, micros: u32) -> Self
Sourcepub fn position(&self) -> i32
pub fn position(&self) -> i32
Returns the step count since the driver was built, forward positive.
Sourcepub fn release(self) -> ((A, B, C, Dp), D)
pub fn release(self) -> ((A, B, C, Dp), D)
Source§impl<A, B, C, Dp, D, E> FourWire<A, B, C, Dp, D>where
A: OutputPin<Error = E>,
B: OutputPin<Error = E>,
C: OutputPin<Error = E>,
Dp: OutputPin<Error = E>,
D: DelayNs,
impl<A, B, C, Dp, D, E> FourWire<A, B, C, Dp, D>where
A: OutputPin<Error = E>,
B: OutputPin<Error = E>,
C: OutputPin<Error = E>,
Dp: 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 coil 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 coil line cannot be driven; the steps
already taken stay counted.
Sourcepub fn idle(&mut self) -> Result<(), DriverError<E>>
pub fn idle(&mut self) -> Result<(), DriverError<E>>
Drops every coil, so the motor holds nothing and draws nothing.
§Errors
Returns DriverError::Bus if a coil line cannot be driven.