setAcceleration

918 views
Skip to first unread message

Andres Penaranda

unread,
Nov 6, 2014, 5:45:03 PM11/6/14
to accels...@googlegroups.com
Hi!!,

I've been having problems with setAcceleration. I haven't been able to change de acceleration of the motor.
It always goes as fast as it can to the speed thats was set. I would like for it to start slowly until it reaches de desired speed.
But its seems that setAcceleration doesn't change the acceleration of the stepper. So how can i do it??
I tried this code but it doesn't seem to work...

#include <AccelStepper.h>

// Define a stepper and the pins it will use
AccelStepper stepper(AccelStepper::FULL4WIRE,8,9,10,11); // Defaults to AccelStepper::FULL4WIRE (4 pins) on 2, 3, 4, 5
int spd=1000;
void setup()

  stepper.setMaxSpeed(3500);
  stepper.setAcceleration(1);

 
}

void loop()
{
 while (spd != 3500){
   spd=spd+10;
   stepper.setSpeed(spd);
   stepper.runSpeed();
 }

}

Sandy Noble

unread,
Nov 6, 2014, 5:59:00 PM11/6/14
to accels...@googlegroups.com
Well, you're setting the acceleration, then you're immediately overriding the speed and setting it manually.

Why not have a look at the accelstepper examples and see how it's meant to be used? That's what they're there for.


void setup()
{  
    stepper.setMaxSpeed(200.0);
    stepper.setAcceleration(100.0);
}

void loop()
{    
    stepper.runToNewPosition(500);
}


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



--
Sandy Noble
Message has been deleted

Andres Penaranda

unread,
Nov 6, 2014, 11:56:04 PM11/6/14
to accels...@googlegroups.com
Well I'm trying for it to run a constant speed for a lot of time.,  so that's why I'm using the runSpeed function
So if i want i it to run at a constant speed, when the stepper is at postion 500,  I  will have to set a new target position that would be the start position right? 
Like so
void setup()
{
  stepper.setMaxSpeed(200.0);
  stepper.setAcceleration(100.0);
}
void loop()
{
  if ( stepper.currentPosition () = 0) {
    stepper.runToNewPosition(500);
  }

  if ( stepper.currentPosition () = 500) {
    stepper.runToNewPosition(0);

Sandy Noble

unread,
Nov 7, 2014, 5:53:47 PM11/7/14
to accels...@googlegroups.com
If you want acceleration, you have to set a target so it knows when to start decelerating, and NOT use runSpeed(). runSpeed() bypasses the acceleration calculations.

Then set the acceleration rate you need, and use either 

- a loop with run() in it, if you have other things you want to do at the same time
- runToNewPosition(2147483647); // max long int size


I've often tried to to use run() to get up to speed, and then detect when the speed got up to maxSpeed and the hand it off to runSpeed() indefinitely. Never really managed to get it to work, but in principle I don't see why it wouldn't work.


sn
Reply all
Reply to author
Forward
0 new messages