Unipolar stepper motor operation library
Dependents: LAB04_Oppgave1 test_stepper Stepper_Motor_Demo StepperMotorUni_Hello ... more
StepperMotorUni Class Reference
Stepper Motor (Unipolar) control library. More...
#include <StepperMotorUni.h>
Public Types | |
enum | OperationPhaseMode { ONE_PHASE, TWO_PHASE, HALFSTEP } |
Constants for motor rotate mode. More... | |
enum | RotMode { SHORTEST, NO_WRAPAROUND, CLOCKWISE_ONLY, COUNTER_CLOCKWISE_ONLY } |
Constants for motor rotate mode. More... | |
enum | SyncMode { ASYNCHRONOUS, SYNCHRONOUS } |
Constants for syncronization mode. More... | |
enum | PositionDetectPorarity { RISING_EDGE, FALLING_EDGE } |
Constants for position detection edge polarity. More... | |
enum | BrakeMode { SOFT_BRAKE, HARD_BRAKE } |
Constants for position detection edge polarity. More... | |
Public Member Functions | |
StepperMotorUni (PinName out_A, PinName out_B, PinName out_C, PinName out_D, PinName position_detect=NC) | |
Create a stepper motor object connected to specified DigitalOut pins and a DigitalIn pin. | |
float | set_pps (float v) |
Set the pulse width (i.e. | |
void | set_max_pps (float v) |
Set maximum PPS (= minimum pulse width) which will be used in finding home position. | |
int | find_home_position (PositionDetectPorarity edge) |
Find home position: rotate the motor until the detection edge comes. | |
void | set_home_position (void) |
Update home position. | |
int | go_position (int v) |
Turn the motor to defined position (by steps from home position) | |
void | go_angle (float angle) |
Turn the motor to defined position (by angle (degree)) from home position) | |
int | move_steps (int s) |
Turn the motor to defined position (by steps from current position) | |
int | move_rotates (float r) |
Turn the motor to defined rotation (from current position) | |
void | set_operation_phase_mode (OperationPhaseMode v) |
Interface for opertion phase mode setting. | |
void | set_rot_mode (RotMode m) |
Interface for motor rotate mode setting. | |
void | set_sync_mode (SyncMode m) |
Interface for syncronization mode setting. | |
int | distance (void) |
Check remaining distance that motor need to move. | |
void | set_pause (int sw) |
Pause/Resume the motor action. | |
void | brake (void) |
Pause/Resume the motor action. | |
void | set_power_ctrl (int sw) |
Auto power control enable. | |
void | set_steps_per_rotate (int steps) |
Setting for steps/rotate. | |
void | set_ramp_control (float initial_speed_rate, int ramp_steps) |
Setting for ramp control. |
Detailed Description
Stepper Motor (Unipolar) control library.
- Version:
- 1.1.3
- Date:
- 13-Sep-2017
Copyright: 2010, 2014, 2015, 2017 Tedd OKANO Released under the Apache 2 license License
The library that controls stepper motor via motor driver chip This is a driver for a unipolar stepper motor.
Example:
#include "mbed.h" #include "StepperMotorUni.h" StepperMotorUni motor( p26, p25, p24, p23 ); int main() { motor.set_pps( 50 ); while ( 1 ) { motor.move_steps( 24 ); wait( 1 ); motor.move_steps( -24 ); wait( 1 ); } }
version 0.51 (27-Nov-2010) // initial version (un-published) version 0.6 (15-Jan-2014) // compatible to LPC1768, LPC11U24 and LPC1114 targets version 1.0 (19-Jun-2014) // version 1.0 release version 1.0.1 (14-Apr-2015) // API document correction version 1.1 (21-Apr-2015) // ramp control function enabled version 1.1.1 (22-Apr-2015) // fixed: find_home_position compatibility with ramp control feature version 1.1.2 (27-Apr-2015) // fixed: init_done behavior version 1.1.3 (13-Sep-2017) // fixed: keeping stopped position while power_ctrl is set false
Definition at line 53 of file StepperMotorUni.h.
Member Enumeration Documentation
enum BrakeMode |
Constants for position detection edge polarity.
Definition at line 84 of file StepperMotorUni.h.
enum OperationPhaseMode |
Constants for motor rotate mode.
- Enumerator:
ONE_PHASE 1 phase operation (default)
TWO_PHASE 2 phase operation
HALFSTEP halfstep operation
Definition at line 58 of file StepperMotorUni.h.
Constants for position detection edge polarity.
- Enumerator:
RISING_EDGE position detection done by rising edge
FALLING_EDGE position detection done by falling edge
Definition at line 78 of file StepperMotorUni.h.
enum RotMode |
Constants for motor rotate mode.
- Enumerator:
SHORTEST turn by shortest direction (default)
NO_WRAPAROUND do not accross home position
CLOCKWISE_ONLY one-way: clockwise turn
COUNTER_CLOCKWISE_ONLY one-way: counter clockwise turn
Definition at line 65 of file StepperMotorUni.h.
enum SyncMode |
Constants for syncronization mode.
- Enumerator:
ASYNCHRONOUS program does wait motor turn completion (default)
SYNCHRONOUS program doesn't wait motor turn completion
Definition at line 72 of file StepperMotorUni.h.
Constructor & Destructor Documentation
StepperMotorUni | ( | PinName | out_A, |
PinName | out_B, | ||
PinName | out_C, | ||
PinName | out_D, | ||
PinName | position_detect = NC |
||
) |
Create a stepper motor object connected to specified DigitalOut pins and a DigitalIn pin.
- Parameters:
-
out_A DigitalOut pin for motor pulse signal-A out_B DigitalOut pin for motor pulse signal-B out_C DigitalOut pin for motor pulse signal-C out_D DigitalOut pin for motor pulse signal-D position_detect DigitalIn pin for home position detection (option). if not defined, "find_home_position()" function cannot be used
Definition at line 48 of file StepperMotorUni.cpp.
Member Function Documentation
void brake | ( | void | ) |
Pause/Resume the motor action.
- Parameters:
-
sw use "true" for pause, "false" (default) for resume
Definition at line 227 of file StepperMotorUni.cpp.
int distance | ( | void | ) |
Check remaining distance that motor need to move.
software can check if the motor action completed in asynchronous mode
- Returns:
- remaining steps that motor need to go
Definition at line 217 of file StepperMotorUni.cpp.
int find_home_position | ( | PositionDetectPorarity | edge ) |
Find home position: rotate the motor until the detection edge comes.
Turns the motor until the home position detected. The "home position" is a reference point for the step and angle. It will be step=0 and angle=0. The detection signal edge can be defined by an argument. It follows the rotate mode. When the edge is detected, the motor will be stopped and it will be the new home position. If no detection signal detected, no home position update done.
- Parameters:
-
edge defines detection edge rise or fall
Definition at line 94 of file StepperMotorUni.cpp.
void go_angle | ( | float | angle ) |
Turn the motor to defined position (by angle (degree)) from home position)
Make motor move to absolute position
- Parameters:
-
v the position defined by steps from home position
Definition at line 169 of file StepperMotorUni.cpp.
int go_position | ( | int | v ) |
Turn the motor to defined position (by steps from home position)
Make motor move to absolute position
- Parameters:
-
v the position defined by steps from home position
Definition at line 332 of file StepperMotorUni.cpp.
int move_rotates | ( | float | r ) |
Turn the motor to defined rotation (from current position)
Make motor rotate
- Parameters:
-
r number of rotation start from current position
Definition at line 180 of file StepperMotorUni.cpp.
int move_steps | ( | int | s ) |
Turn the motor to defined position (by steps from current position)
Make motor move to defined position
- Parameters:
-
v the position defined by steps from current position
Definition at line 174 of file StepperMotorUni.cpp.
void set_home_position | ( | void | ) |
Update home position.
Set the home position as current motor position.
Definition at line 159 of file StepperMotorUni.cpp.
void set_max_pps | ( | float | v ) |
Set maximum PPS (= minimum pulse width) which will be used in finding home position.
- Parameters:
-
v maximum pulse per second : lower number makes the turn slower (default = 100)
Definition at line 89 of file StepperMotorUni.cpp.
void set_operation_phase_mode | ( | OperationPhaseMode | v ) |
Interface for opertion phase mode setting.
- Parameters:
-
v Driving phase mode change : ONE_PHASE (default), TWO_PHASE or HALFSTEP
Definition at line 186 of file StepperMotorUni.cpp.
void set_pause | ( | int | sw ) |
Pause/Resume the motor action.
- Parameters:
-
sw use "true" for pause, "false" (default) for resume
Definition at line 222 of file StepperMotorUni.cpp.
void set_power_ctrl | ( | int | sw ) |
Auto power control enable.
If the auto power control is enabled, the motor power will be turned-off when it stays same place
- Parameters:
-
sw use "true" for pause, "false" (default) for resume
Definition at line 256 of file StepperMotorUni.cpp.
float set_pps | ( | float | v ) |
Set the pulse width (i.e.
motor turning speed)
- Parameters:
-
v pulse per second (pps) : lower number makes the turn slower (default = 100)
Definition at line 78 of file StepperMotorUni.cpp.
void set_ramp_control | ( | float | initial_speed_rate, |
int | ramp_steps | ||
) |
Setting for ramp control.
This function enables the ramp-up and ramp-down of the motor behavior
- Parameters:
-
initial_speed_rate speed rate. if the pps was set to 50pps and initial_speed_rate is given like 0.1, the ramp-up-start and ramp-dowm-end speed will be 5pps (= 0.1 * 50pps) ramp_steps the steps for ramp-up and ramp-down.
Definition at line 266 of file StepperMotorUni.cpp.
void set_rot_mode | ( | RotMode | m ) |
Interface for motor rotate mode setting.
Example:
StepperMotor m( p21, p22, p23, p24 );
int main() {
m.set_rot_mode( StepperMotor::NO_WRAPAROUND );
...
- Parameters:
-
m motor rotate mode : SHORTEST (default), NO_WRAPAROUND, CLOCKWISE_ONLY or COUNTER_CLOCKWISE_ONLY
Definition at line 207 of file StepperMotorUni.cpp.
void set_steps_per_rotate | ( | int | steps ) |
Setting for steps/rotate.
This parameter is required if program want to use the "go_angle()" interface. The angle will be calculated from this parameter.
- Parameters:
-
steps per rotate
Definition at line 261 of file StepperMotorUni.cpp.
void set_sync_mode | ( | SyncMode | m ) |
Interface for syncronization mode setting.
Example:
StepperMotor m( p21, p22, p23, p24 );
int main() {
m.set_sync_mode( StepperMotor::NO_WRAPAROUND );
...
- Parameters:
-
m motor rotate mode : ASYNCHRONOUS (default) or SYNCHRONOUS
Definition at line 212 of file StepperMotorUni.cpp.
Generated on Wed Jul 13 2022 21:26:19 by 1.7.2