From 609a8f8170c0318235f0247251bb8b3c7a30ea2a Mon Sep 17 00:00:00 2001 From: Rerouter Date: Sun, 10 Sep 2023 16:49:38 +1000 Subject: [PATCH] Corrected Acceleration Limited Max Speed Previously _cn could never significantly drop below its initial value, leading to cases where low accelerations meant it could never exceed a speed value of about 1361000 / sqrt(acceleration) This fix is to correct it such that the libraries speed limit is the only thing limiting the maximum speed, This may have the consequence of changing the acceleration scaling at higher speeds slightly, as it no longer rolls off, instead increasing to the cruise phase --- src/AccelStepper.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/AccelStepper.cpp b/src/AccelStepper.cpp index 54535cc..8f0c790 100644 --- a/src/AccelStepper.cpp +++ b/src/AccelStepper.cpp @@ -99,7 +99,7 @@ unsigned long AccelStepper::computeNewSpeed() { long distanceTo = distanceToGo(); // +ve is clockwise from curent location - long stepsToStop = (long)((_speed * _speed) / (2.0 * _acceleration)); // Equation 16 + long stepsToStop = abs(_n); // Equation 16 if (distanceTo == 0 && stepsToStop <= 1) { @@ -155,7 +155,7 @@ unsigned long AccelStepper::computeNewSpeed() else { // Subsequent step. Works for accel (n is +_ve) and decel (n is -ve). - _cn = _cn - ((2.0 * _cn) / ((4.0 * _n) + 1)); // Equation 13 + _cn = ((2.0 * _c0) / ((4.0 * _n) + 1)); // Equation 13 _cn = max(_cn, _cmin); } _n++;