StepperMotor

Struct StepperMotor 

Source
pub struct StepperMotor<STEP, DIR, DELAY, STATE = Idle>
where STEP: OutputPin, DIR: OutputPin, DELAY: DelayNs, STATE: MotorState,
{ /* private fields */ }
Expand description

Stepper motor driver with type-state safety.

Generic over:

  • STEP: STEP pin type (must implement OutputPin)
  • DIR: DIR pin type (must implement OutputPin)
  • DELAY: Delay provider (must implement DelayNs)
  • STATE: Type-state marker (defaults to Idle)

Implementations§

Source§

impl<STEP, DIR, DELAY, STATE> StepperMotor<STEP, DIR, DELAY, STATE>
where STEP: OutputPin, DIR: OutputPin, DELAY: DelayNs, STATE: MotorState + StateName,

Source

pub fn name(&self) -> &str

Get the motor name.

Source

pub fn position_steps(&self) -> Steps

Get current position in steps.

Source

pub fn position_degrees(&self) -> Degrees

Get current position in degrees.

Source

pub fn constraints(&self) -> &MechanicalConstraints

Get the mechanical constraints.

Source

pub fn state_name(&self) -> &'static str

Get the current state name.

Source§

impl<STEP, DIR, DELAY> StepperMotor<STEP, DIR, DELAY, Idle>
where STEP: OutputPin, DIR: OutputPin, DELAY: DelayNs,

Source

pub fn move_to( self, target: Degrees, ) -> Result<StepperMotor<STEP, DIR, DELAY, Moving>, (Self, Error)>

Start a move to an absolute position in degrees.

Returns a motor in the Moving state.

Source

pub fn move_by( self, delta: Degrees, ) -> Result<StepperMotor<STEP, DIR, DELAY, Moving>, (Self, Error)>

Move by a relative amount in degrees.

Source

pub fn set_origin(&mut self)

Set the current position as the origin (zero).

Source

pub fn set_position(&mut self, degrees: Degrees)

Set the current position to a specific value.

Source

pub fn execute( self, trajectory_name: &str, registry: &TrajectoryRegistry, ) -> Result<Self, (Self, Error)>

Execute a named trajectory from a registry.

This method looks up the trajectory by name, validates it against the motor’s constraints, and executes it to completion.

§Arguments
  • trajectory_name - Name of the trajectory in the registry
  • registry - The trajectory registry to look up the trajectory
§Returns

Returns Ok(self) with the motor back in Idle state after the move completes.

§Errors

Returns an error if:

  • The trajectory is not found in the registry
  • The trajectory’s target motor doesn’t match this motor’s name
  • The move fails due to limits or hardware errors
Source

pub fn move_to_blocking(self, target: Degrees) -> Result<Self, (Self, Error)>

Move to an absolute position and run to completion (blocking).

This is a convenience method that combines move_to and run_to_completion.

Source§

impl<STEP, DIR, DELAY> StepperMotor<STEP, DIR, DELAY, Moving>
where STEP: OutputPin, DIR: OutputPin, DELAY: DelayNs,

Source

pub fn step(&mut self) -> Result<bool>

Execute one step pulse.

Returns true if the move is complete.

Source

pub fn is_complete(&self) -> bool

Check if the move is complete.

Source

pub fn progress(&self) -> f32

Get move progress (0.0 to 1.0).

Source

pub fn phase(&self) -> MotionPhase

Get current motion phase.

Source

pub fn finish(self) -> StepperMotor<STEP, DIR, DELAY, Idle>

Complete the move and return to Idle state.

This should be called after is_complete() returns true or to abandon a move in progress.

Source

pub fn run_to_completion(self) -> Result<StepperMotor<STEP, DIR, DELAY, Idle>>

Run the move to completion (blocking).

Auto Trait Implementations§

§

impl<STEP, DIR, DELAY, STATE> Freeze for StepperMotor<STEP, DIR, DELAY, STATE>
where STEP: Freeze, DIR: Freeze, DELAY: Freeze,

§

impl<STEP, DIR, DELAY, STATE> RefUnwindSafe for StepperMotor<STEP, DIR, DELAY, STATE>
where STEP: RefUnwindSafe, DIR: RefUnwindSafe, DELAY: RefUnwindSafe, STATE: RefUnwindSafe,

§

impl<STEP, DIR, DELAY, STATE> Send for StepperMotor<STEP, DIR, DELAY, STATE>
where STEP: Send, DIR: Send, DELAY: Send, STATE: Send,

§

impl<STEP, DIR, DELAY, STATE> Sync for StepperMotor<STEP, DIR, DELAY, STATE>
where STEP: Sync, DIR: Sync, DELAY: Sync, STATE: Sync,

§

impl<STEP, DIR, DELAY, STATE> Unpin for StepperMotor<STEP, DIR, DELAY, STATE>
where STEP: Unpin, DIR: Unpin, DELAY: Unpin, STATE: Unpin,

§

impl<STEP, DIR, DELAY, STATE> UnwindSafe for StepperMotor<STEP, DIR, DELAY, STATE>
where STEP: UnwindSafe, DIR: UnwindSafe, DELAY: UnwindSafe, STATE: 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.