[−][src]Crate accel_stepper
A Rust port of the popular AccelStepper
Arduino stepper
library.
Basic Usage
The most common way of using this crate is by driving an axis to a particular location.
use accel_stepper::{Driver, SystemClock}; let mut axis = Driver::new(); // Make sure to set your device's motion parameters axis.set_max_speed(500.0); axis.set_acceleration(100.0); // The axis needs a clock for timing purposes. This could be an // `accel_stepper::OperatingSystemClock` when compiled with the `std` // feature, or your device's external oscillator #[derive(Debug, Default)] struct TickingClock(RefCell<Duration>); impl SystemClock for TickingClock { fn elapsed(&self) -> Duration { let mut ticks = self.0.borrow_mut(); *ticks = *ticks + Duration::from_millis(10); ticks.clone() } } let clock = TickingClock::default(); let mut forward = 0; let mut back = 0; { // for testing purposes, we'll create a Device which counts the number // of forward/backward steps let mut dev = accel_stepper::func_device(|| forward += 1, || back += 1); // set the desired location axis.move_to(17); // keep polling the axis until it reaches that location while axis.is_running() { axis.poll(&mut dev, &clock)?; } } // we should have arrived at our destination assert_eq!(17, axis.current_position()); // it takes 17 steps forward to reach position 17 assert_eq!(17, forward); assert_eq!(0, back);
Cargo Features
To minimise compile time and code size, this crate uses cargo features.
std
- Enable functionality which depends on the standard library (e.g. the OS clock)hal
- Enable functionality which implementsDevice
on top of traits from theembedded-hal
crate.
Structs
CummulativeSteps | A helper type for determining the number of steps to take when moving a distance in the real world, taking rounding errors into consideration. |
Driver | A stepper motor driver. |
MultiDriver | Controller for moving multiple axes in a coordinated fashion. |
OperatingSystemClock | A monotonically non-decreasing clock backed by the operating system. |
StepAndDirection | A |
StepContext | Extra contextual information passed to a |
Traits
Device | An interface to the stepper motor. |
SystemClock | Something which records the elapsed real time. |
Functions
fallible_func_device | A device which uses callbacks which may fail. |
func_device | A |