Prototype of class for accessing all features of the uStepper in a single object. More...
#include <uStepper.h>
Public Member Functions | |
uStepper (float accel, float vel) | |
Constructor of uStepper class. More... | |
uStepper (void) | |
Constructor of uStepper class. More... | |
void | setMaxAcceleration (float accel) |
Set the maximum acceleration of the stepper motor. More... | |
float | getMaxAcceleration (void) |
Get the value of the maximum motor acceleration. More... | |
void | setMaxVelocity (float vel) |
Sets the maximum rotational velocity of the motor. More... | |
float | getMaxVelocity (void) |
Returns the maximum rotational velocity of the motor. More... | |
void | runContinous (bool dir) |
Make the motor rotate continuously. More... | |
void | moveSteps (uint32_t steps, bool dir, bool holdMode) |
Make the motor perform a predefined number of steps. More... | |
void | hardStop (bool holdMode) |
Stop the motor without deceleration. More... | |
void | softStop (bool holdMode) |
Stop the motor with deceleration. More... | |
void | setup (bool mode=NORMAL, uint8_t microStepping=SIXTEEN, float faultSpeed=3000.0, uint32_t faultTolerance=20) |
Initializes the different parts of the uStepper object. More... | |
bool | getCurrentDirection (void) |
Returns the direction the motor is currently configured to rotate. More... | |
bool | getMotorState (void) |
Get the current state of the motor. More... | |
int64_t | getStepsSinceReset (void) |
Get the number of steps applied since reset. More... | |
Public Attributes | |
uStepperTemp | temp |
uStepperEncoder | encoder |
Private Member Functions | |
void | startTimer (void) |
Starts timer for stepper algorithm. More... | |
void | stopTimer (void) |
Stops the timer for the stepper algorithm. More... | |
void | enableMotor (void) |
Enables the stepper driver output stage. More... | |
void | disableMotor (void) |
Disables the stepper driver output stage. More... | |
Private Attributes | |
uint16_t | cruiseDelay |
float2 | multiplier |
uint8_t | state |
uint32_t | accelSteps |
uint32_t | decelSteps |
uint32_t | initialDecelSteps |
uint32_t | cruiseSteps |
uint32_t | currentStep |
uint32_t | totalSteps |
bool | continous |
bool | hold |
bool | direction |
int64_t | stepsSinceReset |
float2 | exactDelay |
uint16_t | delay |
bool | dropIn |
float | velocity |
float | acceleration |
volatile uint16_t | faultStepDelay |
volatile float | tolerance |
volatile float | stepResolution |
Friends | |
void | naked |
void | TIMER2_COMPA_vect (void) __attribute__((signal |
void | TIMER1_COMPA_vect (void) __attribute__((signal)) |
Prototype of class for accessing all features of the uStepper in a single object.
This class enables the user of the library to access all features of the uStepper board, by use of a single object.
Definition at line 436 of file uStepper.h.
uStepper::uStepper | ( | float | accel, |
float | vel | ||
) |
Constructor of uStepper class.
This is the constructor of the uStepper class. This version of the constructor takes in two arguments, "accel" and "vel". These two arguments lets the programmer set the maximum acceleration and velocity, respectively, during instantiation of the uStepper object.
accel | - Floating point representation of the maximum acceleration allowed in steps/s^2. |
vel | - Floating point representation of the maximum velocity allowed in steps/s. |
Definition at line 796 of file uStepper.cpp.
uStepper::uStepper | ( | void | ) |
Constructor of uStepper class.
This is the constructor of the uStepper class. This version of the constructor doesn't take any arguments, and instantiates an object with a maximum acceleration and velocity of 1000 steps/s^2 and 1000 steps/s, respectively.
Definition at line 781 of file uStepper.cpp.
|
private |
Disables the stepper driver output stage.
This function disables the stepper driver output stage. If this function is used, the motor will not brake, and it will be possible to turn the motor shaft by hand
Definition at line 1262 of file uStepper.cpp.
|
private |
Enables the stepper driver output stage.
This function enables the output stage of the stepper driver. If no step pulses is applied to the stepper driver, either manually or by means of the stepper algorithm of this library, this will make the force the motor to brake in the current position.
Definition at line 1257 of file uStepper.cpp.
bool uStepper::getCurrentDirection | ( | void | ) |
Returns the direction the motor is currently configured to rotate.
This function checks the last configured direction of rotation and returns this.
Definition at line 1267 of file uStepper.cpp.
float uStepper::getMaxAcceleration | ( | void | ) |
Get the value of the maximum motor acceleration.
This function returns the maximum acceleration used by the stepper algorithm.
Definition at line 830 of file uStepper.cpp.
float uStepper::getMaxVelocity | ( | void | ) |
Returns the maximum rotational velocity of the motor.
This function returns the maximum rotational velocity the motor is allowed to run. In order to change this velocity, The function setMaximumVelocity() should be used.
Definition at line 893 of file uStepper.cpp.
bool uStepper::getMotorState | ( | void | ) |
Get the current state of the motor.
This function returns the current state of the motor, i.e. if the motor is rotating or not.
Definition at line 1272 of file uStepper.cpp.
int64_t uStepper::getStepsSinceReset | ( | void | ) |
Get the number of steps applied since reset.
This function returns the number of steps applied to the motor driver since reset. This function doesn't care if the step has actually been performed or not. Steps applied in the clockwise direction is added and steps applied in the counter clockwise direction is subtracted. This means that a negative return value indicates that the motor should have rotated the returned amount of steps in the counter clockwise direction, with respect to the initial position. Likewise a positive value indicate the number of steps the motor should have rotated in the clockwise direction, with respect to the initial position.
Definition at line 1282 of file uStepper.cpp.
void uStepper::hardStop | ( | bool | holdMode | ) |
Stop the motor without deceleration.
This function will stop any ongoing motor movement, without any deceleration phase. If the motor is rotation at a significant speed, the motor might not stop instantaneously, due to build up inertia. The argument "holdMode" can be used to define whether the motor should brake or freewheel after the function has been called.
holdMode | - can be set to "HARD" for brake mode or "SOFT" for freewheel mode (without the quotes). |
Definition at line 1138 of file uStepper.cpp.
void uStepper::moveSteps | ( | uint32_t | steps, |
bool | dir, | ||
bool | holdMode | ||
) |
Make the motor perform a predefined number of steps.
This function makes the motor perform a predefined number of steps, using the acceleration profile implemented in this library. The motor will accelerate at the rate set by setMaximumAcceleration(), and eventually reach the speed set by setMaximumVelocity() function. The direction of rotation is set by the argument "dir". The argument "holdMode", defines whether the motor should brake or let the motor freewheel after the steps has been performed.
steps | - Number of steps to be performed. |
dir | - Can be set to "CCW" or "CW" (without the quotes). |
holdMode | - can be set to "HARD" for brake mode or "SOFT" for freewheel mode (without the quotes). |
Definition at line 985 of file uStepper.cpp.
void uStepper::runContinous | ( | bool | dir | ) |
Make the motor rotate continuously.
This function makes the motor rotate continuously, using the acceleration profile implemented in this library. The motor will accelerate at the rate set by setMaximumAcceleration(), and eventually reach the speed set by setMaximumVelocity() function. The direction of rotation is set by the argument "dir".
dir | - Can be set to "CCW" or "CW" (without the quotes) |
Definition at line 898 of file uStepper.cpp.
void uStepper::setMaxAcceleration | ( | float | accel | ) |
Set the maximum acceleration of the stepper motor.
This function lets the user of this library set the acceleration used by the stepper algorithm. The algorithm is a second order acceleration profile, meaning that the acceleration only assumes three values; -a, 0 and a, with a being the acceleration set by this function.
Maximum | acceleration in steps/s^2 |
Definition at line 810 of file uStepper.cpp.
void uStepper::setMaxVelocity | ( | float | vel | ) |
Sets the maximum rotational velocity of the motor.
This function sets the maximum velocity at which the motor is allowed to run. The rotational velocity of the motor will gradually be ramped up to the value set by this function, by the stepper acceleration profile implemented in this library.
Maximum | rotational velocity of the motor in steps/s |
Definition at line 860 of file uStepper.cpp.
void uStepper::setup | ( | bool | mode = NORMAL , |
uint8_t | microStepping = SIXTEEN , |
||
float | faultSpeed = 3000.0 , |
||
uint32_t | faultTolerance = 20 |
||
) |
Initializes the different parts of the uStepper object.
This function initializes the different parts of the uStepper 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.
Definition at line 1217 of file uStepper.cpp.
void uStepper::softStop | ( | bool | holdMode | ) |
Stop the motor with deceleration.
This function stops any ongoing motor movement, with a deceleration phase. This will take longer for the motor to stop, however the mechanical vibrations related to the stopping of the motor can be significantly reduced compared to the hardStop() function. The argument "holdMode" can be used to define whether the motor should brake or freewheel after the function has been called.
holdMode | - can be set to "HARD" for brake mode or "SOFT" for freewheel mode (without the quotes). |
Definition at line 1169 of file uStepper.cpp.
|
private |
Starts timer for stepper algorithm.
This function actually doesn't start the timer for the stepper algorithm, as the timer is always running. Instead it clears the counter value, clears any pending interrupts and enables the timer compare match interrupt.
Definition at line 1243 of file uStepper.cpp.
|
private |
Stops the timer for the stepper algorithm.
As the startTimer() function, this function doesn't stop the timer, instead it disables the timer compare match interrupt bit in the timer registers, ensuring that the stepper algorithm will not run when the motor is not supposed to run.
Definition at line 1252 of file uStepper.cpp.
|
private |
This variable contains the maximum acceleration to be used. The can be set and read by the user of the library using the functions setMaxAcceleration() and getMaxAcceleration() respectively. Since this library uses a second order acceleration curve, the acceleration applied will always be eith +/- this value (acceleration/deceleration)or zero (cruise).
Definition at line 474 of file uStepper.h.
|
private |
This variable keeps track of how many steps to perform in the acceleration phase of the profile.
Definition at line 446 of file uStepper.h.
|
private |
This variable tells the algorithm whether the motor should rotated continuous or only a limited number of steps. If set to 1, the motor will rotate continous.
Definition at line 458 of file uStepper.h.
|
private |
This variable is used by the stepper acceleration algorithm to set the delay between step pulses when running at the set cruise speed
Definition at line 440 of file uStepper.h.
|
private |
This variable keeps track of how many steps to perform in the cruise phase of the profile.
Definition at line 452 of file uStepper.h.
|
private |
This variable keeps track of the current step number in the current move of a predefined number of steps.
Definition at line 454 of file uStepper.h.
|
private |
This variable keeps track of how many steps to perform in the deceleration phase of the profile.
Definition at line 448 of file uStepper.h.
|
private |
This variable is used by the stepper algorithm to keep track of when to apply the next step pulse. When the algorithm have applied a step pulse, it will calculate the next delay (in number of interrupts) needed before the next pulse should be applied. A truncated version of this delay will be put in this variable and is decremented by one for each interrupt untill it reaches zero and a step is applied.
Definition at line 468 of file uStepper.h.
|
private |
This variable tells the algorithm the direction of rotation for the commanded move.
Definition at line 462 of file uStepper.h.
uStepperEncoder uStepper::encoder |
Instantiate object for the encoder
Definition at line 524 of file uStepper.h.
|
private |
This variable contains the exact delay (in number of interrupts) before the next step is applied. This variable is used in the calculations of the next step delay.
Definition at line 466 of file uStepper.h.
|
private |
This variable tells the algorithm if it should block the motor by keeping the motor coils excited after the commanded number of steps have been carried out, or if it should release the motor coil, allowing the shaft to be rotated freely.
Definition at line 460 of file uStepper.h.
|
private |
This variable keeps track of how many steps to perform in the initial deceleration phase of the profile.
Definition at line 450 of file uStepper.h.
|
private |
This is the constant multiplier used by the stepper algorithm. See description of timer2 overflow interrupt routine for more details.
Definition at line 442 of file uStepper.h.
|
private |
This variable is used by the stepper algorithm to keep track of which part of the acceleration profile the motor is currently operating at.
Definition at line 444 of file uStepper.h.
|
private |
This variable contains an open-loop number of steps moved from the position the motor had when powered on (or reset). a negative value represents a rotation in the counter clock wise direction and a positive value corresponds to a rotation in the clock wise direction.
Definition at line 464 of file uStepper.h.
uStepperTemp uStepper::temp |
Instantiate object for the temperature sensor
Definition at line 523 of file uStepper.h.
|
private |
This variable keeps track of the total number of steps to be performed in the current move of a predefined number of steps.
Definition at line 456 of file uStepper.h.
|
private |
This variable contains the maximum velocity, the motor is allowed to reach at any given point. The user of the library can set this by use of the setMaxVelocity() function, and get the current value with the getMaxVelocity() function.
Definition at line 472 of file uStepper.h.