uStepper S
|
Prototype of class for accessing all features of the uStepper S in a single object. More...
#include <uStepperS.h>
Public Member Functions | |
uStepperS () | |
Constructor of uStepper class. More... | |
uStepperS (float acceleration, float velocity) | |
Overloaded Constructor of uStepper class. More... | |
void | init (void) |
Internal function to prepare the uStepperS in the constructor. More... | |
void | setup (uint8_t mode=NORMAL, uint16_t stepsPerRevolution=200, float pTerm=10.0, float iTerm=0.0, float dTerm=0.0, uint16_t dropinStepSize=16, bool setHome=true, uint8_t invert=0, uint8_t runCurrent=50, uint8_t holdCurrent=30) |
Initializes the different parts of the uStepper S object. More... | |
void | setRPM (float rpm) |
Set the velocity in rpm. More... | |
void | setMaxAcceleration (float acceleration) |
Set the maximum acceleration of the stepper motor. More... | |
void | setMaxDeceleration (float deceleration) |
Set the maximum deceleration of the stepper motor. More... | |
void | setMaxVelocity (float velocity) |
Set the maximum velocity of the stepper motor. More... | |
void | setCurrent (double current) |
Set motor output current. More... | |
void | setHoldCurrent (double current) |
Set motor hold current. More... | |
void | moveSteps (int32_t steps) |
Make the motor perform a predefined number of steps. More... | |
void | moveAngle (float angle) |
Makes the motor rotate a specific angle relative to the current position. More... | |
void | moveToAngle (float angle) |
Makes the motor rotate a specific angle relative to the current position. More... | |
void | runContinous (bool dir) |
Make the motor rotate continuously. More... | |
float | angleMoved (void) |
Get the angle moved from reference position in degrees. More... | |
bool | getMotorState (uint8_t statusType=POSITION_REACHED) |
Get the current motor driver state. More... | |
void | stop (bool mode=HARD) |
Stop the motor. More... | |
void | enableStallguard (int8_t threshold=4, bool stopOnStall=false) |
Enable TMC5130 StallGuard. More... | |
void | disableStallguard (void) |
Disables the builtin stallguard offered from TMC5130, and reenables StealthChop. More... | |
void | clearStall (void) |
Clear the stallguard, reenabling the motor to return to its previous operation. More... | |
bool | isStalled (void) |
This method returns a bool variable indicating wether the motor is stalled or not. Uses the default stallguard threshold, unless this has been changed by .enableStallguard() More... | |
bool | isStalled (int8_t threshold) |
This method returns a bool variable indicating wether the motor is stalled or not. The stallguard is sensitive to the speed of the motor, as the torque available is a function of the speed. Therefore, it is necessary to change the treshold according to the application. A higher treshold makes the stallguard less sensitive to external loads, meaning that, the higher the application speed, the higher the treshold has to be for the stall guard to perform well. More... | |
void | setBrakeMode (uint8_t mode, float brakeCurrent=25.0) |
More... | |
void | enablePid (void) |
This method reenables the PID after being disabled. More... | |
void | disablePid (void) |
This method disables the PID until calling enablePid. More... | |
void | enableClosedLoop (void) |
This method reenables the closed loop mode after being disabled. More... | |
void | disableClosedLoop (void) |
This method disables the closed loop mode until calling enableClosedLoop. More... | |
void | setControlThreshold (float threshold) |
This method sets the control threshold for the closed loop position control in microsteps - i.e. it is the allowed control error. 10 microsteps is suitable in most applications. More... | |
float | moveToEnd (bool dir, float rpm=40.0, int8_t threshold=4) |
Moves the motor to its physical limit, without limit switch. More... | |
float | getPidError (void) |
This method returns the current PID error. More... | |
void | setProportional (float P) |
This method is used to change the PID proportional parameter P. More... | |
void | setIntegral (float I) |
This method is used to change the PID integral parameter I. More... | |
void | setDifferential (float D) |
This method is used to change the PID differential parameter D. More... | |
void | invertDropinDir (bool invert) |
This method is used to invert the drop-in direction pin interpretation. More... | |
void | dropinCli () |
This method is used to tune Drop-in parameters. After tuning uStepper S, the parameters are saved in EEPROM. More... | |
void | parseCommand (String *cmd) |
This method is used for the dropinCli to take in user commands. More... | |
void | dropinPrintHelp () |
This method is used to print the dropinCli menu explainer: More... | |
void | checkOrientation (float distance=10) |
This method is used to check the orientation of the motor connector. More... | |
Public Attributes | |
uStepperDriver | driver |
uStepperEncoder | encoder |
Private Member Functions | |
uint8_t | SPI (uint8_t data) |
void | setSPIMode (uint8_t mode) |
void | chipSelect (uint8_t pin, bool state) |
void | filterSpeedPos (posFilter_t *filter, int32_t steps) |
float | pid (float error) |
bool | loadDropinSettings (void) |
void | saveDropinSettings (void) |
uint8_t | dropinSettingsCalcChecksum (dropinCliSettings_t *settings) |
Private Attributes | |
float | maxVelocity |
float | maxAcceleration |
float | maxDeceleration |
bool | invertPidDropinDirection |
float | rpmToVelocity |
float | angleToStep |
uint16_t | microSteps |
uint16_t | fullSteps |
uint16_t | dropinStepSize |
int32_t | stepCnt |
float | stepsPerSecondToRPM |
float | RPMToStepsPerSecond |
volatile posFilter_t | externalStepInputFilter |
float | currentPidSpeed |
volatile uint8_t | mode |
float | pTerm |
float | iTerm |
float | dTerm |
bool | brake |
volatile bool | pidDisabled |
volatile float | controlThreshold = 10 |
volatile bool | stall |
volatile int32_t | pidPositionStepsIssued = 0 |
volatile float | currentPidError |
int8_t | stallThreshold = 4 |
bool | stallStop = false |
bool | stallEnabled = false |
dropinCliSettings_t | dropinSettings |
Friends | |
class | uStepperDriver |
class | uStepperEncoder |
void | used |
void | interrupt0 (void) |
Used by dropin feature to take in step pulses. More... | |
void | TIMER1_COMPA_vect (void) __attribute__((signal |
Interrupt routine for critical tasks. More... | |
Prototype of class for accessing all features of the uStepper S in a single object.
This class enables the user of the library to access all features of the uStepper S board, by use of a single object.
Definition at line 272 of file uStepperS.h.
uStepperS::uStepperS | ( | ) |
Constructor of uStepper class.
Definition at line 34 of file uStepperS.cpp.
uStepperS::uStepperS | ( | float | acceleration, |
float | velocity | ||
) |
Overloaded Constructor of uStepper class.
Definition at line 46 of file uStepperS.cpp.
float uStepperS::angleMoved | ( | void | ) |
Get the angle moved from reference position in degrees.
Definition at line 481 of file uStepperS.cpp.
void uStepperS::checkOrientation | ( | float | distance = 10 | ) |
This method is used to check the orientation of the motor connector.
[in] | distance | - the amount of degrees the motor shaft should rotate during orientation determination. |
Definition at line 92 of file uStepperS.cpp.
|
private |
void uStepperS::clearStall | ( | void | ) |
Clear the stallguard, reenabling the motor to return to its previous operation.
Definition at line 319 of file uStepperS.cpp.
void uStepperS::disableClosedLoop | ( | void | ) |
This method disables the closed loop mode until calling enableClosedLoop.
Definition at line 640 of file uStepperS.cpp.
void uStepperS::disablePid | ( | void | ) |
This method disables the PID until calling enablePid.
Definition at line 628 of file uStepperS.cpp.
void uStepperS::disableStallguard | ( | void | ) |
Disables the builtin stallguard offered from TMC5130, and reenables StealthChop.
Definition at line 312 of file uStepperS.cpp.
void uStepperS::dropinCli | ( | ) |
This method is used to tune Drop-in parameters. After tuning uStepper S, the parameters are saved in EEPROM.
Usage:
Set Proportional constant: 'P=10.002;' Set Integral constant: 'I=10.002;' Set Differential constant: 'D=10.002;' Invert Direction: 'invert;' Get Current PID Error: 'error;' Get Run/Hold Current Settings: 'current;' Set Run Current (percent): 'runCurrent=50.0;' Set Hold Current (percent): 'holdCurrent=50.0;'
Definition at line 1172 of file uStepperS.cpp.
void uStepperS::dropinPrintHelp | ( | ) |
This method is used to print the dropinCli menu explainer:
Usage: Show this command list: 'help;' Get PID Parameters: 'parameters;' Set Proportional constant: 'P=10.002;' Set Integral constant: 'I=10.002;' Set Differential constant: 'D=10.002;' Invert Direction: 'invert;' Get Current PID Error: 'error;' Get Run/Hold Current Settings: 'current;' Set Run Current (percent): 'runCurrent=50.0;' Set Hold Current (percent): 'holdCurrent=50.0;'
Definition at line 1198 of file uStepperS.cpp.
|
private |
void uStepperS::enableClosedLoop | ( | void | ) |
This method reenables the closed loop mode after being disabled.
Definition at line 635 of file uStepperS.cpp.
void uStepperS::enablePid | ( | void | ) |
This method reenables the PID after being disabled.
Definition at line 621 of file uStepperS.cpp.
void uStepperS::enableStallguard | ( | int8_t | threshold = 4 , |
bool | stopOnStall = false |
||
) |
Enable TMC5130 StallGuard.
This function enables the builtin stallguard offered from TMC5130 stepper driver. The threshold should be tuned as to trigger stallguard before a step is lost.
threshold | - stall sensitivity. A value between -64 and +63 |
stopOnStall | - should the driver automatic stop the motor on a stall |
Definition at line 301 of file uStepperS.cpp.
|
private |
bool uStepperS::getMotorState | ( | uint8_t | statusType = POSITION_REACHED | ) |
Get the current motor driver state.
This function is used to check some internal status flags of the driver. The argument is used to specify the flag to check
param[in] statusType - status flag to check. Possible values: POSITION_REACHED - has last commanded position been reached? VELOCITY_REACHED - has last commanded velocity been reached? STANDSTILL - Are the motor currently stopped? STALLGUARD2 - Has the stallguard been trickered?
Definition at line 82 of file uStepperS.cpp.
float uStepperS::getPidError | ( | void | ) |
This method returns the current PID error.
Definition at line 676 of file uStepperS.cpp.
void uStepperS::init | ( | void | ) |
Internal function to prepare the uStepperS in the constructor.
Definition at line 57 of file uStepperS.cpp.
void uStepperS::invertDropinDir | ( | bool | invert | ) |
This method is used to invert the drop-in direction pin interpretation.
[in] | invert | - 0 = not inverted, 1 = inverted |
Definition at line 762 of file uStepperS.cpp.
bool uStepperS::isStalled | ( | int8_t | threshold | ) |
This method returns a bool variable indicating wether the motor is stalled or not. The stallguard is sensitive to the speed of the motor, as the torque available is a function of the speed. Therefore, it is necessary to change the treshold according to the application. A higher treshold makes the stallguard less sensitive to external loads, meaning that, the higher the application speed, the higher the treshold has to be for the stall guard to perform well.
[in] | threshold | - Threshold for stallguard. A value between -64 and +63 |
Definition at line 329 of file uStepperS.cpp.
bool uStepperS::isStalled | ( | void | ) |
This method returns a bool variable indicating wether the motor is stalled or not. Uses the default stallguard threshold, unless this has been changed by .enableStallguard()
Definition at line 324 of file uStepperS.cpp.
|
private |
Definition at line 1217 of file uStepperS.cpp.
void uStepperS::moveAngle | ( | float | angle | ) |
Makes the motor rotate a specific angle relative to the current position.
This function makes the motor a rotate by a specific angle relative to the current position, using the acceleration profile. The motor will accelerate at the rate set by setMaxAcceleration(), decelerate at the rate set by setMaxDeceleration() and eventually reach the speed set by setMaxVelocity() function. The direction of rotation is set by the sign of the commanded angle to move
[in] | angle | - Angle to move. an input value of 300 makes the motor go 300 degrees in CW direction, and an input value of -300 makes the motor move 300 degrees in CCW direction. |
Definition at line 266 of file uStepperS.cpp.
void uStepperS::moveSteps | ( | int32_t | steps | ) |
Make the motor perform a predefined number of steps.
This function makes the motor perform a predefined number of steps, using the acceleration profile. The motor will accelerate at the rate set by setMaxAcceleration(), decelerate at the rate set by setMaxDeceleration() and eventually reach the speed set by setMaxVelocity() function. The direction of rotation is set by the sign of the commanded steps to perform
[in] | steps | - Number of steps to be performed. an input value of 300 makes the motor go 300 steps in CW direction, and an input value of -300 makes the motor move 300 steps in CCW direction. |
Definition at line 251 of file uStepperS.cpp.
void uStepperS::moveToAngle | ( | float | angle | ) |
Makes the motor rotate a specific angle relative to the current position.
This function makes the motor a rotate by a specific angle relative to the current position, using the acceleration profile. The motor will accelerate at the rate set by setMaxAcceleration(), decelerate at the rate set by setMaxDeceleration() and eventually reach the speed set by setMaxVelocity() function. The direction of rotation is set by the sign of the commanded angle to move
[in] | angle | - Angle to move. an input value of 300 makes the motor go 300 degrees in CW direction, and an input value of -300 makes the motor move 300 degrees in CCW direction. |
Definition at line 283 of file uStepperS.cpp.
float uStepperS::moveToEnd | ( | bool | dir, |
float | rpm = 40.0 , |
||
int8_t | threshold = 4 |
||
) |
Moves the motor to its physical limit, without limit switch.
This function, makes the motor run continously, untill the encoder detects a stall, at which point the motor is assumed to be at it's limit.
[in] | dir | Direction to search for limit |
[in] | rpm | RPM of the motor while searching for limit |
[in] | threshold | Sensitivity of stall detection (-64 to +63), low is more sensitive |
Definition at line 645 of file uStepperS.cpp.
void uStepperS::parseCommand | ( | String * | cmd | ) |
This method is used for the dropinCli to take in user commands.
[in] | cmd | - input from terminal for dropinCli |
Definition at line 767 of file uStepperS.cpp.
|
private |
Definition at line 681 of file uStepperS.cpp.
void uStepperS::runContinous | ( | bool | dir | ) |
Make the motor rotate continuously.
This function makes the motor rotate continuously, using the acceleration profile.
[in] | dir | - Can be set to "CCW" or "CW" (without the quotes) |
Definition at line 468 of file uStepperS.cpp.
|
private |
Definition at line 1238 of file uStepperS.cpp.
void uStepperS::setBrakeMode | ( | uint8_t | mode, |
float | brakeCurrent = 25.0 |
||
) |
[in] | mode | - this parameter specifies how the motor should brake during standstill. available modes: FREEWHEELBRAKE - This will result in no holding torque at standstill COOLBRAKE 1 - This will make the motor brake by shorting the two bottom FET's of the H-Bridge. This will provide less holding torque, but will significantly reduce driver heat HARDBRAKE 2 - This will make the motor brake by sending the full specified current through the coils. This will provide high holding torque, but will make the driver (and motor) dissipate power |
[in] | brakeCurrent | (optional) - if HARDBRAKE is use as mode, this argument can set the current to use for braking (0-100% of 2A). If argument is not specified, the motor will brake with 25% of max current |
Definition at line 343 of file uStepperS.cpp.
void uStepperS::setControlThreshold | ( | float | threshold | ) |
This method sets the control threshold for the closed loop position control in microsteps - i.e. it is the allowed control error. 10 microsteps is suitable in most applications.
Definition at line 617 of file uStepperS.cpp.
void uStepperS::setCurrent | ( | double | current | ) |
Set motor output current.
This function allows the user to change the current setting of the motor driver.
[in] | current | - Desired current in percent (0% - 100%) |
Definition at line 441 of file uStepperS.cpp.
void uStepperS::setDifferential | ( | float | D | ) |
This method is used to change the PID differential parameter D.
[in] | D | - PID differential part D |
Definition at line 757 of file uStepperS.cpp.
void uStepperS::setHoldCurrent | ( | double | current | ) |
Set motor hold current.
This function allows the user to change the current setting of the motor driver.
[in] | current | - Desired hold current in percent (0% - 100%) |
Definition at line 454 of file uStepperS.cpp.
void uStepperS::setIntegral | ( | float | I | ) |
This method is used to change the PID integral parameter I.
[in] | I | - PID integral part I |
Definition at line 752 of file uStepperS.cpp.
void uStepperS::setMaxAcceleration | ( | float | acceleration | ) |
Set the maximum acceleration of the stepper motor.
This function lets the user set the max acceleration used by the stepper driver.
[in] | acceleration | - Maximum acceleration in steps/s^2 |
Definition at line 418 of file uStepperS.cpp.
void uStepperS::setMaxDeceleration | ( | float | deceleration | ) |
Set the maximum deceleration of the stepper motor.
This function lets the user set the max deceleration used by the stepper driver.
[in] | deceleration | - Maximum deceleration in steps/s^2 |
Definition at line 430 of file uStepperS.cpp.
void uStepperS::setMaxVelocity | ( | float | velocity | ) |
Set the maximum velocity of the stepper motor.
This function lets the user set the max velocity used by the stepper driver.
[in] | velocity | - Maximum velocity in steps/s |
Definition at line 407 of file uStepperS.cpp.
void uStepperS::setProportional | ( | float | P | ) |
This method is used to change the PID proportional parameter P.
[in] | P | - PID proportional part P |
Definition at line 747 of file uStepperS.cpp.
void uStepperS::setRPM | ( | float | rpm | ) |
Set the velocity in rpm.
This function lets the user set the velocity of the motor in rpm. A negative value switches direction of the motor.
[in] | rpm | - The velocity in rotations per minute |
Definition at line 364 of file uStepperS.cpp.
|
private |
void uStepperS::setup | ( | uint8_t | mode = NORMAL , |
uint16_t | stepsPerRevolution = 200 , |
||
float | pTerm = 10.0 , |
||
float | iTerm = 0.0 , |
||
float | dTerm = 0.0 , |
||
uint16_t | dropinStepSize = 16 , |
||
bool | setHome = true , |
||
uint8_t | invert = 0 , |
||
uint8_t | runCurrent = 50 , |
||
uint8_t | holdCurrent = 30 |
||
) |
Initializes the different parts of the uStepper S object.
This function initializes the different parts of the uStepper S object, and should be called in the setup() function of the arduino sketch. This function is needed as some things, like the timer can not be setup in the constructor, since arduino for some strange reason, resets a lot of the AVR registers just before entering the setup() function.
[in] | mode | Default is normal mode. Pass the constant "DROPIN" to configure the uStepper to act as dropin compatible to the stepstick. Pass the constant "PID", to enable closed loop feature for regular movement functions, such as moveSteps() |
[in] | stepsPerRevolution | Number of fullsteps per revolution |
[in] | pTerm | The proportional coefficent of the DROPIN PID controller |
[in] | iTerm | The integral coefficent of the DROPIN PID controller |
[in] | dTerm | The differential coefficent of the DROPIN PID controller |
[in] | dropinStepSize | number of steps per fullstep, send from external dropin controller |
[in] | setHome | When set to true, the encoder position is Reset. When set to false, the encoder position is not reset. |
[in] | invert | Inverts the motor direction for dropin feature. 0 = NOT invert, 1 = invert. this has no effect for other modes than dropin |
[in] | runCurrent | Sets the current (in percent) to use while motor is running. |
[in] | holdCurrent | Sets the current (in percent) to use while motor is NOT running |
Definition at line 154 of file uStepperS.cpp.
|
private |
void uStepperS::stop | ( | bool | mode = HARD | ) |
Stop the motor.
This function stops any ongoing motor movement. The "mode" argument determines whether the motor should stop with or without a deceleration phase
mode | - can be set to "HARD" for no deceleration phase or "SOFT" for deceleration phase. |
Definition at line 486 of file uStepperS.cpp.
|
friend |
Used by dropin feature to take in step pulses.
This interrupt routine is used by the dropin feature to keep track of step and direction pulses from main controller
Definition at line 539 of file uStepperS.cpp.
|
friend |
Interrupt routine for critical tasks.
This interrupt routine is in charge of sampling the encoder, process the data and handle PID
Definition at line 574 of file uStepperS.cpp.
|
friend |
Definition at line 278 of file uStepperS.h.
|
friend |
Definition at line 275 of file uStepperS.h.
|
friend |
Definition at line 276 of file uStepperS.h.
|
private |
Definition at line 713 of file uStepperS.h.
|
private |
Definition at line 735 of file uStepperS.h.
|
private |
This variable sets the threshold for activating/deactivating closed loop position control - i.e. it is the allowed error in steps for the control
Definition at line 738 of file uStepperS.h.
|
private |
Definition at line 745 of file uStepperS.h.
|
private |
Definition at line 726 of file uStepperS.h.
uStepperDriver uStepperS::driver |
Instantiate object for the driver
Definition at line 282 of file uStepperS.h.
|
private |
Definition at line 766 of file uStepperS.h.
|
private |
Definition at line 717 of file uStepperS.h.
|
private |
Definition at line 734 of file uStepperS.h.
uStepperEncoder uStepperS::encoder |
Instantiate object for the Encoder
Definition at line 285 of file uStepperS.h.
|
private |
Definition at line 724 of file uStepperS.h.
|
private |
Definition at line 716 of file uStepperS.h.
|
private |
Definition at line 711 of file uStepperS.h.
|
private |
This variable contains the integral coefficient used by the PID
Definition at line 732 of file uStepperS.h.
|
private |
This variable contains the maximum acceleration in steps/s to be used. The can be set and read by the user of the library using the functions setMaxAcceleration()
Definition at line 709 of file uStepperS.h.
|
private |
Definition at line 710 of file uStepperS.h.
|
private |
This variable contains the maximum velocity in steps/s, the motor is allowed to reach at any given point. The user of the library can set this by use of the setMaxVelocity()
Definition at line 703 of file uStepperS.h.
|
private |
Definition at line 715 of file uStepperS.h.
|
private |
This variable is used to indicate which mode the uStepper is running in (Normal, dropin or pid)
Definition at line 729 of file uStepperS.h.
|
private |
Definition at line 736 of file uStepperS.h.
|
private |
Definition at line 744 of file uStepperS.h.
|
private |
Definition at line 730 of file uStepperS.h.
|
private |
Definition at line 722 of file uStepperS.h.
|
private |
Definition at line 712 of file uStepperS.h.
|
private |
This variable holds information on wether the motor is stalled or not. 0 = OK, 1 = stalled
Definition at line 741 of file uStepperS.h.
|
private |
Flag to keep track of stallguard
Definition at line 754 of file uStepperS.h.
|
private |
This variable hold the default state for Stallguard (stopOnStall)
Definition at line 751 of file uStepperS.h.
|
private |
This variable holds the default stall threshold, but can be updated by the user.
Definition at line 748 of file uStepperS.h.
|
private |
Definition at line 719 of file uStepperS.h.
|
private |
Definition at line 721 of file uStepperS.h.