pub struct StepperMotor<STEP, DIR, DELAY, STATE = Idle>{ /* private fields */ }Expand description
Stepper motor driver with type-state safety.
Generic over:
STEP: STEP pin type (must implementOutputPin)DIR: DIR pin type (must implementOutputPin)DELAY: Delay provider (must implementDelayNs)STATE: Type-state marker (defaults toIdle)
Implementations§
Source§impl<STEP, DIR, DELAY, STATE> StepperMotor<STEP, DIR, DELAY, STATE>
impl<STEP, DIR, DELAY, STATE> StepperMotor<STEP, DIR, DELAY, STATE>
Sourcepub fn position_steps(&self) -> Steps
pub fn position_steps(&self) -> Steps
Get current position in steps.
Sourcepub fn position_degrees(&self) -> Degrees
pub fn position_degrees(&self) -> Degrees
Get current position in degrees.
Sourcepub fn constraints(&self) -> &MechanicalConstraints
pub fn constraints(&self) -> &MechanicalConstraints
Get the mechanical constraints.
Sourcepub fn state_name(&self) -> &'static str
pub fn state_name(&self) -> &'static str
Get the current state name.
Source§impl<STEP, DIR, DELAY> StepperMotor<STEP, DIR, DELAY, Idle>
impl<STEP, DIR, DELAY> StepperMotor<STEP, DIR, DELAY, Idle>
Sourcepub fn move_to(
self,
target: Degrees,
) -> Result<StepperMotor<STEP, DIR, DELAY, Moving>, (Self, Error)>
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.
Sourcepub fn move_by(
self,
delta: Degrees,
) -> Result<StepperMotor<STEP, DIR, DELAY, Moving>, (Self, Error)>
pub fn move_by( self, delta: Degrees, ) -> Result<StepperMotor<STEP, DIR, DELAY, Moving>, (Self, Error)>
Move by a relative amount in degrees.
Sourcepub fn set_origin(&mut self)
pub fn set_origin(&mut self)
Set the current position as the origin (zero).
Sourcepub fn set_position(&mut self, degrees: Degrees)
pub fn set_position(&mut self, degrees: Degrees)
Set the current position to a specific value.
Sourcepub fn execute(
self,
trajectory_name: &str,
registry: &TrajectoryRegistry,
) -> Result<Self, (Self, Error)>
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 registryregistry- 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
Sourcepub fn move_to_blocking(self, target: Degrees) -> Result<Self, (Self, Error)>
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>
impl<STEP, DIR, DELAY> StepperMotor<STEP, DIR, DELAY, Moving>
Sourcepub fn step(&mut self) -> Result<bool>
pub fn step(&mut self) -> Result<bool>
Execute one step pulse.
Returns true if the move is complete.
Sourcepub fn is_complete(&self) -> bool
pub fn is_complete(&self) -> bool
Check if the move is complete.
Sourcepub fn phase(&self) -> MotionPhase
pub fn phase(&self) -> MotionPhase
Get current motion phase.
Sourcepub fn finish(self) -> StepperMotor<STEP, DIR, DELAY, Idle>
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.
Sourcepub fn run_to_completion(self) -> Result<StepperMotor<STEP, DIR, DELAY, Idle>>
pub fn run_to_completion(self) -> Result<StepperMotor<STEP, DIR, DELAY, Idle>>
Run the move to completion (blocking).