Преглед на файлове

Merge pull request #3502 from thinkyhead/rc_fix_arcs_bugs

General cleanup of arc code
Scott Lahteine преди 9 години
родител
ревизия
b243844690
променени са 1 файла, в които са добавени 25 реда и са изтрити 26 реда
  1. 25
    26
      Marlin/Marlin_main.cpp

+ 25
- 26
Marlin/Marlin_main.cpp Целия файл

@@ -7301,26 +7301,26 @@ void plan_arc(
7301 7301
 ) {
7302 7302
 
7303 7303
   float radius = hypot(offset[X_AXIS], offset[Y_AXIS]),
7304
-        center_axis0 = current_position[X_AXIS] + offset[X_AXIS],
7305
-        center_axis1 = current_position[Y_AXIS] + offset[Y_AXIS],
7304
+        center_X = current_position[X_AXIS] + offset[X_AXIS],
7305
+        center_Y = current_position[Y_AXIS] + offset[Y_AXIS],
7306 7306
         linear_travel = target[Z_AXIS] - current_position[Z_AXIS],
7307 7307
         extruder_travel = target[E_AXIS] - current_position[E_AXIS],
7308
-        r_axis0 = -offset[X_AXIS],  // Radius vector from center to current location
7309
-        r_axis1 = -offset[Y_AXIS],
7310
-        rt_axis0 = target[X_AXIS] - center_axis0,
7311
-        rt_axis1 = target[Y_AXIS] - center_axis1;
7308
+        r_X = -offset[X_AXIS],  // Radius vector from center to current location
7309
+        r_Y = -offset[Y_AXIS],
7310
+        rt_X = target[X_AXIS] - center_X,
7311
+        rt_Y = target[Y_AXIS] - center_Y;
7312 7312
 
7313 7313
   // CCW angle of rotation between position and target from the circle center. Only one atan2() trig computation required.
7314
-  float angular_travel = atan2(r_axis0 * rt_axis1 - r_axis1 * rt_axis0, r_axis0 * rt_axis0 + r_axis1 * rt_axis1);
7315
-  if (angular_travel < 0)  angular_travel += RADIANS(360);
7316
-  if (clockwise)  angular_travel -= RADIANS(360);
7314
+  float angular_travel = atan2(r_X * rt_Y - r_Y * rt_X, r_X * rt_X + r_Y * rt_Y);
7315
+  if (angular_travel < 0) angular_travel += RADIANS(360);
7316
+  if (clockwise) angular_travel -= RADIANS(360);
7317 7317
 
7318 7318
   // Make a circle if the angular rotation is 0
7319
-  if (current_position[X_AXIS] == target[X_AXIS] && current_position[Y_AXIS] == target[Y_AXIS] && angular_travel == 0)
7320
-    angular_travel += RADIANS(360);
7319
+  if (angular_travel == 0 && current_position[X_AXIS] == target[X_AXIS] && current_position[Y_AXIS] == target[Y_AXIS])
7320
+    angular_travel == RADIANS(360);
7321 7321
 
7322 7322
   float mm_of_travel = hypot(angular_travel * radius, fabs(linear_travel));
7323
-  if (mm_of_travel < 0.001)  return;
7323
+  if (mm_of_travel < 0.001) return;
7324 7324
   uint16_t segments = floor(mm_of_travel / (MM_PER_ARC_SEGMENT));
7325 7325
   if (segments == 0) segments = 1;
7326 7326
 
@@ -7359,9 +7359,7 @@ void plan_arc(
7359 7359
   float sin_T = theta_per_segment;
7360 7360
 
7361 7361
   float arc_target[NUM_AXIS];
7362
-  float sin_Ti;
7363
-  float cos_Ti;
7364
-  float r_axisi;
7362
+  float sin_Ti, cos_Ti, r_new_Y;
7365 7363
   uint16_t i;
7366 7364
   int8_t count = 0;
7367 7365
 
@@ -7373,28 +7371,29 @@ void plan_arc(
7373 7371
 
7374 7372
   float feed_rate = feedrate * feedrate_multiplier / 60 / 100.0;
7375 7373
 
7376
-  for (i = 1; i < segments; i++) { // Increment (segments-1)
7374
+  for (i = 1; i < segments; i++) { // Iterate (segments-1) times
7377 7375
 
7378
-    if (count < N_ARC_CORRECTION) {
7379
-      // Apply vector rotation matrix to previous r_axis0 / 1
7380
-      r_axisi = r_axis0 * sin_T + r_axis1 * cos_T;
7381
-      r_axis0 = r_axis0 * cos_T - r_axis1 * sin_T;
7382
-      r_axis1 = r_axisi;
7383
-      count++;
7376
+    if (++count < N_ARC_CORRECTION) {
7377
+      // Apply vector rotation matrix to previous r_X / 1
7378
+      r_new_Y = r_X * sin_T + r_Y * cos_T;
7379
+      r_X = r_X * cos_T - r_Y * sin_T;
7380
+      r_Y = r_new_Y;
7384 7381
     }
7385 7382
     else {
7386 7383
       // Arc correction to radius vector. Computed only every N_ARC_CORRECTION increments.
7387 7384
       // Compute exact location by applying transformation matrix from initial radius vector(=-offset).
7385
+      // To reduce stuttering, the sin and cos could be computed at different times.
7386
+      // For now, compute both at the same time.
7388 7387
       cos_Ti = cos(i * theta_per_segment);
7389 7388
       sin_Ti = sin(i * theta_per_segment);
7390
-      r_axis0 = -offset[X_AXIS] * cos_Ti + offset[Y_AXIS] * sin_Ti;
7391
-      r_axis1 = -offset[X_AXIS] * sin_Ti - offset[Y_AXIS] * cos_Ti;
7389
+      r_X = -offset[X_AXIS] * cos_Ti + offset[Y_AXIS] * sin_Ti;
7390
+      r_Y = -offset[X_AXIS] * sin_Ti - offset[Y_AXIS] * cos_Ti;
7392 7391
       count = 0;
7393 7392
     }
7394 7393
 
7395 7394
     // Update arc_target location
7396
-    arc_target[X_AXIS] = center_axis0 + r_axis0;
7397
-    arc_target[Y_AXIS] = center_axis1 + r_axis1;
7395
+    arc_target[X_AXIS] = center_X + r_X;
7396
+    arc_target[Y_AXIS] = center_Y + r_Y;
7398 7397
     arc_target[Z_AXIS] += linear_per_segment;
7399 7398
     arc_target[E_AXIS] += extruder_per_segment;
7400 7399
 

Loading…
Отказ
Запис