2 Basic questions about run() commands

1,707 views
Skip to first unread message

dubi....@gmail.com

unread,
Jan 12, 2014, 4:26:30 PM1/12/14
to accels...@googlegroups.com
Hi Dear group, first of all i want to thank you for your time and work making this library and answering questions here...
Im an arduino beginner, trying to get myself into accelstepper, and got somewhat confused between the different run() command variations. therefore 2 questions :

1. i have made a small table for reference,  please tell me what should be in the "?", since i had some problem finding it by myself (see question 2)

should be executed constantly to move motor Blocking support acceleration COMMAND
V X V run()
V X X runSpeed()
? V X runToPosition()
? V (?) X runSpeedToPosition()

2. i tried the runtoposition() command, which i understand should move the motor to position and stop ,with a single call.
the following code makes the motor spin constantly without moving, although i wanted it to stop after 1 revolution.
please tell me what wrong  :


#include <AccelStepper.h>
AccelStepper stepper(AccelStepper::HALF4WIRE,8,10,9,11); 
int steps=4076; //steps for 1 revolution
int flag=0;
void setup()

  stepper.setMaxSpeed(900);
}

void loop()

  
 while (flag ==0 )  { 
stepper.moveTo(steps);
stepper.setSpeed(900);
stepper.runToPosition();
flag=1;
}

}

dubi....@gmail.com

unread,
Jan 12, 2014, 4:29:19 PM1/12/14
to accels...@googlegroups.com
sorry, i meant "code makes the motor spin constantly without stopping"
the following code makes the motor spin constantly without stopping, although i wanted it to stop after 1 revolution.

Sandy Noble

unread,
Jan 12, 2014, 6:00:59 PM1/12/14
to accels...@googlegroups.com
This is like a question in the AccelStepper Certified Professional exam :)

should be executed constantly to move motorBlockingsupport acceleration COMMAND
YNY run()
Y NNrunSpeed()
NY YrunToPosition()
Y
NN runSpeedToPosition()


Your two last columns are inversions of each other. Strictly speaking, even the non-blocking methods are blocking - they just don't block for long,  and also only move one step at the most.

runSpeedToPosition() is a version of runSpeed() with position checking.
run() is a version of runSpeed() with acceleration calculations and position checking.
runToPosition() and runNewSpeedToPosition() are blocking, or self-looping version of run(), therefore it _does_ do accelerations - although the docs say it moves at constant speed.

I had the same problem as you when I tried this with the current version of accelstepper linked to on the website (v1.37). Upgrading to the newest version (http://www.airspayce.com/mikem/arduino/AccelStepper/AccelStepper-1.38.zip) fixed the endless spinning problem, but also revealed the discrepency above. RunToPosition() _does_ implement accelerations after Mike's last fix. Hurray!

So try upgrading your library and see if that makes more sense. (I've never quite understood runToPosition(), it wasn't just me being daft!)

sn



--
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.



--
Sandy Noble

dubi....@gmail.com

unread,
Jan 12, 2014, 8:39:48 PM1/12/14
to accels...@googlegroups.com
Thanks, this was very helpful!
it works now, but i most add some other notes +  strange behavior:

1.1 the below code worked only after i added a
setacceleration() >100  command in the setup.

1.2 when setting acceleration=0, it continued to rotate continusly.

1.3 when setting acceleration between 0-99 it didnt rotate at all.

1.4 when settting negative acceleration it moves in constant speed as it should.  (wtf? :))
Reply all
Reply to author
Forward
0 new messages