stepper_lib
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.
Basis library for the sybot_lib
In Action
Let us assume we want to control a simple stepper motor (in this example a 17HE15_1504_S) with a PWM controller connected to the BCM pins 27 and 19.
# ...
[]
# Include the library configured for the raspberry pi
= { = "0.11.0", = [ "rasp" ] }
# ...
use PI;
// Include components and data
use ;
use LinkedData;
// Include the unit system
use *;
// Pin declerations (BCM on raspberry pi)
const PIN_DIR : u8 = 27;
const PIN_STEP : u8 = 19;
// Define distance and max speed
const DELTA : Delta = Delta;
const OMEGA : Omega = Omega;
(Source: "examples/stepper_motor.rs")
Overview
Features
- Motors
- Stepper motors
- Servo motors
- DC motors
- Components
- Cylinder
- Gear joint
- Cylinder-triangle
- Conveyor
- Tools
- Tongs
- Axial joint
- Calculation
- Complex acceleration curves
- Overloads
- Forces
- Inertias
- Measurements
- Simple switch
- Rotary resolver
- Extendable
- Custom components
- Custom tools
- Minimal
- Fully supports
no_std
environment - Available for basic embedded systems
- Fully supports
- Platforms
- Raspberry Pi and similar
Components
A component (trait SyncComp
in the library) represents a synchronous motor, optionally connected to a mechanical structure that transforms the rotatory movements created by the motor. If a struct implements the SyncComp
trait, it can be linked into a group with SyncCompGroup
, later required in the sybot_lib.
The library does include some standard components commonly used
- Cylinder, a simple cylinder translating the rotatory movements of a motor to a linear extension
- GearJoint, a motor connected to a gear that translates the movement with a certain ratio
- Cylinder-triangle, a cylinder being the hypotenuse in a triangular shape, creating a high torque/slow movement joint
In this example we drive a cylinder by a certain amount of millimeters.
# ...
[]
# Include the library configured for the raspberry pi
= { = "0.11.0", = [ "rasp" ] }
# ...
// Include components and data
use ;
use Cylinder;
use LinkedData;
// Include the unit system
use *;
// Pin declerations (BCM on raspberry pi)
const PIN_DIR : u8 = 27;
const PIN_STEP : u8 = 19;
// Define distance and max speed
const DELTA : Delta = Delta; // 10 millimeters
const OMEGA : Omega = Omega; // 20 millimeters per second
(Source: "examples/cylinder.rs")
Custom components
If a component is desired that is not included in the standard components, then a custom component can be created. Simply implement the SyncComp
trait for the component.
There are two ways of defining a new component
- Defining a super component, which would be the motor to a gear or the cylinder in the
CylinderTriangle
, the only functions that have to be overwritten then are the functions required to communicate with the super component. Though in many cases some kind of ratio is added. - Completely implementing the trait, therefore defining a completely new type of motor.
The following example shows a custom component with a stepper motor as super component. Additionally it prints out a message every time write drive a relative distance.
# ...
[]
# Include the library configured for the raspberry pi
= { = "0.11.0", = [ "rasp" ] }
# ...
// Include components and data
use ;
use LinkedData;
use SimpleMeas;
// Include the unit system
use *;
// Pin declerations (BCM on raspberry pi)
const PIN_DIR : u8 = 27;
const PIN_STEP : u8 = 19;
// Define distance and max speed
const DELTA : Delta = Delta;
const OMEGA : Omega = Omega;
// Defining component structure
// Console output:
// "
// Starting to move ...
// Now driving!
// Distance 10rad with max speed 20rad/s done
// "
(Source: "examples/custom_component.rs")
Tools
The library also includes various simple tools like tongs, axial joints and so on. These tools are controlled by a servo controller, though other types of motors can be used in custom tools by implementing the Tool
trait, just like SyncComp
.
This example controls a simple pair of tongs using a servo motor.
# ...
[]
# Include the library configured for the raspberry pi
= { = "0.11.0", = [ "rasp" ] }
# ...
use Duration;
use sleep;
use ;
use Tongs;
use ServoDriver;
use ServoConst;
// Include the unit system
use *;
// Pin declerations (BCM on raspberry pi)
const PIN_PWM : u8 = 27;
Platforms and simulation
The final goal of the library is to work on as many platforms as possible, even on embedded systems. To configure the library for a specific platform, the right features have to be enabled. Note that some of the features automatically enable std
usage.
The current platforms and features enabled are
- "rasp": Raspberry Pi and similar controller
# Platform features
= [ "std", "dep:rppal" ]
If no platform is selected the library automatically goes into simulation mode. Meaning no movements will be actually executed, no pins will be written to or checked, which can lead to problems. As the library does for example not care if the same two pins are used in simulation mode.
Issues and requests
If you encounter any issues or if you have any request for new features, feel free to create an issue at the GitHub repo.