119 #ifndef _USTEPPER_S_H_ 120 #define _USTEPPER_S_H_ 122 #ifndef __AVR_ATmega328PB__ 123 #error !!This library only supports the ATmega328PB MCU!! 126 #include <avr/interrupt.h> 129 #include <inttypes.h> 134 #define POSITION_REACHED 0x20 135 #define VELOCITY_REACHED 0x10 136 #define STANDSTILL 0x08 137 #define STALLGUARD2 0x04 175 float posError = 0.0;
177 float velIntegrator = 0.0;
193 #define CS_DRIVER PE2 194 #define CS_ENCODER PD7 208 #define CLOCKFREQ 16000000.0 211 #define ENCODERINTFREQ 1000.0 213 #define ENCODERINTPERIOD 1.0/ENCODERINTFREQ 215 #define ENCODERSPEEDCONSTANT ENCODERINTFREQ/65535.0 217 #define PULSEFILTERKP 120.0 219 #define PULSEFILTERKI 1900.0*ENCODERINTPERIOD 275 uStepperS(
float acceleration,
float velocity);
318 uint16_t stepsPerRevolution = 200,
322 uint16_t dropinStepSize = 16,
325 uint8_t runCurrent = 50,
326 uint8_t holdCurrent = 30);
491 bool isStalled(
float stallSensitivity = 0.992);
493 void brakeMotor(
bool brake);
520 float moveToEnd(
bool dir,
float stallSensitivity = 0.992);
616 float maxDeceleration;
617 bool invertPidDropinDirection;
623 uint16_t dropinStepSize;
627 float stepsPerSecondToRPM;
628 float RPMToStepsPerSecond;
632 float currentPidSpeed;
642 volatile bool pidDisabled;
648 volatile int32_t pidPositionStepsIssued = 0;
649 volatile float currentPidError;
650 float stallSensitivity = 0.992;
651 uint8_t SPI( uint8_t data );
653 void setSPIMode( uint8_t
mode );
657 void filterSpeedPos(
posFilter_t *filter, int32_t steps);
659 float pid(
float error);
660 bool detectStall(int32_t stepsMoved);
662 bool loadDropinSettings(
void);
663 void saveDropinSettings(
void);
void dropinCli()
This method is used to tune Drop-in parameters. After tuning uStepper S, the parameters are saved in ...
void moveAngle(float angle)
Moves the motor rotate a specific angle relative to the current position.
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.
Prototype of class for accessing all features of the uStepper S in a single object.
void setHoldCurrent(double current)
Set motor hold current.
Struct to store dropin settings.
void dropinPrintHelp()
This method is used to print the dropinCli menu explainer:
Function prototypes and definitions for the TMC5130 motor driver.
void setMaxVelocity(float velocity)
Set the maximum velocity of the stepper motor.
void interrupt1(void)
Used by dropin feature to take in enable signal.
Struct for encoder velocity estimator.
float getPidError(void)
This method returns the current PID error.
void runContinous(bool dir)
Make the motor rotate continuously.
void parseCommand(String *cmd)
This method is used for the dropinCli to take in user commands.
Prototype of class for the TMC5130 Driver.
Prototype of class for the AEAT8800-Q24 encoder.
void setHome(void)
Define new reference(home) position.
void setMaxDeceleration(float deceleration)
Set the maximum deceleration of the stepper motor.
uStepperS()
Constructor of uStepper class.
void moveToAngle(float angle)
Moves the motor rotate a specific angle relative to the current position.
void TIMER1_COMPA_vect(void) __attribute__((signal
Interrupt routine for critical tasks.
Union to easily split a float into its binary representation.
void enablePid(void)
This method enables the PID after being disabled (disablePid).
void setRPM(float rpm)
Set the velocity in rpm.
void stop(bool mode=HARD)
Stop the motor.
void moveSteps(int32_t steps)
Make the motor perform a predefined number of steps.
void init(void)
Internal function to prepare the uStepperS in the constructor.
void chipSelect(bool state)
Set the output level of the chip select pin.
bool isStalled(float stallSensitivity=0.992)
This method returns a bool variable indicating wether the motor is stalled or not.
void setIntegral(float I)
This method is used to change the PID integral parameter I.
Function prototypes and definitions for the AEAT8800-Q24 Encoder.
Function prototypes and definitions for the uStepper Servo library.
void setProportional(float P)
This method is used to change the PID proportional parameter P.
void invertDropinDir(bool invert)
This method is used to invert the drop-in direction pin interpretation.
float moveToEnd(bool dir, float stallSensitivity=0.992)
Moves the motor to its physical limit, without limit switch.
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.
void disablePid(void)
This method disables the PID until calling enablePid.
void setDifferential(float D)
This method is used to change the PID differential parameter D.
float angleMoved(void)
Get the angle moved from reference position in degrees.
void setMaxAcceleration(float acceleration)
Set the maximum acceleration of the stepper motor.
void setCurrent(double current)
Set motor output current.
bool getMotorState(uint8_t statusType=POSITION_REACHED)
Get the current motor driver state.
friend void interrupt0(void)
Used by dropin feature to take in step pulses.