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
impl Driver
pub fn new() -> Driver
Sourcepub fn move_to(&mut self, location: i64)
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()
).
Sourcepub fn set_max_speed(&mut self, steps_per_second: f32)
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.
Sourcepub fn set_acceleration(&mut self, acceleration: f32)
pub fn set_acceleration(&mut self, acceleration: f32)
Set the acceleration/deceleration rate (in steps/sec/sec
).
Sourcepub fn acceleration(&self) -> f32
pub fn acceleration(&self) -> f32
Get the acceleration/deceleration rate.
Sourcepub fn set_speed(&mut self, speed: f32)
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()
.
Sourcepub fn distance_to_go(&self) -> i64
pub fn distance_to_go(&self) -> i64
Get the number of steps to go until reaching the target position.
Sourcepub fn target_position(&self) -> i64
pub fn target_position(&self) -> i64
Get the most recently set target position.
Sourcepub fn set_current_position(&mut self, position: i64)
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.
Sourcepub fn current_position(&self) -> i64
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.
Sourcepub fn stop(&mut self)
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.
Sourcepub fn is_running(&self) -> bool
pub fn is_running(&self) -> bool
Checks to see if the motor is currently running to a target.
Sourcepub fn poll<C, D>(&mut self, device: D, clock: C) -> Result<(), D::Error>where
C: SystemClock,
D: Device,
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.
Sourcepub fn poll_at_constant_speed<C, D>(
&mut self,
device: D,
clock: C,
) -> Result<bool, D::Error>where
C: SystemClock,
D: Device,
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.