AccelStepper - how to disable acceleration

Hi there,

I'm using AccelStepper for a simple stepper sketch. I don't need the acceleration feature, I would like the stepper to start and stop as fast as possible. I set acceleration to a very high value but ideally I'd like to disable it altogether.

Can someone point me to the right direction?

void setup() {
	// set the maximum speed, acceleration factor,
	// initial speed and the target position
  myStepper.setMaxSpeed(3500);
	myStepper.setAcceleration(100000);
	myStepper.setSpeed(1500);
	myStepper.moveTo(355);
  myStepper.runToPosition();
  delay(100);
  myStepper.moveTo(0);
  myStepper.runToPosition();
  delay(1000);
  pinMode (XTIDE, INPUT);
  pinMode (enable, OUTPUT);
  Serial.begin(9600);

}

void loop() {

Activity = digitalRead(XTIDE);
if (Activity == 1) {
 // Activity = digitalRead(XTIDE);
  Seek = random(0, 355);
  digitalWrite(enable, 1);
  myStepper.moveTo(Seek);
	myStepper.runToPosition();
  digitalWrite(enable, 0);
  Bob = random(10, 500);
  delay(Bob);

}
  
}

Thanks!
Tony

Then set the acceleration as high as possible. If you set it higher than possible then the motor will loose steps and will not start and stop as fast as possible.

You realize that this results in very poor performance and unpredictable step losses?

Thanks both.

The stepper is used for a non-critical function so as long as it moves and makes some noise it's ok. I know it sounds silly...

Is there an alternative to this then? The basic stepper library doesn't seem to work with a controller which accepts STEP and DIRECTION pins?

Use runSpeed instead of run

Thanks.
I found this about runspeed

Poll the motor and step it if a step is due, implementing a constant speed as set by the most recent call to [setSpeed()]. You must call this as frequently as possible, but at least once per step interval,

Returns
true if the motor was stepped.

Right now my sketch does not call for the stepper function more than once. I use runToPosition and the stepper just does that.

runSpeed would need a change in the code, right?

Is there a command similar to runToPosition which does not account for acceleration?

Yes, you answered your own question. Use one pin for direction and pulse another pin for step. As long as you don't pulse the pin too fast (probably keep it under 500 steps/second) that will work.

of course - but that means re-write the code. I was hoping to just be able to adjust some parameters and use the existing code.

If I remembrt correctly, there ist also runSpeedToPosition

Executes [runSpeed()] unless the targetPosition is reached. This function needs to be called often just like [runSpeed()] or [run()]. Will step the motor if a step is required at the currently selected speed unless the target position has been reached. Does not implement accelerations.

Returns
true if it stepped

So I need to keep calling until it returns true?
I'm not a developer, please forgive me if I am saying rubbish :slight_smile:

Then the solution was already provided in post #2!!!
Set a very high acceleration and it's done.

well, that's what I am doing so the solution would be in post #1!!!!!!!

I was hoping for a cleaner solution, a library - or a parameter within this library - which allowed to move the stepper without even considering the acceleration - which is my original question.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.