laurb9 / StepperDriver

Arduino library for A4988, DRV8825, DRV8834, DRV8880 and generic two-pin (DIR/STEP) stepper motor drivers
MIT License
555 stars 228 forks source link

get current position #101

Closed sharkyenergy closed 3 years ago

sharkyenergy commented 3 years ago

Hello! thanks for the library!

Is there a way to get the current motor position? (while standing still and while moving..)

Ideally as absolute value relative to the starting point...

Thank you

laurb9 commented 3 years ago

Hi,

The method getStepsCompleted can be used to get the number of steps completed since the move started. This is of course useful mostly in non-blocking mode.

Houri93 commented 3 years ago

I have just had to implement this, modify the library so a long number is set to 0 at the constructor, named it currentPosition. within nextAction, check if dir_state is positive, add one to currentPosition, otherwise subtract one.

The library implements relative movements of the current location using startMove, I have implemented a method startMoveToPosition which has a long pos input parameter and simply does startMove(pos - currentPos).

also implemented get and set methods for currentPos.

this is done in BasicStepperDriver file.

stale[bot] commented 3 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.