A library for all types of components used in robots, including controlls for stepper motors, servo motors and more complex assemblies using said motors. Currently all implementations are made for the raspberry pi, though new implementations for more controllers are currently being made.
Let us assume we want to control a simple stepper motor (in this example a 17HE151504S) with a PWM controller connected to the BOARD pins 27 and 19.
Importing the library
```toml
[dependencies]
stepper_lib = "0.10.6"
```
```rust // Include components and data use crate::{StepperCtrl, StepperConst, SyncComp}; use crate::data::LinkedData; // Include the unit system use crate::units::*;
// Pin declerations (BOARD on raspberry pi) const PINDIR : u8 = 27; const PINSTEP : u8 = 19;
// Define distance and max speed const DELTA : Delta = Delta(2.0 * PI); const OMEGA : Omega = Omega(10.0);
fn main() -> Result<(), crate::Error> { // Create the controls for a stepper motor let mut ctrl = StepperCtrl::new(StepperConst::MOT17HE151504S, PINDIR, PINSTEP); // Link the component to a system ctrl.writelink(LinkedData { u: 12.0, // System voltage in volts sf: 1.5 // System safety factor, should be at least 1.0 });
// Apply some loads
ctrl.apply_inertia(Inertia(0.2));
ctrl.apply_force(Force(0.10));
println!("Staring to move");
ctrl.drive_rel(DELTA, OMEGA)?; // Move the motor
println!("Distance {}rad with max speed {:?}rad/s done", DELTA, OMEGA);
Ok(())
} ```