What is "position" in accelstepper?

739 views
Skip to first unread message

Harrzack

unread,
Jan 7, 2014, 3:48:09 AM1/7/14
to accels...@googlegroups.com

I'm no t clear on what "position" is referring to. The term is used heavily in AS, but not fully explained.

Say I want to divide a disk into n divisions, and have a motor that moves 200 steps per rotation. I want to rotate the disk thru 20 stops, which are to be done with 20 button presses, or 1 "division" per press. 200 steps per full rev of the motor means I would take 200/20 steps (10) per button press. Acceleration/decel may be needed depending on the mass of the disk.

How does the AS concept of "position" relate to this task? Speed of rotation is somewhat immaterial - would be mostly under a couple rpm's.

Brian Schmalz

unread,
Jan 7, 2014, 4:37:05 AM1/7/14
to accels...@googlegroups.com
I believe position is in steps (or microsteps if you're using a microstep driver). Whatever that translates to in real-world motion is dependent on your mechanical system. So AS just keeps track of steps.

*Brian
________________________________________
From: accels...@googlegroups.com [accels...@googlegroups.com] on behalf of Harrzack [a...@sargasso-sea.net]
Sent: Monday, January 06, 2014 9:48 PM
To: accels...@googlegroups.com
Subject: [accelstepper] What is "position" in accelstepper?

I'm no t clear on what "position" is referring to. The term is used heavily in AS, but not fully explained.

Say I want to divide a disk into n divisions, and have a motor that moves 200 steps per rotation. I want to rotate the disk thru 20 stops, which are to be done with 20 button presses, or 1 "division" per press. 200 steps per full rev of the motor means I would take 200/20 steps (10) per button press. Acceleration/decel may be needed depending on the mass of the disk.

How does the AS concept of "position" relate to this task? Speed of rotation is somewhat immaterial - would be mostly under a couple rpm's.

--
You received this message because you are subscribed to the Google Groups "accelstepper" group.
To unsubscribe from this group and stop receiving emails from it, send an email to accelstepper...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Harrzack

unread,
Jan 7, 2014, 2:37:52 PM1/7/14
to accels...@googlegroups.com
Hmm - I still a tad confused over the use of the word 'position'.  After pouring over the .ccp file for AS, this is what I think it means (plz to correct if wrong!):

At the start, the stepper is at an arbitrary 'position' of zero.  If I want to move or step n steps, then my "target position" would be n steps away from where it is now.
So if I do a "stepper.setCurrentPosiiton(50) - followed by successive 'stepper.run(); calls, the motor would be moved 50 steps, and then the run would do nothing further. This appears to be needed to avoid blocking by just sitting in a tight loop and doing a 'high-delay-low' on the motor pins.  I also see the code in there to implement the acceleration features as well.

To recap:  It is my take that 'position' means the number of steps that will be done over successive 'run' calls (to avoid blocking), and that the number of steps (position) remaining is tracked and decremented at each step, till the 'position of 0' is reached. Further calls to run will do nothing. I think this is the essence - hope I'm not restating the obvious as it wasn't to me!  LOL! 

=Alan R.

Sandy Noble

unread,
Jan 7, 2014, 3:03:20 PM1/7/14
to accels...@googlegroups.com
That's right Alan, the examples show the pattern of use too.

Like Brian says, position is the degree of rotation of the motor shaft, measured in motor steps, relative to 0. The currentPosition is set to 0 when AccelStepper is initialised, but it can also be set explicitly if required, using setCurrentPosition(..).

Note that in your example you used setCurrentPosition() to set the _target_. In fact you should use .moveTo(50) to set the target to 50. Then lots of calls to run(). Using .move(50) will set the target relatively instead of absolute.

Run() will only cause a step to be taken if 
1. the target has not yet been reached (distanceToGo() != 0) AND
2. a motor step is due, based on the current speed of the motor.

If there are no more steps to take (like it has reached the target), then run will do nothing.
If the motor is turning at a low speed and has just stepped, then run will do nothing.

And yes, it's done that way so that it doesn't block other processes, and allows timed speed control. High-delay-low would just step at an arbitrary rate limited by the speed of the software loop.

sn

--
Sandy Noble
Reply all
Reply to author
Forward
0 new messages