Browse Source

🐛 Fix G2/G3 angular motion calculation (#22407)

Yash 4 years ago
parent
commit
497541e199
No account linked to committer's email address
1 changed files with 9 additions and 6 deletions
  1. 9
    6
      Marlin/src/gcode/motion/G2_G3.cpp

+ 9
- 6
Marlin/src/gcode/motion/G2_G3.cpp View File

@@ -83,12 +83,13 @@ void plan_arc(
83 83
   #endif
84 84
 
85 85
   // Angle of rotation between position and target from the circle center.
86
-  float angular_travel;
86
+  float angular_travel, abs_angular_travel;
87 87
 
88 88
   // Do a full circle if starting and ending positions are "identical"
89 89
   if (NEAR(current_position[p_axis], cart[p_axis]) && NEAR(current_position[q_axis], cart[q_axis])) {
90 90
     // Preserve direction for circles
91 91
     angular_travel = clockwise ? -RADIANS(360) : RADIANS(360);
92
+    abs_angular_travel = RADIANS(360);
92 93
   }
93 94
   else {
94 95
     // Calculate the angle
@@ -103,8 +104,10 @@ void plan_arc(
103 104
       case 2: angular_travel += RADIANS(360); break; // Negative but CCW? Reverse direction.
104 105
     }
105 106
 
107
+    abs_angular_travel = ABS(angular_travel);
108
+
106 109
     #ifdef MIN_ARC_SEGMENTS
107
-      min_segments = CEIL(min_segments * ABS(angular_travel) / RADIANS(360));
110
+      min_segments = CEIL(min_segments * abs_angular_travel / RADIANS(360));
108 111
       NOLESS(min_segments, 1U);
109 112
     #endif
110 113
   }
@@ -117,8 +120,8 @@ void plan_arc(
117 120
   #endif
118 121
 
119 122
   // If circling around...
120
-  if (ENABLED(ARC_P_CIRCLES) && circles) {
121
-    const float total_angular = angular_travel + circles * RADIANS(360),  // Total rotation with all circles and remainder
123
+  if (TERN0(ARC_P_CIRCLES, circles)) {
124
+    const float total_angular = abs_angular_travel + circles * RADIANS(360),  // Total rotation with all circles and remainder
122 125
               part_per_circle = RADIANS(360) / total_angular;             // Each circle's part of the total
123 126
 
124 127
     #if HAS_Z_AXIS
@@ -138,8 +141,8 @@ void plan_arc(
138 141
     TERN_(HAS_EXTRUDERS, extruder_travel = cart.e - current_position.e);
139 142
   }
140 143
 
141
-  const float flat_mm = radius * angular_travel,
142
-              mm_of_travel = TERN_(HAS_Z_AXIS, linear_travel ? HYPOT(flat_mm, linear_travel) :) ABS(flat_mm);
144
+  const float flat_mm = radius * abs_angular_travel,
145
+              mm_of_travel = TERN_(HAS_Z_AXIS, linear_travel ? HYPOT(flat_mm, linear_travel) :) flat_mm;
143 146
   if (mm_of_travel < 0.001f) return;
144 147
 
145 148
   const feedRate_t scaled_fr_mm_s = MMS_SCALED(feedrate_mm_s);

Loading…
Cancel
Save