uStepper
|
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 (uint8_t mode=NORMAL, uint8_t microStepping=SIXTEEN, float faultTolerance=10.0, float faultHysteresis=5.0, float pTerm=1.0, float iTerm=0.02, float dterm=0.006) |
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... | |
void | pwmD8 (float duty) |
Generate PWM signal on digital output 8. More... | |
void | pwmD3 (float duty) |
Generate PWM signal on digital output 3. More... | |
void | updateSetPoint (float setPoint) |
Updates setpoint for the motor. 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... | |
void | pidDropIn (void) |
This method handles the actual PID controller calculations for drop-in feature, if enabled. | |
void | pid (void) |
This method handles the actual PID controller calculations, if enabled. | |
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 float | tolerance |
volatile float | hysteresis |
volatile float | stepConversion |
volatile uint16_t | counter |
volatile int32_t | stepCnt |
volatile int32_t | control |
volatile uint32_t | speedValue [2] |
float | pTerm |
float | iTerm |
float | dTerm |
uint8_t | mode |
float | angleToStep |
Friends | |
void | naked |
void | used |
void | TIMER2_COMPA_vect (void) __attribute__((signal |
Used to apply step pulses to the motor. More... | |
void | TIMER1_COMPA_vect (void) __attribute__((signal |
Measures angle and speed of motor. More... | |
void | interrupt1 (void) |
Used by dropin feature to take in enable signal. More... | |
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 495 of file uStepper.h.
uStepper::uStepper | ( | float | accel, |
float | vel | ||
) |
Constructor of uStepper class.
< Instantiate object for the encoder 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 926 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 910 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 1386 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 1381 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 1391 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 961 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 999 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 1396 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 1406 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 1242 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 1089 of file uStepper.cpp.
void uStepper::pwmD3 | ( | float | duty | ) |
Generate PWM signal on digital output 3.
This function allows the user to generate PWM signal on digital output 3. The PWM signal has a fixed frequency of 28.2kHz, from 0% - 100% duty cycle, in steps of 1.43% (resolution of 6.13 bits).
duty | - Desired duty cycle of PWM signal. range: 0.0 to 100.0. |
Definition at line 1437 of file uStepper.cpp.
void uStepper::pwmD8 | ( | float | duty | ) |
Generate PWM signal on digital output 8.
This function allows the user to generate PWM signal on digital output 8. The PWM signal has a fixed frequency of 1kHz, from 0% - 100% duty cycle, in steps of 0.00625% (resolution of 13.97 bits).
duty | - Desired duty cycle of PWM signal. range: 0.0 to 100.0. |
Definition at line 1418 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 1004 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.
accel | - Maximum acceleration in steps/s^2 |
Definition at line 941 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.
vel | - Maximum rotational velocity of the motor in steps/s |
Definition at line 966 of file uStepper.cpp.
void uStepper::setup | ( | uint8_t | mode = NORMAL , |
uint8_t | microStepping = SIXTEEN , |
||
float | faultTolerance = 10.0 , |
||
float | faultHysteresis = 5.0 , |
||
float | pTerm = 1.0 , |
||
float | iTerm = 0.02 , |
||
float | dterm = 0.006 |
||
) |
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.
[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 PID feature for regular movement functions, such as moveSteps() |
[in] | microStepping | When mode is set to anythings else than "NORMAL", this parameter should be set to the current microstep setting. available arguments are: FULL HALF QUARTER EIGHT SIXTEEN |
[in] | faultTolerance | This parameter defines the allowed number of missed steps before the correction should kick in. |
[in] | faultHysteresis | The number of missed steps allowed for the PID to turn off |
[in] | pTerm | The proportional coefficent of the PID controller |
[in] | iTerm | The integral coefficent of the PID controller |
[in] | dterm | The differential coefficent of the PID controller |
Definition at line 1321 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 1273 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 1367 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 1376 of file uStepper.cpp.
void uStepper::updateSetPoint | ( | float | setPoint | ) |
Updates setpoint for the motor.
This method updates the setpoint for the motor. This function is used when it is desired to provide an absolute position for the motor, and should be used in the DROPIN mode
[in] | setPoint | The setpoint in degrees |
Definition at line 1456 of file uStepper.cpp.
|
friend |
Used by dropin feature to take in enable signal.
This interrupt routine is used by the dropin feature to keep track of enable signal from main controller
Definition at line 81 of file uStepper.cpp.
|
friend |
Measures angle and speed of motor.
This interrupt routine is in charge of sampling the encoder and measure the current speed of the motor. In case of Dropin or PID feature this routine runs at a frequency of 500Hz while during normal operation it runs at a frequency of 1kHz.
Definition at line 395 of file uStepper.cpp.
|
friend |
Used to apply step pulses to the motor.
< This variable converts an angle in degrees into a corresponding number of steps
This interrupt routine is in charge of applying step pulses to the motor. The routine runs at a frequency of 28.2kHz, and handles acceleration algorithm calculations, as well as applying step pulses during compensation for missed steps, while either dropin or PID feature are enabled.
Definition at line 127 of file uStepper.cpp.
|
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 566 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 511 of file uStepper.h.
|
private |
< This variable is used to indicate which mode the uStepper is running in (Normal, dropin or pid)
Definition at line 606 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 529 of file uStepper.h.
|
private |
< This variable contains the number of steps commanded by external controller, in case of dropin feature
Definition at line 588 of file uStepper.h.
|
private |
< This variable contains the conversion coefficient from raw encoder data to number of steps
Definition at line 582 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 520 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 523 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 514 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 551 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 538 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 559 of file uStepper.h.
|
private |
< This variable contains the integral coefficient used by the PID
Definition at line 599 of file uStepper.h.
uStepperEncoder uStepper::encoder |
< Instantiate object for the temperature sensor
Definition at line 671 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 547 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 533 of file uStepper.h.
|
private |
< This variable contains the number of missed steps allowed before the PID controller kicks in, if activated
Definition at line 576 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 517 of file uStepper.h.
|
private |
< This variable contains the proportional coefficient used by the PID
Definition at line 597 of file uStepper.h.
|
private |
< This variable contains the differential coefficient used by the PID
Definition at line 602 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 503 of file uStepper.h.
|
private |
< This variable contains the number of microseconds between last step pulse from external controller
Definition at line 594 of file uStepper.h.
|
private |
< This variable contains the number of steps we are off the setpoint, and is updated once every PID sample.
Definition at line 591 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 507 of file uStepper.h.
|
private |
< This variable is used by Timer2 to check wether it is time to generate steps or not. only used if PID is activated
Definition at line 585 of file uStepper.h.
|
private |
< This variable contains the error which the PID controller should have obtained in order to switch off
Definition at line 579 of file uStepper.h.
|
private |
< This variable tells the algorithm the direction of rotation for the commanded move.
Definition at line 541 of file uStepper.h.
|
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 either +/- this value (acceleration/deceleration)or zero (cruise).
Definition at line 573 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 526 of file uStepper.h.
|
private |
< Not used anymore !
Definition at line 561 of file uStepper.h.