Skip to content

Commit eedc8d0

Browse files
committed
hangprinter: simplify things by turning unrolled stuff into loops
For some compilers, some times, unrollowing things manually gets you a performance improvement. After some time, all compilers kind of implement "the right way" of "doing it". What's important (except for the editor) we must all do the same (except for the editor). Wheter we do ++i or i++ is not going to make a difference in running time anymore, but consistency is good in projects, and I see you have it. Then let's keep it. So, my question in the commit, for anyone reading it...looped or unrolled?
1 parent a2179fb commit eedc8d0

1 file changed

Lines changed: 14 additions & 20 deletions

File tree

src/Movement/Kinematics/HangprinterKinematics.cpp

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -107,16 +107,15 @@ void HangprinterKinematics::Recalc() noexcept
107107

108108
// This is the difference between a "line length" and a "line position"
109109
// "line length" == ("line position" + "line length in origin")
110-
lineLengthsOrigin[A_AXIS] = fastSqrtf(fsquare(anchors[A_AXIS][0]) + fsquare(anchors[A_AXIS][1]) + fsquare(anchors[A_AXIS][2]));
111-
lineLengthsOrigin[B_AXIS] = fastSqrtf(fsquare(anchors[B_AXIS][0]) + fsquare(anchors[B_AXIS][1]) + fsquare(anchors[B_AXIS][2]));
112-
lineLengthsOrigin[C_AXIS] = fastSqrtf(fsquare(anchors[C_AXIS][0]) + fsquare(anchors[C_AXIS][1]) + fsquare(anchors[C_AXIS][2]));
113-
lineLengthsOrigin[D_AXIS] = fastSqrtf(fsquare(anchors[D_AXIS][0]) + fsquare(anchors[D_AXIS][1]) + fsquare(anchors[D_AXIS][2]));
114-
110+
for (size_t i = 0; i < HANGPRINTER_AXES; ++i)
111+
{
112+
lineLengthsOrigin[i] = fastSqrtf(fsquare(anchors[i][0]) + fsquare(anchors[i][1]) + fsquare(anchors[i][2]));
113+
}
115114

116115
// Line buildup compensation
117116
float stepsPerUnitTimesRTmp[HANGPRINTER_AXES] = { 0.0 };
118117
Platform& platform = reprap.GetPlatform(); // No const because we want to set drive steper per unit
119-
for (size_t i = 0; i < HANGPRINTER_AXES; i++)
118+
for (size_t i = 0; i < HANGPRINTER_AXES; ++i)
120119
{
121120
const uint8_t driver = platform.GetAxisDriversConfig(i).driverNumbers[0].localDriver; // Only supports single driver
122121
bool dummy;
@@ -275,22 +274,15 @@ bool HangprinterKinematics::CartesianToMotorSteps(const float machinePos[], cons
275274
size_t numVisibleAxes, size_t numTotalAxes, int32_t motorPos[], bool isCoordinated) const noexcept
276275
{
277276
float squaredLineLengths[HANGPRINTER_AXES];
278-
squaredLineLengths[A_AXIS] = LineLengthSquared(machinePos, anchors[A_AXIS]);
279-
squaredLineLengths[B_AXIS] = LineLengthSquared(machinePos, anchors[B_AXIS]);
280-
squaredLineLengths[C_AXIS] = LineLengthSquared(machinePos, anchors[C_AXIS]);
281-
squaredLineLengths[D_AXIS] = LineLengthSquared(machinePos, anchors[D_AXIS]);
282-
283277
float linePos[HANGPRINTER_AXES];
278+
284279
for (size_t i = 0; i < HANGPRINTER_AXES; ++i)
285280
{
281+
squaredLineLengths[i] = LineLengthSquared(machinePos, anchors[i]);
286282
linePos[i] = fastSqrtf(squaredLineLengths[i]) - lineLengthsOrigin[i];
283+
motorPos[i] = lrintf(k0[i] * (fastSqrtf(spoolRadiiSq[i] + linePos[i] * k2[i]) - spoolRadii[i]));
287284
}
288285

289-
motorPos[A_AXIS] = lrintf(k0[A_AXIS] * (fastSqrtf(spoolRadiiSq[A_AXIS] + linePos[A_AXIS] * k2[A_AXIS]) - spoolRadii[A_AXIS]));
290-
motorPos[B_AXIS] = lrintf(k0[B_AXIS] * (fastSqrtf(spoolRadiiSq[B_AXIS] + linePos[B_AXIS] * k2[B_AXIS]) - spoolRadii[B_AXIS]));
291-
motorPos[C_AXIS] = lrintf(k0[C_AXIS] * (fastSqrtf(spoolRadiiSq[C_AXIS] + linePos[C_AXIS] * k2[C_AXIS]) - spoolRadii[C_AXIS]));
292-
motorPos[D_AXIS] = lrintf(k0[D_AXIS] * (fastSqrtf(spoolRadiiSq[D_AXIS] + linePos[D_AXIS] * k2[D_AXIS]) - spoolRadii[D_AXIS]));
293-
294286
return true;
295287
}
296288

@@ -587,10 +579,12 @@ void HangprinterKinematics::ForwardTransform(float const a, float const b, float
587579
// Print all the parameters for debugging
588580
void HangprinterKinematics::PrintParameters(const StringRef& reply) const noexcept
589581
{
590-
reply.printf("Anchor coordinates (%.2f,%.2f,%.2f) (%.2f,%.2f,%.2f) (%.2f,%.2f,%.2f)\n",
591-
(double)anchors[A_AXIS][X_AXIS], (double)anchors[A_AXIS][Y_AXIS], (double)anchors[A_AXIS][Z_AXIS],
592-
(double)anchors[B_AXIS][X_AXIS], (double)anchors[B_AXIS][Y_AXIS], (double)anchors[B_AXIS][Z_AXIS],
593-
(double)anchors[C_AXIS][X_AXIS], (double)anchors[C_AXIS][Y_AXIS], (double)anchors[C_AXIS][Z_AXIS]);
582+
reply.printf("Anchor coordinates");
583+
for (size_t i = 0; i < HANGPRINTER_AXES; ++i)
584+
{
585+
reply.printf(" (%.2f,%.2f,%.2f)", (double)anchors[i][X_AXIS], (double)anchors[i][Y_AXIS], (double)anchors[i][Z_AXIS]);
586+
}
587+
reply.printf("\n");
594588
}
595589

596590
#if DUAL_CAN

0 commit comments

Comments
 (0)