Bladeren bron

Arc Direction followup for circles (#20314)

yysh12 4 jaren geleden
bovenliggende
commit
dcb101224f
No account linked to committer's email address
1 gewijzigde bestanden met toevoegingen van 14 en 12 verwijderingen
  1. 14
    12
      Marlin/src/gcode/motion/G2_G3.cpp

+ 14
- 12
Marlin/src/gcode/motion/G2_G3.cpp Bestand weergeven

@@ -80,24 +80,26 @@ void plan_arc(
80 80
   // Angle of rotation between position and target from the circle center.
81 81
   float angular_travel = ATAN2(rvec.a * rt_Y - rvec.b * rt_X, rvec.a * rt_X + rvec.b * rt_Y);
82 82
 
83
-  // Make sure angular travel over 180 degrees goes the other way around.
84
-  switch (((angular_travel < 0) << 1) + clockwise) {
85
-    case 1: angular_travel -= RADIANS(360); break; // Positive but CW? Reverse direction.
86
-    case 2: angular_travel += RADIANS(360); break; // Negative but CCW? Reverse direction.
87
-  }
88
-
89 83
   #ifdef MIN_ARC_SEGMENTS
90
-    uint16_t min_segments = CEIL((MIN_ARC_SEGMENTS) * ABS(angular_travel) / RADIANS(360));
91
-    NOLESS(min_segments, 1U);
84
+    uint16_t min_segments = MIN_ARC_SEGMENTS;
92 85
   #else
93 86
     constexpr uint16_t min_segments = 1;
94 87
   #endif
95 88
 
96
-  // Make a circle if the angular rotation is 0 and the target is current position
97
-  if (NEAR_ZERO(angular_travel) && NEAR(current_position[p_axis], cart[p_axis]) && NEAR(current_position[q_axis], cart[q_axis])) {
98
-    angular_travel = RADIANS(360);
89
+  // Do a full circle if angular rotation is near 0 and the target is current position
90
+  if ((!angular_travel || NEAR_ZERO(angular_travel)) && NEAR(current_position[p_axis], cart[p_axis]) && NEAR(current_position[q_axis], cart[q_axis])) {
91
+    // Preserve direction for circles
92
+    angular_travel = clockwise ? -RADIANS(360) : RADIANS(360);
93
+  }
94
+  else {
95
+    // Make sure angular travel over 180 degrees goes the other way around.
96
+    switch (((angular_travel < 0) << 1) | clockwise) {
97
+      case 1: angular_travel -= RADIANS(360); break; // Positive but CW? Reverse direction.
98
+      case 2: angular_travel += RADIANS(360); break; // Negative but CCW? Reverse direction.
99
+    }
99 100
     #ifdef MIN_ARC_SEGMENTS
100
-      min_segments = MIN_ARC_SEGMENTS;
101
+      min_segments = CEIL(min_segments * ABS(angular_travel) / RADIANS(360));
102
+      NOLESS(min_segments, 1U);
101 103
     #endif
102 104
   }
103 105
 

Laden…
Annuleren
Opslaan