From 7d1a0bf2eacb0da89ac28da7768c7d284ae85244 Mon Sep 17 00:00:00 2001 From: luni64 Date: Sat, 17 Jul 2021 08:41:45 +0200 Subject: [PATCH 1/2] Optimize speed of motor group in case v_max --- src/StepControlBase.h | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/StepControlBase.h b/src/StepControlBase.h index 1302e2e..6a44087 100644 --- a/src/StepControlBase.h +++ b/src/StepControlBase.h @@ -92,13 +92,26 @@ namespace TeensyStep } // Calculate acceleration parameters -------------------------------- - uint32_t targetSpeed = std::abs((*std::min_element(this->motorList, this->motorList + N, Stepper::cmpVmin))->vMax) * speedOverride; // use the lowest max frequency for the move, scale by relSpeed uint32_t pullInSpeed = this->leadMotor->vPullIn; uint32_t pullOutSpeed = this->leadMotor->vPullOut; uint32_t acceleration = (*std::min_element(this->motorList, this->motorList + N, Stepper::cmpAcc))->a; // use the lowest acceleration for the move + uint32_t targetSpeed = std::abs((*std::min_element(this->motorList, this->motorList + N, Stepper::cmpVmin))->vMax) * speedOverride; // use the lowest max frequency for the move, scale by relSpeed if (this->leadMotor->A == 0 || targetSpeed == 0) return; + // target speed---- + + float x = 0; + float leadSpeed = std::abs(this->leadMotor->vMax); + for (int i = 0; i < N; i++) + { + float relDist = this->motorList[i]->A / (float)this->leadMotor->A * leadSpeed / std::abs(this->motorList[i]->vMax); + if (relDist > x) x = relDist; + // Serial.printf("%d %f\n", i, relDist); + } + targetSpeed = leadSpeed / x; + //Serial.printf("\n%d\n",targetSpeed); + // Start move-------------------------- this->timerField.begin(); From 07ba4dbea8a93073641acd19f22e8b40df262403 Mon Sep 17 00:00:00 2001 From: luni64 <12611497+luni64@users.noreply.github.com> Date: Tue, 28 Sep 2021 18:45:58 +0200 Subject: [PATCH 2/2] Fixes issue stopping motor when no steps are left --- src/StepControlBase.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/StepControlBase.h b/src/StepControlBase.h index 6a44087..c3b9d6d 100644 --- a/src/StepControlBase.h +++ b/src/StepControlBase.h @@ -156,6 +156,8 @@ namespace TeensyStep { uint32_t newTarget = accelerator.initiateStopping(this->leadMotor->current); this->leadMotor->target = this->leadMotor->current + this->leadMotor->dir * newTarget; + + if (this->leadMotor->target == this->leadMotor->current) this->timerField.end(); } }