Skip to main content

StepDir

Struct StepDir 

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

Source

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.

Source

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

Sets the width of the step pulse, and how long the direction is held before it.

§Arguments
  • micros - the time the direction line is held before the step line rises, and the time the step line is then held high.
§Returns

The driver.

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 release(self) -> ((S, R), D)

Gives back the lines and the delay.

§Returns

The step and direction pins and the delay the driver was built from.

Source§

impl<S, R, D, E> StepDir<S, R, D>
where S: OutputPin<Error = E>, R: 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 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 line cannot be driven; the steps already taken stay counted.

Trait Implementations§

Source§

impl<S, R, D, E> Actuator for StepDir<S, R, D>
where S: OutputPin<Error = E> + Send, R: 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<S: Debug, R: Debug, D: Debug> Debug for StepDir<S, R, D>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<S, R, D> Freeze for StepDir<S, R, D>
where S: Freeze, R: Freeze, D: Freeze,

§

impl<S, R, D> RefUnwindSafe for StepDir<S, R, D>

§

impl<S, R, D> Send for StepDir<S, R, D>
where S: Send, R: Send, D: Send,

§

impl<S, R, D> Sync for StepDir<S, R, D>
where S: Sync, R: Sync, D: Sync,

§

impl<S, R, D> Unpin for StepDir<S, R, D>
where S: Unpin, R: Unpin, D: Unpin,

§

impl<S, R, D> UnsafeUnpin for StepDir<S, R, D>

§

impl<S, R, D> UnwindSafe for StepDir<S, R, D>
where S: UnwindSafe, R: UnwindSafe, D: 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<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.