Skip to main content

FourWire

Struct FourWire 

Source
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>

Source

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.

Source

pub fn with_step_interval(self, micros: u32) -> Self

Sets the pause after each step, which sets the speed.

§Arguments
  • micros - the interval in microseconds.
§Returns

The driver.

Source

pub fn position(&self) -> i32

Returns the step count since the driver was built, forward positive.

Source

pub fn drive(&self) -> Drive

Returns the drive pattern in use.

Source

pub fn release(self) -> ((A, B, C, Dp), D)

Gives back the coil lines and the delay.

§Returns

The pins and delay the driver was built from.

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,

Source

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.

Source

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.

Source

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.

Trait Implementations§

Source§

impl<A, B, C, Dp, D, E> Actuator for FourWire<A, B, C, Dp, D>
where A: OutputPin<Error = E> + Send, B: OutputPin<Error = E> + Send, C: OutputPin<Error = E> + Send, Dp: OutputPin<Error = E> + Send, D: DelayNs + Send, E: Debug,

Source§

type Command = i32

The command accepted by a single application, for example a setpoint.
Source§

async fn apply(&mut self, count: i32) -> Result<()>

Applies a command to the actuator. Read more
§

fn map_command<F, C>(self, convert: F) -> MapCommand<Self, F, C>
where Self: Sized, F: FnMut(C) -> Self::Command,

Wraps this actuator so every command passes through convert first. Read more
Source§

impl<A: Debug, B: Debug, C: Debug, Dp: Debug, D: Debug> Debug for FourWire<A, B, C, Dp, D>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<A, B, C, Dp, D> Freeze for FourWire<A, B, C, Dp, D>
where D: Freeze, A: Freeze, B: Freeze, C: Freeze, Dp: Freeze,

§

impl<A, B, C, Dp, D> RefUnwindSafe for FourWire<A, B, C, Dp, D>

§

impl<A, B, C, Dp, D> Send for FourWire<A, B, C, Dp, D>
where D: Send, A: Send, B: Send, C: Send, Dp: Send,

§

impl<A, B, C, Dp, D> Sync for FourWire<A, B, C, Dp, D>
where D: Sync, A: Sync, B: Sync, C: Sync, Dp: Sync,

§

impl<A, B, C, Dp, D> Unpin for FourWire<A, B, C, Dp, D>
where D: Unpin, A: Unpin, B: Unpin, C: Unpin, Dp: Unpin,

§

impl<A, B, C, Dp, D> UnsafeUnpin for FourWire<A, B, C, Dp, D>

§

impl<A, B, C, Dp, D> UnwindSafe for FourWire<A, B, C, Dp, D>

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.