gin66 / FastAccelStepper

A high speed stepper library for Atmega 168/328p (nano), Atmega32u4, Atmega 2560, ESP32, ESP32S2, ESP32S3, ESP32C3 and Atmel SAM Due
MIT License
283 stars 67 forks source link

the decelerating at RunForward blocks briefly #192

Closed HerrFlodo closed 11 months ago

HerrFlodo commented 11 months ago

Hi,

I have a problem with the deceleration in the RunForward command. I change the speed with a potentiometer in the loop as follows:

void loop() {

potValue = analogRead(potpin); targetSpeed = map(potValue, 0, 1023, 1, 40000) ;// Targetspeed pro Intervall

stepper->setAcceleration(30000);
stepper->setSpeedInHz(targetSpeed);  // the parameter is Hz !!!
stepper->runForward();

}

The acceleration works wonderfully, but with the deceleration I have errors. There seems to be no acceleration function behind the deceleration, and when I turn the potentiometer slowly the stepper sometimes brakes briefly to a standstill and then accelerates again.

Can anyone help me with this problem?

Greetings

Flo

gin66 commented 11 months ago

Even though, this should not have an impact, it may be better to throw in a delay(1) as FastAccelStepper processes changes of speed/acceleration only approx. every 4ms.

This braking is a sudden stop, which may happen, when the stepper gets irregular pulses ? Or is it deceleration to standstill and start again as usual ?

A possible cause may be the potValue. Please check, that the potValue does not jump in value. Either attach a capacitor at the potentiometer or perform SW averaging. For example like this:

int average = 0;

void loop() {
   potValue = analogRead(potpin);
   average += (potValue - average)/4;
   targetSpeed = map(average, 0, 1023, 1, 40000) ;// Targetspeed pro Intervall

   stepper->setAcceleration(30000);
   stepper->setSpeedInHz(targetSpeed);  // the parameter is Hz !!!
   stepper->runForward();
   delay(1);
}

Please let me know, if this has helped.

HerrFlodo commented 11 months ago

Hi Gin66,

Thanks a lot for the very fast response. I will try that in the afternoon. What I am also confused of is the missing deceleration function. The stepper speed follows direkt the potentiometer position. It should not behave like this, right? If I speed up, it works like expected.

gin66 commented 11 months ago

btw: which version of FastAccelStepper do you use ?

This could be related: 0.30.4: Fix for issue #178: speed does not decelerate but jumps to lower value

HerrFlodo commented 11 months ago

Hi,

so i tested the above code today.

int average = 0;

void loop() { potValue = analogRead(potpin); average += (potValue - average)/4; targetSpeed = map(average, 0, 1023, 1, 40000) ;// Targetspeed pro Intervall

stepper->setAcceleration(30000); stepper->setSpeedInHz(targetSpeed); // the parameter is Hz !!! stepper->runForward(); delay(1); }

Unfortunately it does not bring any improvement. I am using version 0.30. It is conceivable that I have the same error as described in #178, but I could not reproduce it with the code in issue #178.

gin66 commented 11 months ago

Thanks for the update.

So there are two possibilities:

  1. You stick with your solution, which works for you.
  2. Manually update to 0.30.4 and hope, that fix works in your situation, too.

While you are at it, perhaps you leave a comment here

HerrFlodo commented 11 months ago

Thank you so much. I updated the version and it works! Great job, thank you. Can I help you somehow or donate something?