Stepper motor speed ramp generator. Given acceleration, target speed and target step to stop at, generates acceleration or deceleration profile for the stepper motor, in the form of delays between steps.
```rust use stepgen::{new}; let mut stepper = new(1000000);
stepper.setacceleration(1000 << 8); // 1200 steps per second per second stepper.settargetstep(1000); // stop at step 1000 stepper.settargetspeed(800 << 8); // 240RPM (4 turns per second) println!("First delay {}", stepper.firstdelay);
// Take 99 steps for _ in 0..99 { stepper.next(); }
asserteq!(99, stepper.currentstep()); asserteq!(113621, stepper.currentspeed()); assert_eq!(2242, (stepper.next() + 128) >> 8); // delay for 100th step, rounded to nearest integer ```
In few APIs, stepgen keeps numbers as fixed-point numbers, using least significant 8 bits for the fractional part and the remaining bits for the integral part.
[1] [Generate stepper-motor speed profiles in real time](http://www.embedded.com/design/mcus-processors-and-socs/4006438/Generate-stepper-motor-speed-profiles-in-real-time)
Licensed under either of
at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.