Go to the documentation of this file.
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
252 extern "C" void TIMER1_COMPA_vect(void) __attribute__ ((signal,used));
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);
620 float moveToEnd(
bool dir,
float rpm = 40.0, int8_t threshold = 4);
779 uint8_t
SPI( uint8_t data );
787 float pid(
float error);
volatile posFilter_t externalStepInputFilter
Prototype of class for accessing all features of the uStepper S in a single object.
Prototype of class for the TMC5130 Driver.
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.
void setBrakeMode(uint8_t mode, float brakeCurrent=25.0)
friend void TIMER1_COMPA_vect(void) __attribute__((signal
Interrupt routine for critical tasks.
void chipSelect(uint8_t pin, bool state)
void enableStallguard(int8_t threshold=4, bool stopOnStall=false, float rpm=10.0)
Enable TMC5130 StallGuard.
float getDriverRPM(void)
Get the RPM from driver.
Struct to store dropin settings.
void setSPIMode(uint8_t mode)
void disableStallguard(void)
Disables the builtin stallguard offered from TMC5130, and reenables StealthChop.
void runContinous(bool dir)
Make the motor rotate continuously.
Union to easily split a float into its binary representation.
void disablePid(void)
This method disables the PID until calling enablePid.
bool isStalled(void)
This method returns a bool variable indicating wether the motor is stalled or not....
float stepsPerSecondToRPM
void dropinCli()
This method is used to tune Drop-in parameters. After tuning uStepper S, the parameters are saved in ...
Function prototypes and definitions for the TMC5130 motor driver.
volatile float controlThreshold
void stop(bool mode=HARD)
Stop the motor.
void interrupt1(void)
Used by dropin feature to take in enable signal.
void filterSpeedPos(posFilter_t *filter, int32_t steps)
float getPidError(void)
This method returns the current PID error.
void setRPM(float rpm)
Set the velocity in rpm.
void interrupt0(void)
Used by dropin feature to take in step pulses.
void disableClosedLoop(void)
This method disables the closed loop mode until calling enableClosedLoop.
volatile bool pidDisabled
void parseCommand(String *cmd)
This method is used for the dropinCli to take in user commands.
float moveToEnd(bool dir, float rpm=40.0, int8_t threshold=4)
Moves the motor to its physical limit, without limit switch.
void setIntegral(float I)
This method is used to change the PID integral parameter I.
float RPMToStepsPerSecond
void clearStall(void)
Clear the stallguard, reenabling the motor to return to its previous operation.
Function prototypes and definitions for the uStepper Servo library.
void init(void)
Internal function to prepare the uStepperS in the constructor.
bool loadDropinSettings(void)
void setDifferential(float D)
This method is used to change the PID differential parameter D.
void setMaxVelocity(float velocity)
Set the maximum velocity of the stepper motor.
uint8_t dropinSettingsCalcChecksum(dropinCliSettings_t *settings)
void enableClosedLoop(void)
This method reenables the closed loop mode after being disabled.
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.
friend void interrupt0(void)
Used by dropin feature to take in step pulses.
Prototype of class for the AEAT8800-Q24 encoder.
void saveDropinSettings(void)
void setMaxAcceleration(float acceleration)
Set the maximum acceleration of the stepper motor.
float angleMoved(void)
Get the angle moved from reference position in degrees.
void invertDropinDir(bool invert)
This method is used to invert the drop-in direction pin interpretation.
Function prototypes and definitions for the AEAT8800-Q24 Encoder.
void moveAngle(float angle)
Makes the motor rotate a specific angle relative to the current position.
void setHome(float initialAngle=0)
Define new reference(home) position.
dropinCliSettings_t dropinSettings
uint8_t SPI(uint8_t data)
Struct for encoder velocity estimator.
void checkOrientation(float distance=10)
This method is used to check the orientation of the motor connector.
volatile int32_t pidPositionStepsIssued
void setHoldCurrent(double current)
Set motor hold current.
uStepperS()
Constructor of uStepper class.
void moveToAngle(float angle)
Makes the motor rotate to a specific absolute angle.
void dropinPrintHelp()
This method is used to print the dropinCli menu explainer:
void setControlThreshold(float threshold)
This method sets the control threshold for the closed loop position control in microsteps - i....
volatile float currentPidError
void setProportional(float P)
This method is used to change the PID proportional parameter P.
void enablePid(void)
This method reenables the PID after being disabled.
bool invertPidDropinDirection
void setMaxDeceleration(float deceleration)
Set the maximum deceleration of the stepper motor.
void setCurrent(double current)
Set motor output current.