138 #ifndef _USTEPPER_S_H_
139 #define _USTEPPER_S_H_
141 #ifndef ARDUINO_AVR_USTEPPER_S
142 #error !!This library only supports the uStepper S board!!
145 #ifndef __AVR_ATmega328PB__
146 #error !!This library only supports the ATmega328PB MCU!!
150 #include <avr/interrupt.h>
153 #include <inttypes.h>
156 #define FREEWHEELBRAKE 0
163 #define POSITION_REACHED 0x20
164 #define VELOCITY_REACHED 0x10
165 #define STANDSTILL 0x08
166 #define STALLGUARD2 0x04
204 float posError = 0.0;
206 float velIntegrator = 0.0;
222 #define CS_DRIVER PE2
223 #define CS_ENCODER PD7
234 #define PID CLOSEDLOOP
236 #define CLOCKFREQ 16000000.0
242 #define ENCODERINTFREQ 1000
243 #define ENCODERINTPERIOD 1.0/ENCODERINTFREQ
244 #define PULSEFILTERKP 120.0
245 #define PULSEFILTERKI 1900.0*ENCODERINTPERIOD
301 uStepperS(
float acceleration,
float velocity);
344 uint16_t stepsPerRevolution = 200,
351 uint8_t runCurrent = 50,
352 uint8_t holdCurrent = 30);
526 void enableStallguard( int8_t threshold = 4,
bool stopOnStall =
false,
float rpm = 10.0);
622 float moveToEnd(
bool dir,
float rpm = 40.0, int8_t threshold = 4, uint32_t timeOut = 100000);
781 uint8_t
SPI( uint8_t data );
789 float pid(
float error);
Prototype of class for the TMC5130 Driver.
Prototype of class for the AEAT8800-Q24 encoder.
void setHome(float initialAngle=0)
Define new reference(home) position.
Prototype of class for accessing all features of the uStepper S in a single object.
void stop(bool mode=HARD)
Stop the motor.
bool loadDropinSettings(void)
void setMaxVelocity(float velocity)
Set the maximum velocity of the stepper motor.
void saveDropinSettings(void)
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.
float angleMoved(void)
Get the angle moved from reference position in degrees.
float moveToEnd(bool dir, float rpm=40.0, int8_t threshold=4, uint32_t timeOut=100000)
Moves the motor to its physical limit, without limit switch.
volatile posFilter_t externalStepInputFilter
volatile float controlThreshold
float getDriverRPM(void)
Get the RPM from driver.
void parseCommand(String *cmd)
This method is used for the dropinCli to take in user commands.
void setDifferential(float D)
This method is used to change the PID differential parameter D.
void dropinCli()
This method is used to tune Drop-in parameters. After tuning uStepper S, the parameters are saved in ...
void setMaxDeceleration(float deceleration)
Set the maximum deceleration of the stepper motor.
float stepsPerSecondToRPM
bool isStalled(void)
This method returns a bool variable indicating wether the motor is stalled or not....
void setMaxAcceleration(float acceleration)
Set the maximum acceleration of the stepper motor.
void setProportional(float P)
This method is used to change the PID proportional parameter P.
bool invertPidDropinDirection
void disableStallguard(void)
Disables the builtin stallguard offered from TMC5130, and reenables StealthChop.
void setIntegral(float I)
This method is used to change the PID integral parameter I.
void setHoldCurrent(double current)
Set motor hold current.
void chipSelect(uint8_t pin, bool state)
void setRPM(float rpm)
Set the velocity in rpm.
void disablePid(void)
This method disables the PID until calling enablePid.
volatile int32_t pidPositionStepsIssued
volatile bool pidDisabled
float RPMToStepsPerSecond
void moveAngle(float angle)
Makes the motor rotate a specific angle relative to the current position.
void enableClosedLoop(void)
This method reenables the closed loop mode after being disabled.
void filterSpeedPos(posFilter_t *filter, int32_t steps)
void setBrakeMode(uint8_t mode, float brakeCurrent=25.0)
friend void interrupt0(void)
Used by dropin feature to take in step pulses.
friend void TIMER1_COMPA_vect(void) __attribute__((signal
Interrupt routine for critical tasks.
void enableStallguard(int8_t threshold=4, bool stopOnStall=false, float rpm=10.0)
Enable TMC5130 StallGuard.
void checkOrientation(float distance=10)
This method is used to check the orientation of the motor connector.
void setControlThreshold(float threshold)
This method sets the control threshold for the closed loop position control in microsteps - i....
void setSPIMode(uint8_t mode)
void moveToAngle(float angle)
Makes the motor rotate to a specific absolute angle.
void clearStall(void)
Clear the stallguard, reenabling the motor to return to its previous operation.
dropinCliSettings_t dropinSettings
void init(void)
Internal function to prepare the uStepperS in the constructor.
void runContinous(bool dir)
Make the motor rotate continuously.
uint8_t SPI(uint8_t data)
void enablePid(void)
This method reenables the PID after being disabled.
void setCurrent(double current)
Set motor output current.
void dropinPrintHelp()
This method is used to print the dropinCli menu explainer:
volatile float currentPidError
uint8_t dropinSettingsCalcChecksum(dropinCliSettings_t *settings)
void invertDropinDir(bool invert)
This method is used to invert the drop-in direction pin interpretation.
void disableClosedLoop(void)
This method disables the closed loop mode until calling enableClosedLoop.
uStepperS()
Constructor of uStepper class.
void moveSteps(int32_t steps)
Make the motor perform a predefined number of steps.
bool getMotorState(uint8_t statusType=POSITION_REACHED)
Get the current motor driver state.
float getPidError(void)
This method returns the current PID error.
Struct to store dropin settings.
Struct for encoder velocity estimator.
Function prototypes and definitions for the TMC5130 motor driver.
Function prototypes and definitions for the AEAT8800-Q24 Encoder.
void interrupt0(void)
Used by dropin feature to take in step pulses.
void TIMER1_COMPA_vect(void) __attribute__((signal
Interrupt routine for critical tasks.
void interrupt1(void)
Used by dropin feature to take in enable signal.
Function prototypes and definitions for the uStepper Servo library.
Union to easily split a float into its binary representation.