1
0
mirror of https://github.com/bdring/Grbl_Esp32.git synced 2025-08-29 09:10:03 +02:00

prevent division by zero and slower feed rate

This commit is contained in:
odaki
2019-10-18 00:38:29 +09:00
parent f8ece5125e
commit 26c1f87e82

View File

@@ -134,11 +134,18 @@ void inverse_kinematics(float *target, plan_line_data_t *pl_data, float *positio
polar_dist = sqrt( (p_dx * p_dx) + (p_dy * p_dy) +(p_dz * p_dz)); // calculate the total move distance
if (polar_dist == 0 || dist == 0) { // prevent 0 feed rate
polar_dist = dist; // default to same feed rate
float polar_rate_multiply = 1.0; // fail safe rate
if (polar_dist == 0 || dist == 0) { // prevent 0 feed rate and division by 0
polar_rate_multiply = 1.0; // default to same feed rate
} else {
// calc a feed rate multiplier
polar_rate_multiply = polar_dist / dist;
if (polar_rate_multiply < 0.5) { // prevent much slower speed
polar_rate_multiply = 0.5;
}
}
pl_data->feed_rate *= polar_dist / dist; // apply the distance ratio between coord systems
pl_data->feed_rate *= polar_rate_multiply; // apply the distance ratio between coord systems
// end determining new feed rate