Top speed in moveTo or acceleration in setSpeed()...

4,617 views
Skip to first unread message

John Washington

unread,
Aug 10, 2015, 9:29:29 AM8/10/15
to accelstepper
Hi,

I've installed the library today onto an Arduino and got my motor moving no problem using the example - I'm using a DRV8825 pololu stepper driver set to 1/16th stepping with a 200 step motor.  What I'm missing (or don't understand) from the documentation is if I use :-


#include <AccelStepper.h>

AccelStepper stepper(AccelStepper::DRIVER, 2, 3);//step pin, dir pin

void setup()
{  
   stepper.setMaxSpeed(100000);
   stepper.setSpeed(40000);
}

void loop()
{  
   stepper.runSpeed();
}

Then the motor runs fine at the speed but does not accelerate to that speed it just tries to run that speed, which massively hurts the top achievable speed due to stalling with no acceleration profile.  If I use :-

#include <AccelStepper.h>

AccelStepper stepper(AccelStepper::DRIVER, 2, 3);//step pin, dir pin


#include <AccelStepper.h>

// Define a stepper and the pins it will use
//AccelStepper stepper; // Defaults to AccelStepper::FULL4WIRE (4 pins) on 2, 3, 4, 5
AccelStepper stepper(AccelStepper::DRIVER, 2, 3);//step pin, dir pin

void setup()
{  
  // Change these to suit your stepper if you want
  stepper.setMaxSpeed(1000000);
  stepper.setSpeed(40000);
  stepper.setAcceleration(15000);
  stepper.moveTo(5000);
  
}

void loop()
{
    // If at the end of travel go to the other end
    if (stepper.distanceToGo() == 0) {
      stepper.moveTo(-stepper.currentPosition());
      //stepper.setSpeed(40000);
    }
    stepper.run();
}

Then the motor accelerates smoothly to a fixed rotational velocity but that clearly isn't 40000 steps per second, it seems be the steady state velocity appears to be unchangeable certainly it isn't changed using the setSpeed() command.

For my application either of the examples would be fine if .runSpeed() used the acceleration profile or if moveTo() used setSpeed() (or a function I'm missing?) to define the top speed.

Thanks for any insights anybody can share :)

John.

gregor christandl

unread,
Aug 10, 2015, 10:57:56 AM8/10/15
to accels...@googlegroups.com

Hi,
If you want acceleration, use moveTo() and run(). The stepper will accelerate to the speed defined by setMaxSpeed() at the rate defined by setAcceleration().
If you want constant speed, use setSpeed() and runSpeed(). mixing these two forms of movement is not officially supported.

I think 40k steps per second is just too much for an arduino. try setting a lower speed (1000 steps/second) and test it.


--
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/d/optout.

John Washington

unread,
Aug 11, 2015, 8:05:56 AM8/11/15
to accelstepper
Thanks for the reply, 40k SPS is fine using the setSpeed()/runSpeed but not using the moveTo()/run() - it seems to have some internal limit on the steps per second, its not a problem for me if I use full stepping but if I microstep then its hugely limited on the achievable RPS which is a shame.

I'll take a look under the hood in the coming weeks and see if/how/why its limited.

Sandy Noble

unread,
Aug 11, 2015, 4:02:41 PM8/11/15
to accels...@googlegroups.com
run() calculates the speed change (acceleration), and sets the speed, then just calls runSpeed(). The acceleration calculation is comparatively computationally intensive.

runSpeed() on it's own doesn't calculate speed change, so is much faster.

Top speed on an arduino UNO used to be around 4000 steps per second, or thereabouts. I haven't tested it myself recently, but I remember when I did, it wasn't far off. There have been some improvements recently, so it might be better, but 40,000 is unlikely I think.

sn


--
Sandy Noble

Paulo Silva

unread,
Sep 8, 2017, 4:30:16 AM9/8/17
to accelstepper
Hello, with moveTo() and run() does it only accelerate to top speed and go to the target or somewhere in the middle starts to decelerate?
Thanks

gregor christandl

unread,
Sep 8, 2017, 7:12:20 AM9/8/17
to accelstepper

Hi,
AccelStepper accelerates to the top speed and decelerates as it approaches the target position.

Reply all
Reply to author
Forward
0 new messages