Expand description
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§
- Cummulative
Steps - 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.
- Multi
Driver - Controller for moving multiple axes in a coordinated fashion.
- Operating
System Clock - A monotonically non-decreasing clock backed by the operating system.
- Step
AndDirection - A
Device
which has step and direction pins. - Step
Context - Extra contextual information passed to a
Device
when itsDevice::step()
method is invoked.
Traits§
- Device
- An interface to the stepper motor.
- System
Clock - Something which records the elapsed real time.
Functions§
- fallible_
func_ device - A device which uses callbacks which may fail.
- func_
device - A
Device
which will call one function for a forward step, and another for a backward one.