127 #ifndef _USTEPPER_S_LITE_H_
128 #define _USTEPPER_S_LITE_H_
130 #ifndef __AVR_ATmega328PB__
131 #error !!This library only supports the ATmega328pb MCU!!
185 #include <inttypes.h>
187 #include <util/delay.h>
194 #define STEPGENERATORFREQUENCY 100000.0
232 #define DELTAANGLETORPM ENCODERINTFREQ*(60.0/4095.0)
234 #define DELTAANGLETOSTEPSPERSECOND ENCODERINTFREQ*(3200.0/4095.0)
240 #define ENCODERINTFREQ 500.0
242 #define ENCODERINTSAMPLETIME 1.0/ENCODERINTFREQ
244 #define ENCODERADDR 0x36
252 #define MAGNITUDE 0x1B
254 #define PULSEFILTERKP 60.0
256 #define PULSEFILTERKI 500.0*ENCODERINTSAMPLETIME
268 extern "C" void TIMER1_COMPA_vect(
void) __attribute__ ((signal,used));
275 extern "C" void TIMER3_COMPA_vect(
void) __attribute__ ((signal,used,naked));
283 extern "C" void INT0_vect(
void) __attribute__ ((signal,used));
291 extern "C" void INT1_vect(
void) __attribute__ ((signal,used));
568 friend void INT0_vect(
void) __attribute__ ((signal,used));
597 void pid(
float error);
712 void moveSteps(int32_t steps,
bool dir,
bool holdMode = BRAKEON);
728 void hardStop(
bool holdMode = BRAKEON);
745 void softStop(
bool holdMode = BRAKEON);
801 float stepsPerRevolution = 3200.0,
807 uint8_t runCurrent = 50,
808 uint8_t holdCurrent = 30);
868 void setCurrent(uint8_t runCurrent, uint8_t holdCurrent = 25);
915 void moveToAngle(
float angle,
bool holdMode = BRAKEON);
926 void moveAngle(
float angle,
bool holdMode = BRAKEON);
volatile float currentPidAcceleration
float stepsPerSecondToRPM
Prototype of class for accessing all features of the uStepper S-lite in a single object.
volatile int32_t cruiseToDecelThreshold
float RPMToStepsPerSecond
bool isStalled(float stallSensitivity=0.992)
This method returns a bool variable indicating wether the motor is stalled or not.
void runContinous(bool dir)
Make the motor rotate continuously.
void invertDropinDir(bool invert)
This method is used to invert the drop-in direction pin interpretation.
volatile int32_t accelToCruiseThreshold
volatile int32_t angleMoved
Struct to store dropin settings.
volatile uint16_t oldAngle
bool invertPidDropinDirection
volatile float stepConversion
void dropinPrintHelp()
This method is used to print the dropinCli menu explainer:
void enableMotor(void)
Enables the stepper driver output stage.
volatile int32_t targetPosition
Union to easily split a float into its binary representation.
volatile uint8_t pidError
Function prototypes and definitions for the uStepper TMC2208 driver library.
volatile uint32_t stepDelay
volatile float pidStepsSinceReset
volatile uint8_t stepGeneratorDirection
float getAngle(void)
Measure the current shaft angle.
uint8_t dropinSettingsCalcChecksum(dropinCliSettings_t *settings)
This method is used internally for stall detection.
volatile float RPMToStepDelay
void setDifferential(float D)
This method is used to change the PID differential parameter D.
void enablePid(void)
This method enables the PID after being disabled (disablePid).
void setMaxAcceleration(float accel)
Set the maximum acceleration of the stepper motor.
void moveAngle(float angle, bool holdMode=BRAKEON)
Moves the motor to a relative angle.
volatile float currentPidSpeed
float getPidError(void)
This method returns the current PID error.
float getAngleMoved(void)
Measure the angle moved from reference position.
float getSpeed(bool unit=SPS)
Measure the current speed of the motor.
volatile int32_t decelToAccelThreshold
Function prototypes and definitions for the uStepper Servo library.
bool detectStall(void)
This method is used internally for stall detection.
void stop(bool brake=BRAKEON)
Stop the motor with deceleration.
uint8_t getMotorState(void)
Get the current state of the motor.
bool getCurrentDirection(void)
Returns the direction the motor is currently configured to rotate.
void hardStop(bool holdMode=BRAKEON)
Stop the motor without deceleration.
friend void TIMER1_COMPA_vect(void) __attribute__((signal
Measures angle and speed of motor.
float moveToEnd(bool dir, float stallSensitivity=0.992)
Moves the motor to its physical limit, without limit switch.
uint8_t detectMagnet(void)
Detect if magnet is present and within range.
uStepperEncoder(void)
Constructor.
volatile uint32_t cntSinceLastStep
Prototype of class for accessing all features of the TMC2208 in a single object.
void setIntegral(float I)
This method is used to change the PID integral parameter I.
void checkConnectorOrientation(uint8_t mode)
This method handles the connector orientation check in order to automatically compensate the PID for ...
volatile uint8_t direction
friend void INT0_vect(void) __attribute__((signal
Used by dropin feature to take in step pulses.
Prototype of class for the AS5600 encoder.
volatile float currentPidError
void setProportional(float P)
This method is used to change the PID proportional parameter P.
void setup(void)
Setup the encoder.
Prototype of class for accessing the TWI (I2C) interface of the AVR (master mode only).
bool loadDropinSettings(void)
This method loads the dropin settings stored in EEPROM.
int32_t getStepsSinceReset(void)
Get the number of steps applied since reset.
void pidDropin(float error)
This method handles the actual PID Drop-in controller calculations, if enabled.
void setHoldCurrent(uint8_t holdCurrent)
Set motor hold current.
void setHome(void)
Define new reference(home) position.
void pid(float error)
This method handles the actual PID controller calculations, if enabled.
void moveSteps(int32_t steps, bool dir, bool holdMode=BRAKEON)
Make the motor perform a predefined number of steps.
volatile int32_t decelToStopThreshold
void setRunCurrent(uint8_t runCurrent)
Set motor run current.
friend void TIMER3_COMPA_vect(void) __attribute__((signal
Handles accelerations.
dropinCliSettings_t dropinSettings
uint8_t getAgc(void)
Read the current AGC value of the encoder chip.
uint16_t getStrength(void)
Measure the strength of the magnet.
This file contains the implementation of the class methods, used to communicate over the I2C bus.
volatile int32_t stepsSinceReset
void setMaxVelocity(float vel)
Sets the maximum rotational velocity of the motor.
void setup(uint8_t mode=NORMAL, float stepsPerRevolution=3200.0, float pTerm=0.75, float iTerm=3.0, float dTerm=0.0, bool setHome=true, uint8_t invert=0, uint8_t runCurrent=50, uint8_t holdCurrent=30)
Initializes the different parts of the uStepper S-lite object.
uStepperSLite(float accel=1000.0, float vel=1000.0)
Constructor of uStepper S-lite class.
void parseCommand(String *cmd)
This method is used for the dropinCli to take in user commands.
void softStop(bool holdMode=BRAKEON)
Stop the motor with deceleration.
void disablePid(void)
This method disables the PID until calling enablePid.
void moveToAngle(float angle, bool holdMode=BRAKEON)
Moves the motor to an absolute angle.
void saveDropinSettings(void)
This method stores the current dropin settings in EEPROM.
void dropinCli()
This method is used to tune Drop-in parameters. After tuning uStepper S-lite the parameters are saved...
friend void TIMER1_COMPA_vect(void) __attribute__((signal
Measures angle and speed of motor.
void setCurrent(uint8_t runCurrent, uint8_t holdCurrent=25)
Set motor run and hold current.
void disableMotor(void)
Disables the stepper driver output stage.
volatile float pidTargetPosition
volatile bool pidDisabled