Stepper motor control class library
Dependents: StepperMotor_HelloWorld
StepperMotor Class Reference
Stepper Motor control class. More...
#include <StepperMotor.h>
Public Types | |
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... | |
Public Member Functions | |
StepperMotor (PinName out_A=p21, PinName out_B=p22, PinName out_PWR=p23, PinName position_detect=p24) | |
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) | |
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 | set_power_ctrl (int sw) |
Auto power control enable. | |
void | set_steps_per_rotate (int steps) |
Setting for steps/rotate. |
Detailed Description
Stepper Motor control class.
Stepper Motor control library.
Example:
#include "mbed.h" #include "StepperMotor.h" StepperMotor m( p21, p22, p23, p24 ); int main() { m.set_steps_per_rotate( 480 ); m.set_sync_mode( StepperMotor::SYNCHRONOUS ); m.set_power_ctrl( true ); while( 1 ) { m.go_angle( 120 ); wait( 0.5 ); m.go_angle( 240 ); wait( 0.5 ); m.go_angle( 0 ); wait( 0.5 ); m.go_angle( 240 ); wait( 0.5 ); m.go_angle( 120 ); wait( 0.5 ); m.go_angle( 0 ); wait( 0.5 ); } }
- Version:
- 0.6 (13-Sep-2017)
Copyright: 2010 Tedd OKANO, Tsukimidai Communications Syndicate - Crawl Design The library that controls stepper motor via motor driver chip: TA7774 The TA7774 is a driver for a bipolar stepper motor. With this library, mbed will generate 2 phase pulses to operate the motor.
version 0.51 (27-Nov-2010) version 0.6 (13-Sep-2017) // fixed to keep last position while power-control disabled
- Version:
- 0.51(27-Nov-2010)
Copyright: 2010 Tedd OKANO, Tsukimidai Communications Syndicate - Crawl Design The library that controls stepper motor via motor driver chip: TA7774 The TA7774 is a driver for a bipolar stepper motor. With this library, mbed will generate 2 phase pulses to operate the motor.
Definition at line 57 of file StepperMotor.h.
Member Enumeration Documentation
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 75 of file StepperMotor.h.
enum RotMode |
Constants for motor rotate mode.
- Enumerator:
SHORTEST turn by shortest direction
NO_WRAPAROUND do not accross home position
CLOCKWISE_ONLY one-way: clockwise turn
COUNTER_CLOCKWISE_ONLY one-way: counter clockwise turn
Definition at line 61 of file StepperMotor.h.
enum SyncMode |
Constants for syncronization mode.
- Enumerator:
ASYNCHRONOUS program does wait motor turn completion
SYNCHRONOUS program doesn't wait motor turn completion
Definition at line 69 of file StepperMotor.h.
Constructor & Destructor Documentation
StepperMotor | ( | PinName | out_A = p21 , |
PinName | out_B = p22 , |
||
PinName | out_PWR = p23 , |
||
PinName | position_detect = p24 |
||
) |
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_PWR DigitalOut pin for TA7774's power control (option) position_detect DigitalIn pin for home position detection (option)
Definition at line 19 of file StepperMotor.cpp.
Member Function Documentation
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 140 of file StepperMotor.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 57 of file StepperMotor.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 123 of file StepperMotor.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 118 of file StepperMotor.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 home position
Definition at line 127 of file StepperMotor.cpp.
void set_home_position | ( | void | ) |
Update home position.
Set the home position as current motor position.
Definition at line 110 of file StepperMotor.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 53 of file StepperMotor.cpp.
void set_pause | ( | int | sw ) |
Pause/Resume the motor action.
- Parameters:
-
sw use "true" for pause, "false" (default) for resume
Definition at line 144 of file StepperMotor.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 157 of file StepperMotor.cpp.
float set_pps | ( | float | v ) |
Set the pulse width (i.e.
motor turning speed)
- Parameters:
-
v pulse per second : lower number makes the turn slower (default = 100)
Definition at line 43 of file StepperMotor.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 132 of file StepperMotor.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 161 of file StepperMotor.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 136 of file StepperMotor.cpp.
Generated on Wed Jul 13 2022 21:47:06 by
