Skip to content

Commit 15380e9

Browse files
authoredSep 28, 2021
Merge pull request #113 from luni64/develop
Optimize speed of motor group, fix stopping when no steps left
2 parents 57e532f + 07ba4db commit 15380e9

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed
 

‎src/StepControlBase.h

+16-1
Original file line numberDiff line numberDiff line change
@@ -92,13 +92,26 @@ namespace TeensyStep
9292
}
9393

9494
// Calculate acceleration parameters --------------------------------
95-
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
9695
uint32_t pullInSpeed = this->leadMotor->vPullIn;
9796
uint32_t pullOutSpeed = this->leadMotor->vPullOut;
9897
uint32_t acceleration = (*std::min_element(this->motorList, this->motorList + N, Stepper::cmpAcc))->a; // use the lowest acceleration for the move
9998

99+
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
100100
if (this->leadMotor->A == 0 || targetSpeed == 0) return;
101101

102+
// target speed----
103+
104+
float x = 0;
105+
float leadSpeed = std::abs(this->leadMotor->vMax);
106+
for (int i = 0; i < N; i++)
107+
{
108+
float relDist = this->motorList[i]->A / (float)this->leadMotor->A * leadSpeed / std::abs(this->motorList[i]->vMax);
109+
if (relDist > x) x = relDist;
110+
// Serial.printf("%d %f\n", i, relDist);
111+
}
112+
targetSpeed = leadSpeed / x;
113+
//Serial.printf("\n%d\n",targetSpeed);
114+
102115
// Start move--------------------------
103116
this->timerField.begin();
104117

@@ -143,6 +156,8 @@ namespace TeensyStep
143156
{
144157
uint32_t newTarget = accelerator.initiateStopping(this->leadMotor->current);
145158
this->leadMotor->target = this->leadMotor->current + this->leadMotor->dir * newTarget;
159+
160+
if (this->leadMotor->target == this->leadMotor->current) this->timerField.end();
146161
}
147162
}
148163

0 commit comments

Comments
 (0)