From b216af779d6c5774c5948754a6a1b491c8476a14 Mon Sep 17 00:00:00 2001 From: Lutz Niggl Date: Sun, 5 May 2019 20:08:15 +0200 Subject: [PATCH] Motor didn't stop at target in rare cases -> fixed --- src/accelerators/LinStepAccelerator.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/accelerators/LinStepAccelerator.h b/src/accelerators/LinStepAccelerator.h index 8edb824..4ca4342 100644 --- a/src/accelerators/LinStepAccelerator.h +++ b/src/accelerators/LinStepAccelerator.h @@ -55,7 +55,11 @@ int32_t LinStepAccelerator::updateSpeed(int32_t curPos) return v_tgt; //deceleration phase -------------------------------------- - return sqrtf(two_a * ((stepsDone < delta_tgt - 1) ? delta_tgt - stepsDone - 2 : 0) + v_min2); + if(stepsDone < delta_tgt) + return sqrtf(two_a * ((stepsDone < delta_tgt - 1) ? delta_tgt - stepsDone - 2 : 0) + v_min2); + + //we are done, make sure to return 0 to stop the step timer + return 0; } uint32_t LinStepAccelerator::initiateStopping(int32_t curPos)