Struct Driver

Source
pub struct Driver { /* private fields */ }
Expand description

A stepper motor driver.

§Note

You may want to use the CummulativeSteps helper to convert a movement in “real” units (e.g. mm or inches) to the correct number of steps.

Implementations§

Source§

impl Driver

Source

pub fn new() -> Driver

Source

pub fn move_to(&mut self, location: i64)

Move to the specified location relative to the zero point (typically set when calibrating using Driver::set_current_position()).

Source

pub fn move_by(&mut self, delta: i64)

Move forward by the specified number of steps.

Source

pub fn set_max_speed(&mut self, steps_per_second: f32)

Set the maximum permitted speed in steps/second.

§Caution

the maximum speed achievable depends on your processor and clock speed. The default max speed is 1.0 step per second.

Source

pub fn max_speed(&self) -> f32

Get the maximum speed.

Source

pub fn set_acceleration(&mut self, acceleration: f32)

Set the acceleration/deceleration rate (in steps/sec/sec).

Source

pub fn acceleration(&self) -> f32

Get the acceleration/deceleration rate.

Source

pub fn set_speed(&mut self, speed: f32)

Set the desired constant speed in steps/sec.

Speeds of more than 1000 steps per second are unreliable. Very slow speeds may be set (eg 0.00027777 for once per hour, approximately). Speed accuracy depends on the system’s clock. Jitter depends on how frequently you call the Driver::poll_at_constant_speed() method. The speed will be limited by the current value of Driver::max_speed().

Source

pub fn speed(&self) -> f32

Get the most recently set speed.

Source

pub fn distance_to_go(&self) -> i64

Get the number of steps to go until reaching the target position.

Source

pub fn target_position(&self) -> i64

Get the most recently set target position.

Source

pub fn set_current_position(&mut self, position: i64)

Reset the current motor position so the current location is considered the new 0 position.

Useful for setting a zero position on a stepper after an initial hardware positioning move.

Source

pub fn current_position(&self) -> i64

Get the current motor position, as measured by counting the number of pulses emitted.

§Note

Stepper motors are an open-loop system, so there’s no guarantee the motor will actually be at that position.

Source

pub fn stop(&mut self)

Sets a new target position that causes the stepper to stop as quickly as possible, using the current speed and acceleration parameters.

Source

pub fn is_running(&self) -> bool

Checks to see if the motor is currently running to a target.

Source

pub fn poll<C, D>(&mut self, device: D, clock: C) -> Result<(), D::Error>
where C: SystemClock, D: Device,

Poll the driver and step it if a step is due.

This function must called as frequently as possoble, but at least once per minimum step time interval, preferably as part of the main loop.

Note that each call to Driver::poll() will make at most one step, and then only when a step is due, based on the current speed and the time since the last step.

§Warning

For correctness, the same SystemClock should be used every time Driver::poll() is called. Failing to do so may mess up internal timing calculations.

Source

pub fn poll_at_constant_speed<C, D>( &mut self, device: D, clock: C, ) -> Result<bool, D::Error>
where C: SystemClock, D: Device,

Poll the motor and step it if a step is due, implementing a constant speed as set by the most recent call to Driver::set_speed().

You must call this as frequently as possible, but at least once per step interval, returns true if the motor was stepped.

Trait Implementations§

Source§

impl Debug for Driver

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for Driver

Source§

fn default() -> Driver

Returns the “default value” for a type. Read more
Source§

impl PartialEq for Driver

Source§

fn eq(&self, other: &Driver) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for Driver

Auto Trait Implementations§

§

impl Freeze for Driver

§

impl RefUnwindSafe for Driver

§

impl Send for Driver

§

impl Sync for Driver

§

impl Unpin for Driver

§

impl UnwindSafe for Driver

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.