uStepper S
Public Member Functions | Public Attributes | Private Member Functions | Private Attributes | Friends | List of all members
uStepperS Class Reference

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.
 
 uStepperS (float acceleration, float velocity)
 Overloaded Constructor of uStepper class.
 
void init (void)
 Internal function to prepare the uStepperS in the constructor.
 
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)
 Moves the motor rotate a specific angle relative to the current position. More...
 
void moveToAngle (float angle)
 Moves 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...
 
bool isStalled (float stallSensitivity=0.992)
 This method returns a bool variable indicating wether the motor is stalled or not. More...
 
void brakeMotor (bool brake)
 
void enablePid (void)
 This method enables the PID after being disabled (disablePid). More...
 
void disablePid (void)
 This method disables the PID until calling enablePid. More...
 
float moveToEnd (bool dir, float stallSensitivity=0.992)
 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...
 

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 detectStall (int32_t stepsMoved)
 
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
 
uint8_t mode
 
float pTerm
 
float iTerm
 
float dTerm
 
bool brake
 
volatile bool pidDisabled
 
volatile bool stall
 
volatile int32_t pidPositionStepsIssued = 0
 
volatile float currentPidError
 
float stallSensitivity = 0.992
 
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...
 

Detailed Description

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 252 of file uStepperS.h.

Member Function Documentation

◆ angleMoved()

float uStepperS::angleMoved ( void  )

Get the angle moved from reference position in degrees.

Returns
The angle moved in degrees.

Definition at line 432 of file uStepperS.cpp.

◆ disablePid()

void uStepperS::disablePid ( void  )

This method disables the PID until calling enablePid.

Definition at line 589 of file uStepperS.cpp.

◆ dropinCli()

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 1114 of file uStepperS.cpp.

◆ dropinPrintHelp()

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 1140 of file uStepperS.cpp.

◆ enablePid()

void uStepperS::enablePid ( void  )

This method enables the PID after being disabled (disablePid).

Definition at line 582 of file uStepperS.cpp.

◆ getMotorState()

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?

Returns
The angle moved.

Definition at line 82 of file uStepperS.cpp.

◆ getPidError()

float uStepperS::getPidError ( void  )

This method returns the current PID error.

Returns
PID error (float)

Definition at line 618 of file uStepperS.cpp.

◆ invertDropinDir()

void uStepperS::invertDropinDir ( bool  invert)

This method is used to invert the drop-in direction pin interpretation.

Parameters
[in]invert- 0 = not inverted, 1 = inverted

Definition at line 704 of file uStepperS.cpp.

◆ isStalled()

bool uStepperS::isStalled ( float  stallSensitivity = 0.992)

This method returns a bool variable indicating wether the motor is stalled or not.

Parameters
[in]stallSensitivity- Sensitivity of stall detection (0.0 - 1.0), low is more sensitive
Returns
0 = not stalled, 1 = stalled

Definition at line 293 of file uStepperS.cpp.

◆ moveAngle()

void uStepperS::moveAngle ( float  angle)

Moves 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
Parameters
[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 221 of file uStepperS.cpp.

◆ moveSteps()

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
Parameters
[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 206 of file uStepperS.cpp.

◆ moveToAngle()

void uStepperS::moveToAngle ( float  angle)

Moves 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
Parameters
[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 238 of file uStepperS.cpp.

◆ moveToEnd()

float uStepperS::moveToEnd ( bool  dir,
float  stallSensitivity = 0.992 
)

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.
Parameters
[in]dirDirection to search for limit
[in]stallSensitivitySensitivity of stall detection (0.0 - 1.0), low is more sensitive
Returns
Degrees turned from calling the function, till end was reached

Definition at line 596 of file uStepperS.cpp.

◆ parseCommand()

void uStepperS::parseCommand ( String *  cmd)

This method is used for the dropinCli to take in user commands.

Parameters
[in]cmd- input from terminal for dropinCli

Definition at line 709 of file uStepperS.cpp.

◆ runContinous()

void uStepperS::runContinous ( bool  dir)

Make the motor rotate continuously.

        This function makes the motor rotate continuously, using the
        acceleration profile.
Parameters
[in]dir- Can be set to "CCW" or "CW" (without the quotes)

Definition at line 419 of file uStepperS.cpp.

◆ setCurrent()

void uStepperS::setCurrent ( double  current)

Set motor output current.

        This function allows the user to change the current setting of the motor driver.
Parameters
[in]current- Desired current in percent (0% - 100%)

Definition at line 392 of file uStepperS.cpp.

◆ setDifferential()

void uStepperS::setDifferential ( float  D)

This method is used to change the PID differential parameter D.

Parameters
[in]D- PID differential part D

Definition at line 699 of file uStepperS.cpp.

◆ setHoldCurrent()

void uStepperS::setHoldCurrent ( double  current)

Set motor hold current.

        This function allows the user to change the current setting of the motor driver.
Parameters
[in]current- Desired hold current in percent (0% - 100%)

Definition at line 405 of file uStepperS.cpp.

◆ setIntegral()

void uStepperS::setIntegral ( float  I)

This method is used to change the PID integral parameter I.

Parameters
[in]I- PID integral part I

Definition at line 694 of file uStepperS.cpp.

◆ setMaxAcceleration()

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.
Parameters
[in]acceleration- Maximum acceleration in steps/s^2

Definition at line 369 of file uStepperS.cpp.

◆ setMaxDeceleration()

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.
Parameters
[in]deceleration- Maximum deceleration in steps/s^2

Definition at line 381 of file uStepperS.cpp.

◆ setMaxVelocity()

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.
Parameters
[in]velocity- Maximum velocity in steps/s

Definition at line 358 of file uStepperS.cpp.

◆ setProportional()

void uStepperS::setProportional ( float  P)

This method is used to change the PID proportional parameter P.

Parameters
[in]P- PID proportional part P

Definition at line 689 of file uStepperS.cpp.

◆ setRPM()

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.
Parameters
[in]rpm- The velocity in rotations per minute

Definition at line 315 of file uStepperS.cpp.

◆ setup()

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.
Parameters
[in]modeDefault 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]stepsPerRevolutionNumber of fullsteps per revolution
[in]pTermThe proportional coefficent of the DROPIN PID controller
[in]iTermThe integral coefficent of the DROPIN PID controller
[in]dTermThe differential coefficent of the DROPIN PID controller
[in]dropinStepSizenumber of steps per fullstep, send from external dropin controller
[in]setHomeWhen set to true, the encoder position is Reset. When set to false, the encoder position is not reset.
[in]invertInverts the motor direction for dropin feature. 0 = NOT invert, 1 = invert. this has no effect for other modes than dropin
[in]runCurrentSets the current (in percent) to use while motor is running.
[in]holdCurrentSets the current (in percent) to use while motor is NOT running

Definition at line 92 of file uStepperS.cpp.

◆ stop()

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
Parameters
mode- can be set to "HARD" for no deceleration phase or "SOFT" for deceleration phase.

Definition at line 437 of file uStepperS.cpp.

Friends And Related Function Documentation

◆ interrupt0

void interrupt0 ( void  )
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 483 of file uStepperS.cpp.

◆ TIMER1_COMPA_vect

void TIMER1_COMPA_vect ( void  )
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 518 of file uStepperS.cpp.

Member Data Documentation

◆ driver

uStepperDriver uStepperS::driver

Instantiate object for the driver

Definition at line 262 of file uStepperS.h.

◆ encoder

uStepperEncoder uStepperS::encoder

Instantiate object for the Encoder

Definition at line 265 of file uStepperS.h.

◆ iTerm

float uStepperS::iTerm
private

This variable contains the integral coefficient used by the PID

Definition at line 638 of file uStepperS.h.

◆ maxAcceleration

float uStepperS::maxAcceleration
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 615 of file uStepperS.h.

◆ maxVelocity

float uStepperS::maxVelocity
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 609 of file uStepperS.h.

◆ mode

uint8_t uStepperS::mode
private

This variable is used to indicate which mode the uStepper is running in (Normal, dropin or pid)

Definition at line 635 of file uStepperS.h.

◆ stall

volatile bool uStepperS::stall
private

This variable holds information on wether the motor is stalled or not. 0 = OK, 1 = stalled

Definition at line 645 of file uStepperS.h.


The documentation for this class was generated from the following files: