Skip to content

Latest commit

 

History

History
1590 lines (374 loc) · 26.7 KB

class_flexy_stepper.md

File metadata and controls

1590 lines (374 loc) · 26.7 KB
title
FlexyStepper

FlexyStepper

#include <FlexyStepper.h>

Public Functions

Name
FlexyStepper()
constructor for the stepper class
void connectToPins(byte stepPinNumber, byte directionPinNumber)
connect the stepper object to the IO pins
void setStepsPerMillimeter(float motorStepPerMillimeter)
set the number of steps the motor has per millimeters
float getCurrentPositionInMillimeters()
get the current position of the motor in millimeters, this functions is updated while the motor moves
void setCurrentPositionInMillimeters(float currentPositionInMillimeters)
set the current position of the motor in millimeters, this does not move the motor
void setSpeedInMillimetersPerSecond(float speedInMillimetersPerSecond)
set the maximum speed, units in millimeters/second, this is the maximum speed reached while accelerating
void setAccelerationInMillimetersPerSecondPerSecond(float accelerationInMillimetersPerSecondPerSecond)
set the rate of acceleration, units in millimeters/second/second
bool moveToHomeInMillimeters(long directionTowardHome, float speedInMillimetersPerSecond, long maxDistanceToMoveInMillimeters, int homeLimitSwitchPin)
home the motor by moving until the homing sensor is activated, then set the position to zero, with units in millimeters
void moveRelativeInMillimeters(float distanceToMoveInMillimeters)
move relative to the current position, units are in millimeters, this function does not return until the move is complete
void setTargetPositionRelativeInMillimeters(float distanceToMoveInMillimeters)
setup a move relative to the current position, units are in millimeters, no motion occurs until processMove() is called
void moveToPositionInMillimeters(float absolutePositionToMoveToInMillimeters)
move to the given absolute position, units are in millimeters, this function does not return until the move is complete
void setTargetPositionInMillimeters(float absolutePositionToMoveToInMillimeters)
setup a move, units are in millimeters, no motion occurs until processMove() is called
float getCurrentVelocityInMillimetersPerSecond()
Get the current velocity of the motor in millimeters/second.
void setStepsPerRevolution(float motorStepPerRevolution)
set the number of steps the motor has per revolution
void setCurrentPositionInRevolutions(float currentPositionInRevolutions)
set the current position of the motor in revolutions, this does not move the motor
float getCurrentPositionInRevolutions()
get the current position of the motor in revolutions, this functions is updated while the motor moves
void setSpeedInRevolutionsPerSecond(float speedInRevolutionsPerSecond)
set the maximum speed, units in revolutions/second, this is the maximum speed reached while accelerating
void setAccelerationInRevolutionsPerSecondPerSecond(float accelerationInRevolutionsPerSecondPerSecond)
set the rate of acceleration, units in revolutions/second/second
bool moveToHomeInRevolutions(long directionTowardHome, float speedInRevolutionsPerSecond, long maxDistanceToMoveInRevolutions, int homeLimitSwitchPin)
home the motor by moving until the homing sensor is activated, then set the position to zero, with units in revolutions
void moveRelativeInRevolutions(float distanceToMoveInRevolutions)
move relative to the current position, units are in revolutions, this function does not return until the move is complete
void setTargetPositionRelativeInRevolutions(float distanceToMoveInRevolutions)
setup a move relative to the current position, units are in revolutions, no motion occurs until processMove() is called
void moveToPositionInRevolutions(float absolutePositionToMoveToInRevolutions)
move to the given absolute position, units are in revolutions, this function does not return until the move is complete
void setTargetPositionInRevolutions(float absolutePositionToMoveToInRevolutions)
setup a move, units are in revolutions, no motion occurs until processMove() is called
float getCurrentVelocityInRevolutionsPerSecond()
Get the current velocity of the motor in revolutions/second.
void setCurrentPositionInSteps(long currentPositionInSteps)
set the current position of the motor in steps, this does not move the motor
long getCurrentPositionInSteps()
get the current position of the motor in steps, this functions is updated while the motor moves
void setSpeedInStepsPerSecond(float speedInStepsPerSecond)
set the maximum speed, units in steps/second, this is the maximum speed reached while accelerating
void setAccelerationInStepsPerSecondPerSecond(float accelerationInStepsPerSecondPerSecond)
set the rate of acceleration, units in steps/second/second
bool moveToHomeInSteps(long directionTowardHome, float speedInStepsPerSecond, long maxDistanceToMoveInSteps, int homeSwitchPin)
home the motor by moving until the homing sensor is activated, then set the position to zero with units in steps
void moveRelativeInSteps(long distanceToMoveInSteps)
move relative to the current position, units are in steps, this function does not return until the move is complete
void setTargetPositionRelativeInSteps(long distanceToMoveInSteps)
setup a move relative to the current position, units are in steps, no motion occurs until processMove() is called
void moveToPositionInSteps(long absolutePositionToMoveToInSteps)
move to the given absolute position, units are in steps, this function does not return until the move is complete
void setTargetPositionInSteps(long absolutePositionToMoveToInSteps)
setup a move, units are in steps, no motion occurs until processMove() is called
void setTargetPositionToStop()
setup a "Stop" to begin the process of decelerating from the current velocity to zero, decelerating requires calls to processMove() until the move is complete
bool motionComplete()
check if the motor has competed its move to the target position
float getCurrentVelocityInStepsPerSecond()
Get the current velocity of the motor in steps/second.
bool processMovement(void )
if it is time, move one step

Public Functions Documentation

function FlexyStepper

FlexyStepper()

constructor for the stepper class

function connectToPins

void connectToPins(
    byte stepPinNumber,
    byte directionPinNumber
)

connect the stepper object to the IO pins

Parameters:

  • stepPinNumber IO pin number for the Step
  • directionPinNumber IO pin number for the direction bit
  • enablePinNumber IO pin number for the enable bit (LOW is enabled). set to 0 if enable is not supported

function setStepsPerMillimeter

void setStepsPerMillimeter(
    float motorStepPerMillimeter
)

set the number of steps the motor has per millimeters

function getCurrentPositionInMillimeters

float getCurrentPositionInMillimeters()

get the current position of the motor in millimeters, this functions is updated while the motor moves

Return: a signed motor position in millimeters returned

function setCurrentPositionInMillimeters

void setCurrentPositionInMillimeters(
    float currentPositionInMillimeters
)

set the current position of the motor in millimeters, this does not move the motor

function setSpeedInMillimetersPerSecond

void setSpeedInMillimetersPerSecond(
    float speedInMillimetersPerSecond
)

set the maximum speed, units in millimeters/second, this is the maximum speed reached while accelerating

Parameters:

  • speedInMillimetersPerSecond speed to accelerate up to, units in millimeters/second

function setAccelerationInMillimetersPerSecondPerSecond

void setAccelerationInMillimetersPerSecondPerSecond(
    float accelerationInMillimetersPerSecondPerSecond
)

set the rate of acceleration, units in millimeters/second/second

Parameters:

  • accelerationInMillimetersPerSecondPerSecond accelerationInMillimetersPerSecondPerSecond = rate of acceleration, units in millimeters/second/second

function moveToHomeInMillimeters

bool moveToHomeInMillimeters(
    long directionTowardHome,
    float speedInMillimetersPerSecond,
    long maxDistanceToMoveInMillimeters,
    int homeLimitSwitchPin
)

home the motor by moving until the homing sensor is activated, then set the position to zero, with units in millimeters

Parameters:

  • directionTowardHome 1 to move in a positive direction, -1 to move in a negative directions
  • speedInMillimetersPerSecond speed to accelerate up to while moving toward home, units in millimeters/second
  • maxDistanceToMoveInMillimeters unsigned maximum distance to move toward home before giving up
  • homeLimitSwitchPin pin number of the home switch, switch should be configured to go low when at home

Return: true returned if successful, else false

function moveRelativeInMillimeters

void moveRelativeInMillimeters(
    float distanceToMoveInMillimeters
)

move relative to the current position, units are in millimeters, this function does not return until the move is complete

Parameters:

  • distanceToMoveInMillimeters signed distance to move relative to the current position in millimeters

function setTargetPositionRelativeInMillimeters

void setTargetPositionRelativeInMillimeters(
    float distanceToMoveInMillimeters
)

setup a move relative to the current position, units are in millimeters, no motion occurs until processMove() is called

Parameters:

  • distanceToMoveInMillimeters signed distance to move relative to the current position in millimeters

function moveToPositionInMillimeters

void moveToPositionInMillimeters(
    float absolutePositionToMoveToInMillimeters
)

move to the given absolute position, units are in millimeters, this function does not return until the move is complete

Parameters:

  • absolutePositionToMoveToInMillimeters signed absolute position to move to in units of millimeters

function setTargetPositionInMillimeters

void setTargetPositionInMillimeters(
    float absolutePositionToMoveToInMillimeters
)

setup a move, units are in millimeters, no motion occurs until processMove() is called

Parameters:

  • absolutePositionToMoveToInMillimeters signed absolute position to move to in units of millimeters

function getCurrentVelocityInMillimetersPerSecond

float getCurrentVelocityInMillimetersPerSecond()

Get the current velocity of the motor in millimeters/second.

Return: float velocity speed in steps per second returned, signed

This functions is updated while it accelerates up and down in speed. This is not the desired speed, but the speed the motor should be moving at the time the function is called. This is a signed value and is negative when the motor is moving backwards. Note: This speed will be incorrect if the desired velocity is set faster than this library can generate steps, or if the load on the motor is too great for the amount of torque that it can generate.

function setStepsPerRevolution

void setStepsPerRevolution(
    float motorStepPerRevolution
)

set the number of steps the motor has per revolution

Parameters:

  • motorStepPerRevolution

function setCurrentPositionInRevolutions

void setCurrentPositionInRevolutions(
    float currentPositionInRevolutions
)

set the current position of the motor in revolutions, this does not move the motor

function getCurrentPositionInRevolutions

float getCurrentPositionInRevolutions()

get the current position of the motor in revolutions, this functions is updated while the motor moves

Parameters:

  • currentPositionInRevolutions a signed motor position in revolutions returned

function setSpeedInRevolutionsPerSecond

void setSpeedInRevolutionsPerSecond(
    float speedInRevolutionsPerSecond
)

set the maximum speed, units in revolutions/second, this is the maximum speed reached while accelerating

Parameters:

  • speedInRevolutionsPerSecond speed to accelerate up to, units in revolutions/second

function setAccelerationInRevolutionsPerSecondPerSecond

void setAccelerationInRevolutionsPerSecondPerSecond(
    float accelerationInRevolutionsPerSecondPerSecond
)

set the rate of acceleration, units in revolutions/second/second

Parameters:

  • accelerationInRevolutionsPerSecondPerSecond rate of acceleration, units in revolutions/second/second

function moveToHomeInRevolutions

bool moveToHomeInRevolutions(
    long directionTowardHome,
    float speedInRevolutionsPerSecond,
    long maxDistanceToMoveInRevolutions,
    int homeLimitSwitchPin
)

home the motor by moving until the homing sensor is activated, then set the position to zero, with units in revolutions

Parameters:

  • directionTowardHome 1 to move in a positive direction, -1 to move in a negative directions
  • speedInRevolutionsPerSecond speed to accelerate up to while moving toward home, units in revolutions/second
  • maxDistanceToMoveInRevolutions unsigned maximum distance to move toward home before giving up
  • homeLimitSwitchPin pin number of the home switch, switch should be configured to go low when at home

Return: true returned if successful, else false

function moveRelativeInRevolutions

void moveRelativeInRevolutions(
    float distanceToMoveInRevolutions
)

move relative to the current position, units are in revolutions, this function does not return until the move is complete

Parameters:

  • distanceToMoveInRevolutions signed distance to move relative to the current position in revolutions

function setTargetPositionRelativeInRevolutions

void setTargetPositionRelativeInRevolutions(
    float distanceToMoveInRevolutions
)

setup a move relative to the current position, units are in revolutions, no motion occurs until processMove() is called

Parameters:

  • distanceToMoveInRevolutions signed distance to move relative to the currentposition in revolutions

function moveToPositionInRevolutions

void moveToPositionInRevolutions(
    float absolutePositionToMoveToInRevolutions
)

move to the given absolute position, units are in revolutions, this function does not return until the move is complete

Parameters:

  • absolutePositionToMoveToInRevolutions signed absolute position to move to in units of revolutions

function setTargetPositionInRevolutions

void setTargetPositionInRevolutions(
    float absolutePositionToMoveToInRevolutions
)

setup a move, units are in revolutions, no motion occurs until processMove() is called

Parameters:

  • absolutePositionToMoveToInRevolutions signed absolute position to move to in units of revolutions

function getCurrentVelocityInRevolutionsPerSecond

float getCurrentVelocityInRevolutionsPerSecond()

Get the current velocity of the motor in revolutions/second.

Return: velocity speed in steps per second returned, signed

This functions is updated while it accelerates up and down in speed. This is not the desired speed, but the speed the motor should be moving at the time the function is called. This is a signed value and is negative when the motor is moving backwards. Note: This speed will be incorrect if the desired velocity is set faster than this library can generate steps, or if the load on the motor is too great for the amount of torque that it can generate.

function setCurrentPositionInSteps

void setCurrentPositionInSteps(
    long currentPositionInSteps
)

set the current position of the motor in steps, this does not move the motor

Parameters:

  • currentPositionInSteps the new position of the motor in steps

Remark: Note: This function should only be called when the motor is stopped

function getCurrentPositionInSteps

long getCurrentPositionInSteps()

get the current position of the motor in steps, this functions is updated while the motor moves

Return: a signed motor position in steps returned

function setSpeedInStepsPerSecond

void setSpeedInStepsPerSecond(
    float speedInStepsPerSecond
)

set the maximum speed, units in steps/second, this is the maximum speed reached while accelerating

Parameters:

  • speedInStepsPerSecond speed to accelerate up to, units in steps/second

function setAccelerationInStepsPerSecondPerSecond

void setAccelerationInStepsPerSecondPerSecond(
    float accelerationInStepsPerSecondPerSecond
)

set the rate of acceleration, units in steps/second/second

Parameters:

  • accelerationInStepsPerSecondPerSecond rate of acceleration, units in steps/second/second

function moveToHomeInSteps

bool moveToHomeInSteps(
    long directionTowardHome,
    float speedInStepsPerSecond,
    long maxDistanceToMoveInSteps,
    int homeSwitchPin
)

home the motor by moving until the homing sensor is activated, then set the position to zero with units in steps

Parameters:

  • directionTowardHome 1 to move in a positive direction, -1 to move in a negative directions
  • speedInStepsPerSecond speed to accelerate up to while moving toward home, units in steps/second
  • maxDistanceToMoveInSteps unsigned maximum distance to move toward home before giving up
  • homeSwitchPin pin number of the home switch, switch should be configured to go low when at home

Return: true returned if successful, else false

function moveRelativeInSteps

void moveRelativeInSteps(
    long distanceToMoveInSteps
)

move relative to the current position, units are in steps, this function does not return until the move is complete

Parameters:

  • distanceToMoveInSteps signed distance to move relative to the current position in steps

function setTargetPositionRelativeInSteps

void setTargetPositionRelativeInSteps(
    long distanceToMoveInSteps
)

setup a move relative to the current position, units are in steps, no motion occurs until processMove() is called

Parameters:

  • distanceToMoveInSteps signed distance to move relative to the current positionin steps

function moveToPositionInSteps

void moveToPositionInSteps(
    long absolutePositionToMoveToInSteps
)

move to the given absolute position, units are in steps, this function does not return until the move is complete

Parameters:

  • absolutePositionToMoveToInSteps signed absolute position to move to in unitsof steps

function setTargetPositionInSteps

void setTargetPositionInSteps(
    long absolutePositionToMoveToInSteps
)

setup a move, units are in steps, no motion occurs until processMove() is called

Parameters:

  • absolutePositionToMoveToInSteps signed absolute position to move to in units of steps

function setTargetPositionToStop

void setTargetPositionToStop()

setup a "Stop" to begin the process of decelerating from the current velocity to zero, decelerating requires calls to processMove() until the move is complete

Remark: Note: This function can be used to stop a motion initiated in units of steps or revolutions

function motionComplete

bool motionComplete()

check if the motor has competed its move to the target position

Return: true returned if the stepper is at the target position

function getCurrentVelocityInStepsPerSecond

float getCurrentVelocityInStepsPerSecond()

Get the current velocity of the motor in steps/second.

Return: velocity speed in steps per second returned, signed

This functions is updated while it accelerates up and down in speed. This is not the desired speed, but the speed the motor should be moving at the time the function is called. This is a signed value and is negative when the motor is moving backwards. Note: This speed will be incorrect if the desired velocity is set faster than this library can generate steps, or if the load on the motor is too great for the amount of torque that it can generate.

function processMovement

bool processMovement(
    void 
)

if it is time, move one step

Return: true returned if movement complete, false returned not a final target position yet