Skip to content

Latest commit

 

History

History
137 lines (111 loc) · 3.79 KB

README.md

File metadata and controls

137 lines (111 loc) · 3.79 KB

DendoStepper

Work in progress, maybe unstable. Opening issues is more than welcome.
This library takes care of pulse generating for stepper motor drivers with STEP/DIR interface. Pulse generating utilizes general purpose timers to achieve some usable accuracy and smoothness.
Currently supports only linear acceleration and deceleration.

Known limitations

  • maximum number of controlled stepper motors is 4, this is limited by number of general purpose timers
  • If the motor is moving, it is not possible to move it to another direction.

Usage

typedef struct
{
    uint8_t stepPin;           /** step signal pin */
    uint8_t dirPin;            /** dir signal pin */
    uint8_t enPin;             /** enable signal pin */
    microStepping_t miStep;    /** microstepping configured on driver - used in distance calculation */
    float stepAngle;           /** one step angle in degrees (usually 1.8deg), used in steps per rotation calculation */
} DendoStepper_config_t;

enum microStepping_t
{
    MICROSTEP_1 = 0x1,
    MICROSTEP_2,
    MICROSTEP_4 = 0x4,
    MICROSTEP_8 = 0x8,
    MICROSTEP_16 = 0x10,
    MICROSTEP_32 = 0x20,
    MICROSTEP_64 = 0x40,
    MICROSTEP_128 = 0x80,
    MICROSTEP_256 = 0x100,
};

Configuration struct, can be allocated on stack or heap.

void init();

Initializes GPIO and Timer peripherals, registers ISR. Expects populated config struct is alreay passed to the class using config()

void config(DendoStepper_config_t* config);

Configures the class as per passed config struct pointer.

void setStepsPerMm(uint16_t steps);
uint16_t getStepsPerMm();

Sets or gets steps needed to move one millimiter, useful if stepper is moving along linear axis.

void setSpeed(uint16_t speed,uint16_t accT, uint16_t decT);
uint16_t getSpeed();
float getAcc();

Sets maximum speed in steps per second, acceleration and deceleration time in milliseconds.
Gets speed in steps per second
Gets acceleration in steps per second per second

void setSpeedMm(uint16_t speed,uint16_t accT, uint16_t decT);

Sets maximum speed in mm/s, acceleration and deceleration time in milliseconds. Expects already defined steps per millimeter with setStepsPerMm()

void runPos(int32_t relative);

Runs motor to position relative from current position in steps, respecting constraints set with setSpeed()

void runPosMm(int32_t relative);

Runs motor to position relative from current position in millimeters, respecting constraints set with setSpeed()
Expects already defined steps per millimeter with setStepsPerMm()

 bool runAbsolute(uint32_t position);

Runs motor in absolute coordinate plane. Unit: steps (should be constrained with home switch)

 bool runAbsoluteMm(uint32_t position);

Runs motor in absolute coordinate plane. Unit: millimeters (should be constrained with home switch)
Expects already defined steps per millimeter with setStepsPerMm()

 bool runInf(bool direction);

Runs motor infintely in desired direction with constrains set using setSpeed().

void disableMotor();
void enableMotor();

Disables and enables motor via EN pin

uint8_t getState();

enum motor_status{
    DISABLED,
    IDLE,
    ACC,
    COAST,
    DEC,
};

Returns current state of motor, return type is enum motor_status

void resetAbsolute();

Resets absolute position to 0. Called for ex. when endswitch is hit.

void getPosition();

Gets current position in absolute coordinate plane in steps.

void getPositionMm();

Gets current position in absolute coordinate plane in millimeters.
Expects already defined steps per millimeter with setStepsPerMm()

void stop();

Stops the motor dead on the spot. No deceleration is performed this way. Eg. e-stop.