Go to the documentation of this file.
133 #ifndef _USTEPPER_S_H_
134 #define _USTEPPER_S_H_
136 #ifndef ARDUINO_AVR_USTEPPER_S
137 #error !!This library only supports the uStepper S board!!
140 #ifndef __AVR_ATmega328PB__
141 #error !!This library only supports the ATmega328PB MCU!!
145 #include <avr/interrupt.h>
148 #include <inttypes.h>
151 #define FREEWHEELBRAKE 0
158 #define POSITION_REACHED 0x20
159 #define VELOCITY_REACHED 0x10
160 #define STANDSTILL 0x08
161 #define STALLGUARD2 0x04
199 float posError = 0.0;
201 float velIntegrator = 0.0;
217 #define CS_DRIVER PE2
218 #define CS_ENCODER PD7
229 #define PID CLOSEDLOOP
231 #define CLOCKFREQ 16000000.0
237 #define ENCODERINTFREQ 1000
238 #define ENCODERINTPERIOD 1.0/ENCODERINTFREQ
239 #define PULSEFILTERKP 120.0
240 #define PULSEFILTERKI 1900.0*ENCODERINTPERIOD
247 extern "C" void TIMER1_COMPA_vect(void) __attribute__ ((signal,used));
296 uStepperS(
float acceleration,
float velocity);
339 uint16_t stepsPerRevolution = 200,
346 uint8_t runCurrent = 50,
347 uint8_t holdCurrent = 30);
606 float moveToEnd(
bool dir,
float rpm = 40.0, int8_t threshold = 4);
757 uint8_t
SPI( uint8_t data );
765 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.
void enableStallguard(int8_t threshold=4, bool stopOnStall=false)
Enable TMC5130 StallGuard.
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)
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 a specific angle relative to the current position.
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.